Skip to content

Commit

Permalink
minor cleanup from review
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Jun 1, 2022
1 parent ec476af commit e36ee75
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion internal/terraform/context_apply2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ variable "in" {
type = map(string)
default = {
"a" = "first"
"b" = "second"
"b" = "second"
}
}
Expand Down
20 changes: 10 additions & 10 deletions internal/terraform/graph_builder_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,27 @@ 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
&RootVariableTransformer{Config: b.Config, RawValues: b.RootVariableValues},
&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
Expand Down
11 changes: 5 additions & 6 deletions internal/terraform/transform_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion internal/terraform/transform_destroy_edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"log"

"github.com/hashicorp/terraform/internal/addrs"

"github.com/hashicorp/terraform/internal/dag"
)

Expand Down
7 changes: 3 additions & 4 deletions internal/terraform/transform_orphan_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions internal/terraform/transform_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit e36ee75

Please sign in to comment.