@@ -161,6 +161,66 @@ func TestOrphanResourceCountTransformer_oneIndex(t *testing.T) {
161161 }
162162}
163163
164+ func TestOrphanResourceCountTransformer_deposed (t * testing.T ) {
165+ state := states .NewState ()
166+ root := state .RootModule ()
167+ root .SetResourceInstanceCurrent (
168+ mustResourceInstanceAddr ("aws_instance.web" ).Resource ,
169+ & states.ResourceInstanceObjectSrc {
170+ Status : states .ObjectReady ,
171+ AttrsJSON : []byte (`{"id":"foo"}` ),
172+ },
173+ mustProviderConfig (`provider["registry.terraform.io/hashicorp/aws"]` ),
174+ )
175+ root .SetResourceInstanceCurrent (
176+ mustResourceInstanceAddr ("aws_instance.foo[0]" ).Resource ,
177+ & states.ResourceInstanceObjectSrc {
178+ Status : states .ObjectReady ,
179+ AttrsJSON : []byte (`{"id":"foo"}` ),
180+ },
181+ mustProviderConfig (`provider["registry.terraform.io/hashicorp/aws"]` ),
182+ )
183+ root .SetResourceInstanceCurrent (
184+ mustResourceInstanceAddr ("aws_instance.foo[1]" ).Resource ,
185+ & states.ResourceInstanceObjectSrc {
186+ Status : states .ObjectReady ,
187+ AttrsJSON : []byte (`{"id":"foo"}` ),
188+ },
189+ mustProviderConfig (`provider["registry.terraform.io/hashicorp/aws"]` ),
190+ )
191+ root .SetResourceInstanceDeposed (
192+ mustResourceInstanceAddr ("aws_instance.foo[2]" ).Resource ,
193+ states .NewDeposedKey (),
194+ & states.ResourceInstanceObjectSrc {
195+ Status : states .ObjectReady ,
196+ AttrsJSON : []byte (`{"id":"foo"}` ),
197+ },
198+ mustProviderConfig (`provider["registry.terraform.io/hashicorp/aws"]` ),
199+ )
200+
201+ g := Graph {Path : addrs .RootModuleInstance }
202+
203+ {
204+ tf := & OrphanResourceInstanceCountTransformer {
205+ Concrete : testOrphanResourceConcreteFunc ,
206+ Addr : addrs .RootModuleInstance .Resource (
207+ addrs .ManagedResourceMode , "aws_instance" , "foo" ,
208+ ),
209+ InstanceAddrs : []addrs.AbsResourceInstance {mustResourceInstanceAddr ("aws_instance.foo[0]" )},
210+ State : state ,
211+ }
212+ if err := tf .Transform (& g ); err != nil {
213+ t .Fatalf ("err: %s" , err )
214+ }
215+ }
216+
217+ actual := strings .TrimSpace (g .String ())
218+ expected := strings .TrimSpace (testTransformOrphanResourceCountDeposedStr )
219+ if actual != expected {
220+ t .Fatalf ("bad:\n \n %s" , actual )
221+ }
222+ }
223+
164224// When converting from a NoEach mode to an EachMap via a switch to for_each,
165225// an edge is necessary to ensure that the map-key'd instances
166226// are evaluated after the NoKey resource, because the final instance evaluated
@@ -236,6 +296,10 @@ const testTransformOrphanResourceCountOneIndexStr = `
236296aws_instance.foo[1] (orphan)
237297`
238298
299+ const testTransformOrphanResourceCountDeposedStr = `
300+ aws_instance.foo[1] (orphan)
301+ `
302+
239303const testTransformOrphanResourceForEachStr = `
240304aws_instance.foo (orphan)
241305aws_instance.foo["bar"] (orphan)
0 commit comments