diff --git a/parser.go b/parser.go index 8d05d88..47f4043 100644 --- a/parser.go +++ b/parser.go @@ -65,7 +65,7 @@ type moduleStateTerraform0dot12 struct { } type resourceStateTerraform0dot12 struct { Address string `json:"address"` - Index *int `json:"index"` // only set by Terraform for counted resources + Index *interface{} `json:"index"` // only set by Terraform for counted resources Name string `json:"name"` RawValues map[string]interface{} `json:"values"` Type string `json:"type"` @@ -324,7 +324,17 @@ func (s *stateTerraform0dot12) resources() []*Resource { } resourceKeyName := rs.Type + "." + modulePrefix + rs.Name if rs.Index != nil { - resourceKeyName += "." + strconv.Itoa(*rs.Index) + i := *rs.Index + switch v := i.(type) { + case int: + resourceKeyName += "." + strconv.Itoa(v) + case float64: + resourceKeyName += "." + strconv.Itoa(int(v)) + case string: + resourceKeyName += "." + v + default: + fmt.Fprintf(os.Stderr, "Warning: unknown index type %v\n", v) + } } // Terraform stores resources in a name->map map, but we need the name to diff --git a/parser_test.go b/parser_test.go index ad2af80..0ac028a 100644 --- a/parser_test.go +++ b/parser_test.go @@ -943,6 +943,35 @@ const exampleStateFileTerraform0dot12 = ` } } }, + { + "address": "aws_route53_record.this", + "mode": "managed", + "type": "aws_route53_record", + "name": "this", + "index": "testb", + "provider_name": "aws", + "schema_version": 2, + "values": { + "alias": [], + "allow_overwrite": null, + "failover_routing_policy": [], + "fqdn": "testb.tv", + "geolocation_routing_policy": [], + "health_check_id": null, + "id": "abc.tv._A", + "latency_routing_policy": [], + "multivalue_answer_routing_policy": null, + "name": "testb.tv", + "records": [ + "2.2.2.2" + ], + "set_identifier": null, + "ttl": 300, + "type": "A", + "weighted_routing_policy": [], + "zone_id": "abc" + } + }, { "address": "vsphere_tag.bar", "mode": "managed",