diff --git a/terraform/graph_builder_plan.go b/terraform/graph_builder_plan.go index 1bea33c1b..b52a51aa3 100644 --- a/terraform/graph_builder_plan.go +++ b/terraform/graph_builder_plan.go @@ -90,7 +90,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer { &OutputTransformer{Config: b.Config}, // Add orphan resources - &OrphanResourceTransformer{ + &OrphanResourceInstanceTransformer{ Concrete: b.ConcreteResourceOrphan, State: b.State, Config: b.Config, diff --git a/terraform/graph_builder_refresh.go b/terraform/graph_builder_refresh.go index a3b3de4f8..d2459eeeb 100644 --- a/terraform/graph_builder_refresh.go +++ b/terraform/graph_builder_refresh.go @@ -123,7 +123,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer { // Add any fully-orphaned resources from config (ones that have been // removed completely, not ones that are just orphaned due to a scaled-in // count. - &OrphanResourceTransformer{ + &OrphanResourceInstanceTransformer{ Concrete: concreteManagedResourceInstance, State: b.State, Config: b.Config, diff --git a/terraform/transform_orphan_resource.go b/terraform/transform_orphan_resource.go index 6a7995395..5ad9fe7b3 100644 --- a/terraform/transform_orphan_resource.go +++ b/terraform/transform_orphan_resource.go @@ -6,13 +6,15 @@ import ( "github.com/hashicorp/terraform/states" ) -// OrphanResourceTransformer is a GraphTransformer that adds resource -// orphans to the graph. A resource orphan is a resource that is -// represented in the state but not in the configuration. -// -// This only adds orphans that have no representation at all in the +// OrphanResourceInstanceTransformer is a GraphTransformer that adds orphaned +// resource instances to the graph. An "orphan" is an instance that is present +// in the state but belongs to a resource that is no longer present in the // configuration. -type OrphanResourceTransformer struct { +// +// This is not the transformer that deals with "count orphans" (instances that +// are no longer covered by a resource's "count" or "for_each" setting); that's +// handled instead by OrphanResourceCountTransformer. +type OrphanResourceInstanceTransformer struct { Concrete ConcreteResourceInstanceNodeFunc // State is the global state. We require the global state to @@ -24,7 +26,7 @@ type OrphanResourceTransformer struct { Config *configs.Config } -func (t *OrphanResourceTransformer) Transform(g *Graph) error { +func (t *OrphanResourceInstanceTransformer) Transform(g *Graph) error { if t.State == nil { // If the entire state is nil, there can't be any orphans return nil @@ -32,7 +34,7 @@ func (t *OrphanResourceTransformer) Transform(g *Graph) error { if t.Config == nil { // Should never happen: we can't be doing any Terraform operations // without at least an empty configuration. - panic("OrpahResourceTransformer used without setting Config") + panic("OrphanResourceInstanceTransformer used without setting Config") } // Go through the modules and for each module transform in order @@ -46,7 +48,7 @@ func (t *OrphanResourceTransformer) Transform(g *Graph) error { return nil } -func (t *OrphanResourceTransformer) transform(g *Graph, ms *states.Module) error { +func (t *OrphanResourceInstanceTransformer) transform(g *Graph, ms *states.Module) error { if ms == nil { return nil } diff --git a/terraform/transform_orphan_resource_test.go b/terraform/transform_orphan_resource_test.go index b0af2b4cc..fed351cc1 100644 --- a/terraform/transform_orphan_resource_test.go +++ b/terraform/transform_orphan_resource_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform/states" ) -func TestOrphanResourceTransformer(t *testing.T) { +func TestOrphanResourceInstanceTransformer(t *testing.T) { mod := testModule(t, "transform-orphan-basic") state := states.BuildState(func(s *states.SyncState) { @@ -59,7 +59,7 @@ func TestOrphanResourceTransformer(t *testing.T) { } { - tf := &OrphanResourceTransformer{ + tf := &OrphanResourceInstanceTransformer{ Concrete: testOrphanResourceConcreteFunc, State: state, Config: mod, @@ -76,7 +76,7 @@ func TestOrphanResourceTransformer(t *testing.T) { } } -func TestOrphanResourceTransformer_countGood(t *testing.T) { +func TestOrphanResourceInstanceTransformer_countGood(t *testing.T) { mod := testModule(t, "transform-orphan-count") state := states.BuildState(func(s *states.SyncState) { @@ -123,7 +123,7 @@ func TestOrphanResourceTransformer_countGood(t *testing.T) { } { - tf := &OrphanResourceTransformer{ + tf := &OrphanResourceInstanceTransformer{ Concrete: testOrphanResourceConcreteFunc, State: state, Config: mod, @@ -140,7 +140,7 @@ func TestOrphanResourceTransformer_countGood(t *testing.T) { } } -func TestOrphanResourceTransformer_countBad(t *testing.T) { +func TestOrphanResourceInstanceTransformer_countBad(t *testing.T) { mod := testModule(t, "transform-orphan-count-empty") state := states.BuildState(func(s *states.SyncState) { s.SetResourceInstanceCurrent( @@ -186,7 +186,7 @@ func TestOrphanResourceTransformer_countBad(t *testing.T) { } { - tf := &OrphanResourceTransformer{ + tf := &OrphanResourceInstanceTransformer{ Concrete: testOrphanResourceConcreteFunc, State: state, Config: mod, @@ -203,7 +203,7 @@ func TestOrphanResourceTransformer_countBad(t *testing.T) { } } -func TestOrphanResourceTransformer_modules(t *testing.T) { +func TestOrphanResourceInstanceTransformer_modules(t *testing.T) { mod := testModule(t, "transform-orphan-modules") state := states.BuildState(func(s *states.SyncState) { s.SetResourceInstanceCurrent( @@ -249,7 +249,7 @@ func TestOrphanResourceTransformer_modules(t *testing.T) { } { - tf := &OrphanResourceTransformer{ + tf := &OrphanResourceInstanceTransformer{ Concrete: testOrphanResourceConcreteFunc, State: state, Config: mod,