From aaee4df36389059f878aaec4f5b1b6550e85af9c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 21 Sep 2016 18:48:21 -0700 Subject: [PATCH] terraform: working on enabling CBD, some cycles --- terraform/graph_builder_apply.go | 1 + terraform/node_resource_abstract.go | 2 +- terraform/node_resource_destroy.go | 35 ++++++++--------------------- terraform/transform_diff.go | 3 ++- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/terraform/graph_builder_apply.go b/terraform/graph_builder_apply.go index 6929985c8b..598e33adb7 100644 --- a/terraform/graph_builder_apply.go +++ b/terraform/graph_builder_apply.go @@ -74,6 +74,7 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer { // Destruction ordering &DestroyEdgeTransformer{Module: b.Module, State: b.State}, + &CBDEdgeTransformer{Module: b.Module, State: b.State}, // Create all the providers &MissingProviderTransformer{Providers: b.Providers, Factory: providerFactory}, diff --git a/terraform/node_resource_abstract.go b/terraform/node_resource_abstract.go index bdde958bfe..cddccaef26 100644 --- a/terraform/node_resource_abstract.go +++ b/terraform/node_resource_abstract.go @@ -81,7 +81,7 @@ func (n *NodeAbstractResource) ProvidedBy() []string { } // If we have state, then we will use the provider from there - if n.ResourceState != nil { + if n.ResourceState != nil && n.ResourceState.Provider != "" { return []string{n.ResourceState.Provider} } diff --git a/terraform/node_resource_destroy.go b/terraform/node_resource_destroy.go index e0d558528b..af392bdc59 100644 --- a/terraform/node_resource_destroy.go +++ b/terraform/node_resource_destroy.go @@ -6,28 +6,11 @@ import ( // NodeDestroyResource represents a resource that is to be destroyed. type NodeDestroyResource struct { - Addr *ResourceAddress // Addr is the address for this resource - ResourceState *ResourceState // State is the resource state for this resource + *NodeAbstractResource } func (n *NodeDestroyResource) Name() string { - return n.Addr.String() + " (destroy)" -} - -// GraphNodeSubPath -func (n *NodeDestroyResource) Path() []string { - return n.Addr.Path -} - -// GraphNodeProviderConsumer -func (n *NodeDestroyResource) ProvidedBy() []string { - // If we have state, then we will use the provider from there - if n.ResourceState != nil && n.ResourceState.Provider != "" { - return []string{n.ResourceState.Provider} - } - - // Use our type - return []string{resourceProvider(n.Addr.Type, "")} + return n.NodeAbstractResource.Name() + " (destroy)" } // GraphNodeDestroyer @@ -35,14 +18,14 @@ func (n *NodeDestroyResource) DestroyAddr() *ResourceAddress { return n.Addr } -// GraphNodeAttachResourceState -func (n *NodeDestroyResource) ResourceAddr() *ResourceAddress { - return n.Addr -} +// GraphNodeDestroyerCBD +func (n *NodeDestroyResource) CreateBeforeDestroy() bool { + // If we have no config, we just assume no + if n.Config == nil { + return false + } -// GraphNodeAttachResourceState -func (n *NodeDestroyResource) AttachResourceState(s *ResourceState) { - n.ResourceState = s + return n.Config.Lifecycle.CreateBeforeDestroy } // GraphNodeEvalable diff --git a/terraform/transform_diff.go b/terraform/transform_diff.go index d331409118..68e9053461 100644 --- a/terraform/transform_diff.go +++ b/terraform/transform_diff.go @@ -59,7 +59,8 @@ func (t *DiffTransformer) Transform(g *Graph) error { // If we're destroying, add the destroy node if inst.Destroy { - g.Add(&NodeDestroyResource{Addr: addr}) + abstract := &NodeAbstractResource{Addr: addr} + g.Add(&NodeDestroyResource{NodeAbstractResource: abstract}) } // If we have changes, then add the applyable version