diff --git a/internal/terraform/context_apply2_test.go b/internal/terraform/context_apply2_test.go index a9610b725c..afbe9db044 100644 --- a/internal/terraform/context_apply2_test.go +++ b/internal/terraform/context_apply2_test.go @@ -923,7 +923,7 @@ variable "in" { type = map(string) default = { "a" = "first" - "b" = "second" + "b" = "second" } } diff --git a/internal/terraform/graph_builder_plan.go b/internal/terraform/graph_builder_plan.go index 6879664d31..ed63675d22 100644 --- a/internal/terraform/graph_builder_plan.go +++ b/internal/terraform/graph_builder_plan.go @@ -82,9 +82,9 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer { steps := []GraphTransformer{ // Creates all the resources represented in the config &ConfigTransformer{ - Concrete: b.ConcreteResource, - Config: b.Config, - destroyPlan: b.destroy, + Concrete: b.ConcreteResource, + Config: b.Config, + skip: b.destroy, }, // Add dynamic values @@ -92,17 +92,17 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer { &ModuleVariableTransformer{Config: b.Config}, &LocalTransformer{Config: b.Config}, &OutputTransformer{ - Config: b.Config, - RefreshOnly: b.skipPlanChanges, - destroyPlan: b.destroy, + Config: b.Config, + RefreshOnly: b.skipPlanChanges, + removeRootOutputs: b.destroy, }, // Add orphan resources &OrphanResourceInstanceTransformer{ - Concrete: b.ConcreteResourceOrphan, - State: b.State, - Config: b.Config, - destroyPlan: b.destroy, + Concrete: b.ConcreteResourceOrphan, + State: b.State, + Config: b.Config, + skip: b.destroy, }, // We also need nodes for any deposed instance objects present in the diff --git a/internal/terraform/transform_config.go b/internal/terraform/transform_config.go index f404c80d0a..3895efebb2 100644 --- a/internal/terraform/transform_config.go +++ b/internal/terraform/transform_config.go @@ -29,18 +29,17 @@ type ConfigTransformer struct { ModeFilter bool Mode addrs.ResourceMode - // destroyPlan indicated this is being called from a destroy plan. - destroyPlan bool + // Do not apply this transformer. + skip bool } func (t *ConfigTransformer) Transform(g *Graph) error { - // If no configuration is available, we don't do anything - if t.Config == nil { + if t.skip { return nil } - // Configured resource are not added for a destroy plan - if t.destroyPlan { + // If no configuration is available, we don't do anything + if t.Config == nil { return nil } diff --git a/internal/terraform/transform_destroy_edge.go b/internal/terraform/transform_destroy_edge.go index 2132897162..c6cc59397a 100644 --- a/internal/terraform/transform_destroy_edge.go +++ b/internal/terraform/transform_destroy_edge.go @@ -4,7 +4,6 @@ import ( "log" "github.com/hashicorp/terraform/internal/addrs" - "github.com/hashicorp/terraform/internal/dag" ) diff --git a/internal/terraform/transform_orphan_resource.go b/internal/terraform/transform_orphan_resource.go index e218d8970e..974fdf0de3 100644 --- a/internal/terraform/transform_orphan_resource.go +++ b/internal/terraform/transform_orphan_resource.go @@ -27,13 +27,12 @@ type OrphanResourceInstanceTransformer struct { // the appropriate note in this tree using the path in each node. Config *configs.Config - // There are no orphans when doing a full destroy - destroyPlan bool + // Do not apply this transformer + skip bool } func (t *OrphanResourceInstanceTransformer) Transform(g *Graph) error { - if t.destroyPlan { - // everything is being destroyed, so don't worry about orphaned instances + if t.skip { return nil } diff --git a/internal/terraform/transform_output.go b/internal/terraform/transform_output.go index 6805a465a9..107330ec2d 100644 --- a/internal/terraform/transform_output.go +++ b/internal/terraform/transform_output.go @@ -21,7 +21,7 @@ type OutputTransformer struct { // If this is a planned destroy, root outputs are still in the configuration // so we need to record that we wish to remove them - destroyPlan bool + removeRootOutputs bool // Refresh-only mode means that any failing output preconditions are // reported as warnings rather than errors @@ -66,7 +66,7 @@ func (t *OutputTransformer) transform(g *Graph, c *configs.Config) error { } } - destroy := t.destroyPlan + destroy := t.removeRootOutputs if rootChange != nil { destroy = rootChange.Action == plans.Delete } @@ -95,7 +95,7 @@ func (t *OutputTransformer) transform(g *Graph, c *configs.Config) error { Addr: addr, Module: c.Path, Config: o, - Destroy: t.destroyPlan, + Destroy: t.removeRootOutputs, RefreshOnly: t.RefreshOnly, } }