test for inherited create_before_destroy in state

This commit is contained in:
James Bardin 2020-05-14 15:33:56 -04:00
parent 7731441beb
commit c052463f62
1 changed files with 41 additions and 0 deletions

View File

@ -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")
}
}