From 54b961630dc13e3a5802f4f931a72a8425bda939 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 24 Jun 2015 21:23:37 -0700 Subject: [PATCH] terraform: module computed vars with splat vars don't error --- terraform/context_test.go | 17 +++++++++++++++++ terraform/interpolate.go | 8 ++++++++ .../refresh-module-computed-var/child/main.tf | 5 +++++ .../refresh-module-computed-var/main.tf | 8 ++++++++ 4 files changed, 38 insertions(+) create mode 100644 terraform/test-fixtures/refresh-module-computed-var/child/main.tf create mode 100644 terraform/test-fixtures/refresh-module-computed-var/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index db16e4e0894d..fb8d98ce00c2 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -1935,6 +1935,23 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) { } } +func TestContext2Refresh_moduleComputedVar(t *testing.T) { + p := testProvider("aws") + m := testModule(t, "refresh-module-computed-var") + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + // This was failing (see GH-2188) at some point, so this test just + // verifies that the failure goes away. + if _, err := ctx.Refresh(); err != nil { + t.Fatalf("err: %s", err) + } +} + func TestContext2Refresh_delete(t *testing.T) { p := testProvider("aws") m := testModule(t, "refresh-basic") diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 15b51fcb2f0c..c51000a3720e 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -437,6 +437,14 @@ func (i *Interpolater) computeResourceMultiVariable( } if len(values) == 0 { + // If the operation is refresh, it isn't an error for a value to + // be unknown. Instead, we return that the value is computed so + // that the graph can continue to refresh other nodes. It doesn't + // matter because the config isn't interpolated anyways. + if i.Operation == walkRefresh { + return config.UnknownVariableValue, nil + } + return "", fmt.Errorf( "Resource '%s' does not have attribute '%s' "+ "for variable '%s'", diff --git a/terraform/test-fixtures/refresh-module-computed-var/child/main.tf b/terraform/test-fixtures/refresh-module-computed-var/child/main.tf new file mode 100644 index 000000000000..38260d6373c5 --- /dev/null +++ b/terraform/test-fixtures/refresh-module-computed-var/child/main.tf @@ -0,0 +1,5 @@ +variable "value" {} + +output "value" { + value = "${var.value}" +} diff --git a/terraform/test-fixtures/refresh-module-computed-var/main.tf b/terraform/test-fixtures/refresh-module-computed-var/main.tf new file mode 100644 index 000000000000..a8573327b154 --- /dev/null +++ b/terraform/test-fixtures/refresh-module-computed-var/main.tf @@ -0,0 +1,8 @@ +module "child" { + source = "./child" + value = "${join(" ", aws_instance.test.*.id)}" +} + +resource "aws_instance" "test" { + value = "yes" +}