From 7735847579e777160664088b830624d0cde876e6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 19 Jul 2015 17:27:38 -0700 Subject: [PATCH] terraform: splatting with computed values is computed [GH-2744] --- terraform/interpolate.go | 5 ++ terraform/interpolate_test.go | 74 +++++++++++++++++++ .../interpolate-resource-variable/main.tf | 1 + 3 files changed, 80 insertions(+) create mode 100644 terraform/test-fixtures/interpolate-resource-variable/main.tf diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 83f6265e1..40a4645f8 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -433,6 +433,11 @@ func (i *Interpolater) computeResourceMultiVariable( continue } + // If any value is unknown, the whole thing is unknown + if attr == config.UnknownVariableValue { + return config.UnknownVariableValue, nil + } + values = append(values, attr) } diff --git a/terraform/interpolate_test.go b/terraform/interpolate_test.go index 52896a54b..af06e429c 100644 --- a/terraform/interpolate_test.go +++ b/terraform/interpolate_test.go @@ -136,6 +136,80 @@ func TestInterpolater_pathRoot(t *testing.T) { }) } +func TestInterpolater_resourceVariable(t *testing.T) { + lock := new(sync.RWMutex) + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.web": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": "bar", + }, + }, + }, + }, + }, + }, + } + + i := &Interpolater{ + Module: testModule(t, "interpolate-resource-variable"), + State: state, + StateLock: lock, + } + + scope := &InterpolationScope{ + Path: rootModulePath, + } + + testInterpolate(t, i, scope, "aws_instance.web.foo", ast.Variable{ + Value: "bar", + Type: ast.TypeString, + }) +} + +func TestInterpolater_resourceVariableMulti(t *testing.T) { + lock := new(sync.RWMutex) + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.web": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": config.UnknownVariableValue, + }, + }, + }, + }, + }, + }, + } + + i := &Interpolater{ + Module: testModule(t, "interpolate-resource-variable"), + State: state, + StateLock: lock, + } + + scope := &InterpolationScope{ + Path: rootModulePath, + } + + testInterpolate(t, i, scope, "aws_instance.web.*.foo", ast.Variable{ + Value: config.UnknownVariableValue, + Type: ast.TypeString, + }) +} + func testInterpolate( t *testing.T, i *Interpolater, scope *InterpolationScope, diff --git a/terraform/test-fixtures/interpolate-resource-variable/main.tf b/terraform/test-fixtures/interpolate-resource-variable/main.tf new file mode 100644 index 000000000..64cbf6236 --- /dev/null +++ b/terraform/test-fixtures/interpolate-resource-variable/main.tf @@ -0,0 +1 @@ +resource "aws_instance" "web" {}