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" {}