diff --git a/README.md b/README.md index 3660a86..b96a760 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The following providers are supported: * VMware * Nutanix * Open Telekom Cloud +* Yandex.Cloud It's very simple to add support for new providers. See pull requests with the [provider][pv] label for examples. diff --git a/parser.go b/parser.go index 47f4043..d2bffe9 100644 --- a/parser.go +++ b/parser.go @@ -287,9 +287,18 @@ func encodeTerraform0Dot12ValuesAsAttributes(rawValues *map[string]interface{}) case []interface{}: ret[k+".#"] = strconv.Itoa(len(v)) for kk, vv := range v { - if str, typeOk := vv.(string); typeOk { - ret[k+"."+strconv.Itoa(kk)] = str - } else { + switch o := vv.(type) { + case string: + ret[k+"."+strconv.Itoa(kk)] = o + case map[string]interface{}: + for kkk, vvv := range o { + if str, typeOk := vvv.(string); typeOk { + ret[k+"."+strconv.Itoa(kk)+"."+kkk] = str + } else { + ret[k+"."+strconv.Itoa(kk)+"."+kkk] = "" + } + } + default: ret[k+"."+strconv.Itoa(kk)] = "" } } diff --git a/resource.go b/resource.go index d9bdc76..7c9f025 100644 --- a/resource.go +++ b/resource.go @@ -36,6 +36,8 @@ func init() { "network.0.address", // Packet "primary_ip", // Profitbricks "nic_list.0.ip_endpoint_list.0.ip", // Nutanix + "network_interface.0.nat_ip_address", // Yandex + "network_interface.0.ip_address", // Yandex } // Formats: @@ -186,7 +188,20 @@ func (r Resource) Tags() map[string]string { t[kk] = vv } } + case "yandex_compute_instance": + for k, v := range r.Attributes() { + parts := strings.SplitN(k, ".", 2) + // At some point Terraform changed the key for counts of attributes to end with ".%" + // instead of ".#". Both need to be considered as Terraform still supports state + // files using the old format. + if len(parts) == 2 && parts[0] == "labels" && parts[1] != "#" && parts[1] != "%" { + kk := strings.ToLower(parts[1]) + vv := strings.ToLower(v) + t[kk] = vv + } + } } + return t }