diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index f87bb720c..cc92b6c97 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -11011,3 +11011,44 @@ module.mod2: t.Fatalf("expected:\n%s\ngot:\n%s\n", expected, state) } } + +func TestContext2Apply_inheritAndStoreCBD(t *testing.T) { + m := testModuleInline(t, map[string]string{ + "main.tf": ` +resource "aws_instance" "foo" { +} + +resource "aws_instance" "cbd" { + foo = aws_instance.foo.id + lifecycle { + create_before_destroy = true + } +} +`, + }) + + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + ctx := testContext2(t, &ContextOpts{ + Config: m, + Providers: map[addrs.Provider]providers.Factory{ + addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), + }, + }) + + _, diags := ctx.Plan() + if diags.HasErrors() { + t.Fatal(diags.ErrWithWarnings()) + } + + state, diags := ctx.Apply() + if diags.HasErrors() { + t.Fatal(diags.ErrWithWarnings()) + } + + foo := state.ResourceInstance(mustResourceInstanceAddr("aws_instance.foo")) + if !foo.Current.CreateBeforeDestroy { + t.Fatal("aws_instance.foo should also be create_before_destroy") + } +}