From da0e74276adafdabb19f8360c976323b31e25a37 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 28 Sep 2017 18:21:08 -0400 Subject: [PATCH] fix provider with local value test and docs Make sure this fails during destroy Add a note in the documentation that local values may fail during destroy. --- terraform/context_apply_test.go | 17 +++++++++++++++++ .../test-fixtures/provider-with-locals/main.tf | 2 +- website/docs/configuration/providers.html.md | 7 ++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index c22e87a1c..2ab26e885 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -8872,6 +8872,15 @@ func TestContext2Apply_destroyWithLocals(t *testing.T) { func TestContext2Apply_providerWithLocals(t *testing.T) { m := testModule(t, "provider-with-locals") p := testProvider("aws") + + providerRegion := "" + // this should not be overridden during destroy + p.ConfigureFn = func(c *ResourceConfig) error { + if r, ok := c.Get("region"); ok { + providerRegion = r.(string) + } + return nil + } p.DiffFn = testDiffFn p.ApplyFn = testApplyFn ctx := testContext2(t, &ContextOpts{ @@ -8915,4 +8924,12 @@ func TestContext2Apply_providerWithLocals(t *testing.T) { if state.HasResources() { t.Fatal("expected no state, got:", state) } + + // Destroy won't work because the local value is removed before the + // provider. Once this is fixed this test will start to fail, and we + // can remove the invalid interpolation string; + // if providerRegion != "bar" { + if providerRegion != "${local.foo}" { + t.Fatalf("expected region %q, got: %q", "bar", providerRegion) + } } diff --git a/terraform/test-fixtures/provider-with-locals/main.tf b/terraform/test-fixtures/provider-with-locals/main.tf index 44b6d46b3..3a7db0f87 100644 --- a/terraform/test-fixtures/provider-with-locals/main.tf +++ b/terraform/test-fixtures/provider-with-locals/main.tf @@ -1,5 +1,5 @@ provider "aws" { - alias = "${local.foo}" + region = "${local.foo}" } locals { diff --git a/website/docs/configuration/providers.html.md b/website/docs/configuration/providers.html.md index 5c95d6858..7724be4d1 100644 --- a/website/docs/configuration/providers.html.md +++ b/website/docs/configuration/providers.html.md @@ -187,7 +187,12 @@ provider "aws" { An exception to this is the special `version` attribute that applies to all `provider` blocks for specifying [provider versions](#provider-versions); interpolation is not supported for provider versions since provider compatibility is a property of the configuration rather than something dynamic, and provider plugin installation happens too early for variables to be resolvable in this context. --> **NOTE:** Because providers are one of the first things loaded when Terraform parses the graph, it is not possible to use the output from modules or resources as inputs to the provider. At this time, only [variables](/docs/configuration/variables.html) and [data sources](/docs/configuration/data-sources.html), including [remote state](/docs/providers/terraform/d/remote_state.html) may be used in an interpolation inside a provider stanza. +-> **NOTE:** Because providers are one of the first things loaded when Terraform parses the graph, it is not possible to +use the output from modules or resources as inputs to the provider. At this time, only +[variables](/docs/configuration/variables.html) and [data sources](/docs/configuration/data-sources.html), including +[remote state](/docs/providers/terraform/d/remote_state.html) may be used in an interpolation inside a provider stanza. +[Local values](/docs/configuration/locals.html) can also be used, but currently may fail when running `terraform destroy`. + ## Third-party Plugins