add test for destroying with locals in a provider

Verify that locals aren't removed from the state before providers are
evaluated during destroy.
This commit is contained in:
James Bardin 2017-09-28 15:09:42 -04:00
parent 77396107c4
commit 061597304c
2 changed files with 59 additions and 0 deletions

View File

@ -8868,3 +8868,51 @@ func TestContext2Apply_destroyWithLocals(t *testing.T) {
t.Fatalf("wrong final state\ngot:\n%s\nwant:\n%s", got, want)
}
}
func TestContext2Apply_providerWithLocals(t *testing.T) {
m := testModule(t, "provider-with-locals")
p := testProvider("aws")
p.DiffFn = testDiffFn
p.ApplyFn = testApplyFn
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
})
if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}
state, err := ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
ctx = testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
State: state,
Destroy: true,
})
if _, err = ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}
state, err = ctx.Apply()
if err != nil {
t.Fatalf("err: %s", err)
}
if state.HasResources() {
t.Fatal("expected no state, got:", state)
}
}

View File

@ -0,0 +1,11 @@
provider "aws" {
alias = "${local.foo}"
}
locals {
foo = "bar"
}
resource "aws_instance" "foo" {
value = "${local.foo}"
}