@ -13,6 +13,7 @@ import (
"github.com/hashicorp/hil/ast"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/flatmap"
)
const (
@ -213,6 +214,7 @@ func (i *Interpolater) valueResourceVar(
result map [ string ] ast . Variable ) error {
// If we're computing all dynamic fields, then module vars count
// and we mark it as computed.
if i . Operation == walkValidate {
result [ n ] = ast . Variable {
Value : config . UnknownVariableValue ,
@ -343,6 +345,7 @@ func (i *Interpolater) valueUserVar(
func ( i * Interpolater ) computeResourceVariable (
scope * InterpolationScope ,
v * config . ResourceVariable ) ( * ast . Variable , error ) {
id := v . ResourceId ( )
if v . Multi {
id = fmt . Sprintf ( "%s.%d" , id , v . Index )
@ -589,21 +592,19 @@ func (i *Interpolater) interpolateComplexTypeAttribute(
return unknownVariable ( ) , nil
}
var keys [ ] string
keys := make ( [ ] string , 0 )
listElementKey := regexp . MustCompile ( "^" + resourceID + "\\.[0-9]+$" )
for id , _ := range attributes {
if listElementKey . MatchString ( id ) {
keys = append ( keys , id )
}
}
sort . Strings ( keys )
var members [ ] string
for _ , key := range keys {
members = append ( members , attributes [ key ] )
}
// This behaviour still seems very broken to me... it retains BC but is
// probably going to cause problems in future
sort . Strings ( members )
return hil . InterfaceToVariable ( members )
}
@ -620,19 +621,16 @@ func (i *Interpolater) interpolateComplexTypeAttribute(
return unknownVariable ( ) , nil
}
var keys [ ] string
resourceFlatMap := make ( map [ string ] string )
mapElementKey := regexp . MustCompile ( "^" + resourceID + "\\.([^%]+)$" )
for id , _ := range attributes {
if submatches := mapElementKey . FindAllStringSubmatch ( id , - 1 ) ; len ( submatches ) > 0 {
keys = append ( keys , submatches [ 0 ] [ 1 ] )
for id , val := range attributes {
if mapElementKey. MatchString ( id ) {
resourceFlatMap[ id ] = val
}
}
members := make ( map [ string ] interface { } )
for _ , key := range keys {
members [ key ] = attributes [ resourceID + "." + key ]
}
return hil . InterfaceToVariable ( members )
expanded := flatmap . Expand ( resourceFlatMap , resourceID )
return hil . InterfaceToVariable ( expanded )
}
return ast . Variable { } , fmt . Errorf ( "No complex type %s found" , resourceID )