diff --git a/terraform/resource.go b/terraform/resource.go index 7d22a6e9b..1d146799e 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -48,14 +48,6 @@ type Resource struct { // its a primary instance, a tainted instance, or an orphan. type ResourceFlag byte -const ( - FlagPrimary ResourceFlag = 1 << iota - FlagTainted - FlagOrphan - FlagReplacePrimary - FlagDeposed -) - // InstanceInfo is used to hold information about the instance and/or // resource being modified. type InstanceInfo struct { @@ -180,7 +172,8 @@ func (c *ResourceConfig) get( } var current interface{} = raw - for _, part := range parts { + var previous interface{} = nil + for i, part := range parts { if current == nil { return nil, false } @@ -188,12 +181,23 @@ func (c *ResourceConfig) get( cv := reflect.ValueOf(current) switch cv.Kind() { case reflect.Map: + previous = current v := cv.MapIndex(reflect.ValueOf(part)) if !v.IsValid() { + if i > 0 && i != (len(parts)-1) { + tryKey := strings.Join(parts[i:], ".") + v := cv.MapIndex(reflect.ValueOf(tryKey)) + if !v.IsValid() { + return nil, false + } + return v.Interface(), true + } + return nil, false } current = v.Interface() case reflect.Slice: + previous = current if part == "#" { current = cv.Len() } else { @@ -206,6 +210,14 @@ func (c *ResourceConfig) get( } current = cv.Index(int(i)).Interface() } + case reflect.String: + // This happens when map keys contain "." and have a common + // prefix so were split as path components above. + actualKey := strings.Join(parts[i-1:], ".") + if prevMap, ok := previous.(map[string]interface{}); ok { + return prevMap[actualKey], true + } + return nil, false default: panic(fmt.Sprintf("Unknown kind: %s", cv.Kind())) }