diff --git a/terraform/graph_builder_apply.go b/terraform/graph_builder_apply.go index d54a70948..c753cd97c 100644 --- a/terraform/graph_builder_apply.go +++ b/terraform/graph_builder_apply.go @@ -54,15 +54,18 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer { State: b.State, }, - // Attach the configuration to any resources - &AttachResourceConfigTransformer{Module: b.Module}, - // Create orphan output nodes &OrphanOutputTransformer{Module: b.Module, State: b.State}, + // Attach the configuration to any resources + &AttachResourceConfigTransformer{Module: b.Module}, + // Attach the state &AttachStateTransformer{State: b.State}, + // Destruction ordering + &DestroyEdgeTransformer{Module: b.Module, State: b.State}, + // Create all the providers &MissingProviderTransformer{Providers: b.Providers, Factory: providerFactory}, &ProviderTransformer{}, diff --git a/terraform/node_resource_apply.go b/terraform/node_resource_apply.go index 7b8d7b0ed..b3dc4bd53 100644 --- a/terraform/node_resource_apply.go +++ b/terraform/node_resource_apply.go @@ -34,23 +34,27 @@ func (n *NodeApplyableResource) ReferenceableName() []string { // GraphNodeReferencer func (n *NodeApplyableResource) References() []string { - // Let's make this a little shorter so it is easier to reference - c := n.Config - if c == nil { - return nil + // If we have a config, that is our source of truth + if c := n.Config; c != nil { + // Grab all the references + var result []string + result = append(result, c.DependsOn...) + result = append(result, ReferencesFromConfig(c.RawCount)...) + result = append(result, ReferencesFromConfig(c.RawConfig)...) + for _, p := range c.Provisioners { + result = append(result, ReferencesFromConfig(p.ConnInfo)...) + result = append(result, ReferencesFromConfig(p.RawConfig)...) + } + + return result } - // Grab all the references - var result []string - result = append(result, c.DependsOn...) - result = append(result, ReferencesFromConfig(c.RawCount)...) - result = append(result, ReferencesFromConfig(c.RawConfig)...) - for _, p := range c.Provisioners { - result = append(result, ReferencesFromConfig(p.ConnInfo)...) - result = append(result, ReferencesFromConfig(p.RawConfig)...) + // If we have state, that is our next source + if s := n.ResourceState; s != nil { + return s.Dependencies } - return result + return nil } // GraphNodeProviderConsumer diff --git a/terraform/node_resource_destroy.go b/terraform/node_resource_destroy.go index c4cb5fac5..e0d558528 100644 --- a/terraform/node_resource_destroy.go +++ b/terraform/node_resource_destroy.go @@ -30,6 +30,11 @@ func (n *NodeDestroyResource) ProvidedBy() []string { return []string{resourceProvider(n.Addr.Type, "")} } +// GraphNodeDestroyer +func (n *NodeDestroyResource) DestroyAddr() *ResourceAddress { + return n.Addr +} + // GraphNodeAttachResourceState func (n *NodeDestroyResource) ResourceAddr() *ResourceAddress { return n.Addr