core: OrphanResourceTransformer -> OrphanResourceInstanceTransformer
This transformer creates resource _instance_ nodes rather than resource nodes, so this name is a clearer descriptor for what it does.
This commit is contained in:
parent
311cdbdcab
commit
a806bb7d8c
|
@ -90,7 +90,7 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
|
||||||
&OutputTransformer{Config: b.Config},
|
&OutputTransformer{Config: b.Config},
|
||||||
|
|
||||||
// Add orphan resources
|
// Add orphan resources
|
||||||
&OrphanResourceTransformer{
|
&OrphanResourceInstanceTransformer{
|
||||||
Concrete: b.ConcreteResourceOrphan,
|
Concrete: b.ConcreteResourceOrphan,
|
||||||
State: b.State,
|
State: b.State,
|
||||||
Config: b.Config,
|
Config: b.Config,
|
||||||
|
|
|
@ -123,7 +123,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
|
||||||
// Add any fully-orphaned resources from config (ones that have been
|
// Add any fully-orphaned resources from config (ones that have been
|
||||||
// removed completely, not ones that are just orphaned due to a scaled-in
|
// removed completely, not ones that are just orphaned due to a scaled-in
|
||||||
// count.
|
// count.
|
||||||
&OrphanResourceTransformer{
|
&OrphanResourceInstanceTransformer{
|
||||||
Concrete: concreteManagedResourceInstance,
|
Concrete: concreteManagedResourceInstance,
|
||||||
State: b.State,
|
State: b.State,
|
||||||
Config: b.Config,
|
Config: b.Config,
|
||||||
|
|
|
@ -6,13 +6,15 @@ import (
|
||||||
"github.com/hashicorp/terraform/states"
|
"github.com/hashicorp/terraform/states"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OrphanResourceTransformer is a GraphTransformer that adds resource
|
// OrphanResourceInstanceTransformer is a GraphTransformer that adds orphaned
|
||||||
// orphans to the graph. A resource orphan is a resource that is
|
// resource instances to the graph. An "orphan" is an instance that is present
|
||||||
// represented in the state but not in the configuration.
|
// in the state but belongs to a resource that is no longer present in the
|
||||||
//
|
|
||||||
// This only adds orphans that have no representation at all in the
|
|
||||||
// configuration.
|
// 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
|
Concrete ConcreteResourceInstanceNodeFunc
|
||||||
|
|
||||||
// State is the global state. We require the global state to
|
// State is the global state. We require the global state to
|
||||||
|
@ -24,7 +26,7 @@ type OrphanResourceTransformer struct {
|
||||||
Config *configs.Config
|
Config *configs.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *OrphanResourceTransformer) Transform(g *Graph) error {
|
func (t *OrphanResourceInstanceTransformer) Transform(g *Graph) error {
|
||||||
if t.State == nil {
|
if t.State == nil {
|
||||||
// If the entire state is nil, there can't be any orphans
|
// If the entire state is nil, there can't be any orphans
|
||||||
return nil
|
return nil
|
||||||
|
@ -32,7 +34,7 @@ func (t *OrphanResourceTransformer) Transform(g *Graph) error {
|
||||||
if t.Config == nil {
|
if t.Config == nil {
|
||||||
// Should never happen: we can't be doing any Terraform operations
|
// Should never happen: we can't be doing any Terraform operations
|
||||||
// without at least an empty configuration.
|
// 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
|
// Go through the modules and for each module transform in order
|
||||||
|
@ -46,7 +48,7 @@ func (t *OrphanResourceTransformer) Transform(g *Graph) error {
|
||||||
return nil
|
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 {
|
if ms == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/hashicorp/terraform/states"
|
"github.com/hashicorp/terraform/states"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOrphanResourceTransformer(t *testing.T) {
|
func TestOrphanResourceInstanceTransformer(t *testing.T) {
|
||||||
mod := testModule(t, "transform-orphan-basic")
|
mod := testModule(t, "transform-orphan-basic")
|
||||||
|
|
||||||
state := states.BuildState(func(s *states.SyncState) {
|
state := states.BuildState(func(s *states.SyncState) {
|
||||||
|
@ -59,7 +59,7 @@ func TestOrphanResourceTransformer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
tf := &OrphanResourceTransformer{
|
tf := &OrphanResourceInstanceTransformer{
|
||||||
Concrete: testOrphanResourceConcreteFunc,
|
Concrete: testOrphanResourceConcreteFunc,
|
||||||
State: state,
|
State: state,
|
||||||
Config: mod,
|
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")
|
mod := testModule(t, "transform-orphan-count")
|
||||||
|
|
||||||
state := states.BuildState(func(s *states.SyncState) {
|
state := states.BuildState(func(s *states.SyncState) {
|
||||||
|
@ -123,7 +123,7 @@ func TestOrphanResourceTransformer_countGood(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
tf := &OrphanResourceTransformer{
|
tf := &OrphanResourceInstanceTransformer{
|
||||||
Concrete: testOrphanResourceConcreteFunc,
|
Concrete: testOrphanResourceConcreteFunc,
|
||||||
State: state,
|
State: state,
|
||||||
Config: mod,
|
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")
|
mod := testModule(t, "transform-orphan-count-empty")
|
||||||
state := states.BuildState(func(s *states.SyncState) {
|
state := states.BuildState(func(s *states.SyncState) {
|
||||||
s.SetResourceInstanceCurrent(
|
s.SetResourceInstanceCurrent(
|
||||||
|
@ -186,7 +186,7 @@ func TestOrphanResourceTransformer_countBad(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
tf := &OrphanResourceTransformer{
|
tf := &OrphanResourceInstanceTransformer{
|
||||||
Concrete: testOrphanResourceConcreteFunc,
|
Concrete: testOrphanResourceConcreteFunc,
|
||||||
State: state,
|
State: state,
|
||||||
Config: mod,
|
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")
|
mod := testModule(t, "transform-orphan-modules")
|
||||||
state := states.BuildState(func(s *states.SyncState) {
|
state := states.BuildState(func(s *states.SyncState) {
|
||||||
s.SetResourceInstanceCurrent(
|
s.SetResourceInstanceCurrent(
|
||||||
|
@ -249,7 +249,7 @@ func TestOrphanResourceTransformer_modules(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
tf := &OrphanResourceTransformer{
|
tf := &OrphanResourceInstanceTransformer{
|
||||||
Concrete: testOrphanResourceConcreteFunc,
|
Concrete: testOrphanResourceConcreteFunc,
|
||||||
State: state,
|
State: state,
|
||||||
Config: mod,
|
Config: mod,
|
||||||
|
|
Loading…
Reference in New Issue