diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 855548c055..19dcf21f51 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -594,10 +594,6 @@ func (i *Interpolater) computeResourceMultiVariable( } if singleAttr, ok := r.Primary.Attributes[v.Field]; ok { - if singleAttr == config.UnknownVariableValue { - return &unknownVariable, nil - } - values = append(values, singleAttr) continue } @@ -613,10 +609,6 @@ func (i *Interpolater) computeResourceMultiVariable( return nil, err } - if multiAttr == unknownVariable { - return &unknownVariable, nil - } - values = append(values, multiAttr) } diff --git a/terraform/interpolate_test.go b/terraform/interpolate_test.go index 6f1d2c3448..60605fc331 100644 --- a/terraform/interpolate_test.go +++ b/terraform/interpolate_test.go @@ -359,8 +359,81 @@ func TestInterpolater_resourceVariableMulti(t *testing.T) { } testInterpolate(t, i, scope, "aws_instance.web.*.foo", ast.Variable{ - Value: config.UnknownVariableValue, - Type: ast.TypeUnknown, + Type: ast.TypeList, + Value: []ast.Variable{ + { + Type: ast.TypeUnknown, + Value: config.UnknownVariableValue, + }, + }, + }) +} + +func TestInterpolater_resourceVariableMultiPartialUnknown(t *testing.T) { + lock := new(sync.RWMutex) + state := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.web.0": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": "1", + }, + }, + }, + "aws_instance.web.1": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": config.UnknownVariableValue, + }, + }, + }, + "aws_instance.web.2": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": "2", + }, + }, + }, + }, + }, + }, + } + + i := &Interpolater{ + Module: testModule(t, "interpolate-resource-variable-multi"), + State: state, + StateLock: lock, + } + + scope := &InterpolationScope{ + Path: rootModulePath, + } + + testInterpolate(t, i, scope, "aws_instance.web.*.foo", ast.Variable{ + Type: ast.TypeList, + Value: []ast.Variable{ + { + Type: ast.TypeString, + Value: "1", + }, + { + Type: ast.TypeUnknown, + Value: config.UnknownVariableValue, + }, + { + Type: ast.TypeString, + Value: "2", + }, + }, }) } @@ -408,8 +481,13 @@ func TestInterpolater_resourceVariableMultiList(t *testing.T) { } testInterpolate(t, i, scope, "aws_instance.web.*.ip", ast.Variable{ - Value: config.UnknownVariableValue, - Type: ast.TypeUnknown, + Type: ast.TypeList, + Value: []ast.Variable{ + { + Type: ast.TypeUnknown, + Value: config.UnknownVariableValue, + }, + }, }) } diff --git a/terraform/test-fixtures/interpolate-resource-variable-multi/main.tf b/terraform/test-fixtures/interpolate-resource-variable-multi/main.tf new file mode 100644 index 0000000000..b00b04eff9 --- /dev/null +++ b/terraform/test-fixtures/interpolate-resource-variable-multi/main.tf @@ -0,0 +1,3 @@ +resource "aws_instance" "web" { + count = 3 +}