terraform: fix copying dependencies

This commit is contained in:
Mitchell Hashimoto 2014-09-23 14:20:26 -07:00
parent b1a583e3de
commit d443202b31
5 changed files with 9 additions and 10 deletions

View File

@ -959,6 +959,7 @@ func (c *walkContext) persistState(r *Resource) {
rs.init()
module.Resources[r.Id] = rs
}
rs.Dependencies = r.Dependencies
// Assign the instance state to the proper location
if r.Flags&FlagTainted != 0 {
@ -1148,5 +1149,3 @@ func (c *walkContext) computeResourceMultiVariable(
return strings.Join(values, ","), nil
}

View File

@ -79,7 +79,6 @@ type GraphNodeModule struct {
type GraphNodeResource struct {
Index int
Config *config.Resource
Dependencies []string
Resource *Resource
ResourceProviderID string
}
@ -264,7 +263,7 @@ func graphEncodeDependencies(g *depgraph.Graph) {
}
// Update the dependencies
rn.Dependencies = inject
r.Dependencies = inject
}
}

View File

@ -594,12 +594,12 @@ func TestGraphEncodeDependencies(t *testing.T) {
// This should encode the dependency information into the state
graphEncodeDependencies(g)
web := g.Noun("aws_instance.web").Meta.(*GraphNodeResource)
web := g.Noun("aws_instance.web").Meta.(*GraphNodeResource).Resource
if len(web.Dependencies) != 1 || web.Dependencies[0] != "aws_security_group.firewall" {
t.Fatalf("bad: %#v", web)
}
weblb := g.Noun("aws_load_balancer.weblb").Meta.(*GraphNodeResource)
weblb := g.Noun("aws_load_balancer.weblb").Meta.(*GraphNodeResource).Resource
if len(weblb.Dependencies) != 1 || weblb.Dependencies[0] != "aws_instance.web" {
t.Fatalf("bad: %#v", weblb)
}
@ -637,12 +637,12 @@ func TestGraphEncodeDependencies_count(t *testing.T) {
// This should encode the dependency information into the state
graphEncodeDependencies(g)
web := g.Noun("aws_instance.web.0").Meta.(*GraphNodeResource)
web := g.Noun("aws_instance.web.0").Meta.(*GraphNodeResource).Resource
if len(web.Dependencies) != 0 {
t.Fatalf("bad: %#v", web)
}
weblb := g.Noun("aws_load_balancer.weblb").Meta.(*GraphNodeResource)
weblb := g.Noun("aws_load_balancer.weblb").Meta.(*GraphNodeResource).Resource
if len(weblb.Dependencies) != 3 {
t.Fatalf("bad: %#v", weblb)
}

View File

@ -29,6 +29,7 @@ type Resource struct {
Id string
Info *InstanceInfo
Config *ResourceConfig
Dependencies []string
Diff *InstanceDiff
Provider ResourceProvider
State *InstanceState

View File

@ -42,7 +42,7 @@ type State struct {
//
// This should be the preferred method to add module states since it
// allows us to optimize lookups later as well as control sorting.
func (s *State) AddModule(path []string) *ModuleState{
func (s *State) AddModule(path []string) *ModuleState {
m := &ModuleState{Path: path}
m.init()
s.Modules = append(s.Modules, m)
@ -125,7 +125,7 @@ func (s *State) String() string {
// If we're the root module, we just write the output directly.
if reflect.DeepEqual(m.Path, rootModulePath) {
buf.WriteString(mStr+"\n")
buf.WriteString(mStr + "\n")
continue
}