From 983e4f13c613ae361b52984abde1a6397e549d09 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Thu, 23 Jun 2016 21:11:36 +0100 Subject: [PATCH] core: Add context test for empty lists as module outputs This test illustrates a failure which occurs during the Input walk, if an interpolation is used with the input of a splat operation resulting in a multi-variable. The bug was found during use of the RC2, but does not correspond to an open issue at present. --- terraform/context_input_test.go | 21 +++++++++++++++++++ .../main.tf | 9 ++++++++ .../moda/main.tf | 3 +++ .../modb/main.tf | 7 +++++++ 4 files changed, 40 insertions(+) create mode 100644 terraform/test-fixtures/input-module-computed-output-element/main.tf create mode 100644 terraform/test-fixtures/input-module-computed-output-element/moda/main.tf create mode 100644 terraform/test-fixtures/input-module-computed-output-element/modb/main.tf diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 08e017b4c..f953645c8 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -49,6 +49,27 @@ func TestContext2Input(t *testing.T) { } } +func TestContext2Input_moduleComputedOutputElement(t *testing.T) { + m := testModule(t, "input-module-computed-output-element") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { + return c, nil + } + + if err := ctx.Input(InputModeStd); err != nil { + t.Fatalf("err: %s", err) + } +} + func TestContext2Input_badVarDefault(t *testing.T) { m := testModule(t, "input-bad-var-default") p := testProvider("aws") diff --git a/terraform/test-fixtures/input-module-computed-output-element/main.tf b/terraform/test-fixtures/input-module-computed-output-element/main.tf new file mode 100644 index 000000000..bb96e24a3 --- /dev/null +++ b/terraform/test-fixtures/input-module-computed-output-element/main.tf @@ -0,0 +1,9 @@ +module "b" { + source = "./modb" +} + +module "a" { + source = "./moda" + + single_element = "${element(module.b.computed_list, 0)}" +} diff --git a/terraform/test-fixtures/input-module-computed-output-element/moda/main.tf b/terraform/test-fixtures/input-module-computed-output-element/moda/main.tf new file mode 100644 index 000000000..eb09eb192 --- /dev/null +++ b/terraform/test-fixtures/input-module-computed-output-element/moda/main.tf @@ -0,0 +1,3 @@ +variable "single_element" { + type = "string" +} diff --git a/terraform/test-fixtures/input-module-computed-output-element/modb/main.tf b/terraform/test-fixtures/input-module-computed-output-element/modb/main.tf new file mode 100644 index 000000000..ebe4a7eff --- /dev/null +++ b/terraform/test-fixtures/input-module-computed-output-element/modb/main.tf @@ -0,0 +1,7 @@ +resource "aws_instance" "test" { + count = 3 +} + +output "computed_list" { + value = ["${aws_instance.test.*.id}"] +}