From 1664d4e228094fdb416c1aff633f772b75c8b0a4 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 10 Aug 2017 14:12:59 -0400 Subject: [PATCH] test with bad interpolation during Input The interpolation going into a module variable here will be valid after Refresh, but Refresh doesn't happen for the Input phase. --- terraform/context_input_test.go | 54 +++++++++++++++++++ .../input-module-data-vars/child/main.tf | 5 ++ .../input-module-data-vars/main.tf | 8 +++ 3 files changed, 67 insertions(+) create mode 100644 terraform/test-fixtures/input-module-data-vars/child/main.tf create mode 100644 terraform/test-fixtures/input-module-data-vars/main.tf diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 928c11477..750db918a 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -719,3 +719,57 @@ func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) { t.Fatalf("err: %s", err) } } + +// In this case, a module variable can't be resolved from a data source until +// it's refreshed, but it can't be refreshed during Input. +func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) { + input := new(MockUIInput) + p := testProvider("null") + m := testModule(t, "input-module-data-vars") + + p.ReadDataDiffFn = testDataDiffFn + + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "data.null_data_source.bar": &ResourceState{ + Type: "null_data_source", + Primary: &InstanceState{ + ID: "-", + Attributes: map[string]string{ + "foo.#": "1", + "foo.0": "a", + // foo.1 exists in the data source, but needs to be refreshed. + }, + }, + }, + }, + }, + }, + } + + ctx := testContext2(t, &ContextOpts{ + Module: m, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), + State: state, + UIInput: input, + }) + + if err := ctx.Input(InputModeStd); err != nil { + t.Fatalf("err: %s", err) + } + + // ensure that plan works after Refresh + if _, err := ctx.Refresh(); err != nil { + t.Fatalf("err: %s", err) + } + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } +} diff --git a/terraform/test-fixtures/input-module-data-vars/child/main.tf b/terraform/test-fixtures/input-module-data-vars/child/main.tf new file mode 100644 index 000000000..aa5d69bd5 --- /dev/null +++ b/terraform/test-fixtures/input-module-data-vars/child/main.tf @@ -0,0 +1,5 @@ +variable "in" {} + +output "out" { + value = "${var.in}" +} diff --git a/terraform/test-fixtures/input-module-data-vars/main.tf b/terraform/test-fixtures/input-module-data-vars/main.tf new file mode 100644 index 000000000..0a327b102 --- /dev/null +++ b/terraform/test-fixtures/input-module-data-vars/main.tf @@ -0,0 +1,8 @@ +data "null_data_source" "bar" { + foo = ["a", "b"] +} + +module "child" { + source = "./child" + in = "${data.null_data_source.bar.foo[1]}" +}