From f7d6fb368a50306ec050bec8ba11439262d769ad Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 26 Oct 2016 16:05:50 -0400 Subject: [PATCH] Add failing test for missing computed map entries The map output from the module "mod" loses the computed value from the template when we validate. If the "extra" field is removed from the map, the validation fails earlier with map "does not have any elements so cannot determine type". Apply will work, because the computed value will exist in the map. --- terraform/context_validate_test.go | 26 +++++++++++++++++++ terraform/test-fixtures/issue-9549/main.tf | 7 +++++ .../test-fixtures/issue-9549/mod/main.tf | 12 +++++++++ 3 files changed, 45 insertions(+) create mode 100644 terraform/test-fixtures/issue-9549/main.tf create mode 100644 terraform/test-fixtures/issue-9549/mod/main.tf diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index 5d80f0333..58d12ef9e 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -821,3 +821,29 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) { t.Fatal("err:", e) } } + +// Computed values are lost when a map is output from a module +func TestContext2Validate_interpolateMap(t *testing.T) { + input := new(MockUIInput) + + m := testModule(t, "issue-9549") + p := testProvider("null") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + UIInput: input, + }) + + w, e := ctx.Validate() + if w != nil { + t.Log("warnings:", w) + } + if e != nil { + t.Fatal("err:", e) + } +} diff --git a/terraform/test-fixtures/issue-9549/main.tf b/terraform/test-fixtures/issue-9549/main.tf new file mode 100644 index 000000000..b60a7c87c --- /dev/null +++ b/terraform/test-fixtures/issue-9549/main.tf @@ -0,0 +1,7 @@ +module "mod" { + source = "./mod" +} + +resource "template_file" "root_template" { + template = "ext: ${module.mod.base_config["base_template"]}" +} diff --git a/terraform/test-fixtures/issue-9549/mod/main.tf b/terraform/test-fixtures/issue-9549/mod/main.tf new file mode 100644 index 000000000..169a39b86 --- /dev/null +++ b/terraform/test-fixtures/issue-9549/mod/main.tf @@ -0,0 +1,12 @@ +resource "template_file" "example" { + template = "template text" +} + +output "base_config" { + value = { + base_template = "${template_file.example.rendered}" + + # without this we fail with no entries + extra = "value" + } +}