1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-26 07:43:46 +01:00

Add Yandex.Cloud provider (#148)

This commit is contained in:
Dmitry Gadeev 2020-06-22 20:14:15 +05:00 committed by GitHub
parent c7e468f33c
commit e313c510c2
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

@ -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.

@ -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
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] = "<error>"
}
}
default:
ret[k+"."+strconv.Itoa(kk)] = "<error>"
}
}

@ -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
}