diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index c5bc754b6..c22e87a1c 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -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) + } +} diff --git a/terraform/test-fixtures/provider-with-locals/main.tf b/terraform/test-fixtures/provider-with-locals/main.tf new file mode 100644 index 000000000..44b6d46b3 --- /dev/null +++ b/terraform/test-fixtures/provider-with-locals/main.tf @@ -0,0 +1,11 @@ +provider "aws" { + alias = "${local.foo}" +} + +locals { + foo = "bar" +} + +resource "aws_instance" "foo" { + value = "${local.foo}" +}