@@ -11944,3 +11944,66 @@ resource "test_instance" "b" {
1194411944 t .Fatalf ("apply errors: %s" , diags .Err ())
1194511945 }
1194611946}
11947+
11948+ func TestContext2Apply_removeReferencedResource (t * testing.T ) {
11949+ m := testModuleInline (t , map [string ]string {
11950+ "main.tf" : `
11951+ variable "ct" {
11952+ }
11953+
11954+ resource "test_resource" "to_remove" {
11955+ count = var.ct
11956+ }
11957+
11958+ resource "test_resource" "c" {
11959+ value = join("", test_resource.to_remove[*].id)
11960+ }
11961+ ` })
11962+
11963+ p := testProvider ("test" )
11964+ p .ApplyFn = testApplyFn
11965+ p .DiffFn = testDiffFn
11966+
11967+ ctx := testContext2 (t , & ContextOpts {
11968+ Config : m ,
11969+ Providers : map [addrs.Provider ]providers.Factory {
11970+ addrs .NewDefaultProvider ("test" ): testProviderFuncFixed (p ),
11971+ },
11972+ Variables : InputValues {
11973+ "ct" : & InputValue {
11974+ Value : cty .NumberIntVal (1 ),
11975+ },
11976+ },
11977+ })
11978+
11979+ if _ , diags := ctx .Plan (); diags .HasErrors () {
11980+ t .Fatalf ("plan errors: %s" , diags .Err ())
11981+ }
11982+
11983+ state , diags := ctx .Apply ()
11984+ if diags .HasErrors () {
11985+ t .Fatalf ("apply errors: %s" , diags .Err ())
11986+ }
11987+
11988+ ctx = testContext2 (t , & ContextOpts {
11989+ Config : m ,
11990+ Providers : map [addrs.Provider ]providers.Factory {
11991+ addrs .NewDefaultProvider ("test" ): testProviderFuncFixed (p ),
11992+ },
11993+ Variables : InputValues {
11994+ "ct" : & InputValue {
11995+ Value : cty .NumberIntVal (0 ),
11996+ },
11997+ },
11998+ State : state ,
11999+ })
12000+
12001+ if _ , diags := ctx .Plan (); diags .HasErrors () {
12002+ t .Fatalf ("plan errors: %s" , diags .Err ())
12003+ }
12004+
12005+ _ , diags = ctx .Apply ()
12006+ if diags .HasErrors () {
12007+ t .Fatalf ("apply errors: %s" , diags .Err ())
12008+ }
12009+ }
0 commit comments