diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 870fac762e..b42ca8211a 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -493,7 +493,8 @@ func (i *Interpolater) computeResourceMultiVariable( if module == nil || len(module.Resources) == 0 { return &unknownVariable, nil } - var values []string + + var values []interface{} for j := 0; j < count; j++ { id := fmt.Sprintf("%s.%d", v.ResourceId(), j) @@ -521,9 +522,10 @@ func (i *Interpolater) computeResourceMultiVariable( continue } - // computed list attribute - _, ok = r.Primary.Attributes[v.Field+".#"] - if !ok { + // computed list or map attribute + _, isList := r.Primary.Attributes[v.Field+".#"] + _, isMap := r.Primary.Attributes[v.Field+".%"] + if !(isList || isMap) { continue } multiAttr, err := i.interpolateComplexTypeAttribute(v.Field, r.Primary.Attributes) @@ -535,14 +537,7 @@ func (i *Interpolater) computeResourceMultiVariable( return &ast.Variable{Type: ast.TypeString, Value: ""}, nil } - for _, element := range multiAttr.Value.([]ast.Variable) { - strVal := element.Value.(string) - if strVal == config.UnknownVariableValue { - return &unknownVariable, nil - } - - values = append(values, strVal) - } + values = append(values, multiAttr) } if len(values) == 0 { @@ -595,7 +590,7 @@ func (i *Interpolater) interpolateComplexTypeAttribute( keys := make([]string, 0) listElementKey := regexp.MustCompile("^" + resourceID + "\\.[0-9]+$") - for id, _ := range attributes { + for id := range attributes { if listElementKey.MatchString(id) { keys = append(keys, id) } diff --git a/terraform/interpolate_test.go b/terraform/interpolate_test.go index 8012e16af0..65d716c2eb 100644 --- a/terraform/interpolate_test.go +++ b/terraform/interpolate_test.go @@ -449,11 +449,11 @@ func TestInterpolator_resourceMultiAttributesWithResourceCount(t *testing.T) { // More than 1 element testInterpolate(t, i, scope, "aws_route53_zone.terra.0.name_servers", - interfaceToVariableSwallowError(name_servers[0:4])) + interfaceToVariableSwallowError(name_servers[:4])) // More than 1 element in both testInterpolate(t, i, scope, "aws_route53_zone.terra.*.name_servers", - interfaceToVariableSwallowError(name_servers)) + interfaceToVariableSwallowError([]interface{}{name_servers[:4], name_servers[4:]})) // Exactly 1 element testInterpolate(t, i, scope, "aws_route53_zone.terra.0.listeners", @@ -461,7 +461,7 @@ func TestInterpolator_resourceMultiAttributesWithResourceCount(t *testing.T) { // Exactly 1 element in both testInterpolate(t, i, scope, "aws_route53_zone.terra.*.listeners", - interfaceToVariableSwallowError([]interface{}{"red", "blue"})) + interfaceToVariableSwallowError([]interface{}{[]interface{}{"red"}, []interface{}{"blue"}})) // Zero elements testInterpolate(t, i, scope, "aws_route53_zone.terra.0.nothing", @@ -469,7 +469,7 @@ func TestInterpolator_resourceMultiAttributesWithResourceCount(t *testing.T) { // Zero + 1 element testInterpolate(t, i, scope, "aws_route53_zone.terra.*.special", - interfaceToVariableSwallowError([]interface{}{"extra"})) + interfaceToVariableSwallowError([]interface{}{[]interface{}{"extra"}})) // Maps still need to work testInterpolate(t, i, scope, "aws_route53_zone.terra.0.tags.Name", ast.Variable{