diff --git a/parser_test.go b/parser_test.go index ad2af80..5964ef0 100644 --- a/parser_test.go +++ b/parser_test.go @@ -441,6 +441,34 @@ const exampleStateFile = ` "tags.#": "0" } } + }, + "hcloud_server.twenty": { + "type": "hcloud_server", + "depends_on": [], + "primary": { + "id": "42", + "attributes": { + "backup_window": "", + "backups": "false", + "datacenter": "fsn1-dc14", + "id": "42", + "image": "1", + "ipv4_address": "10.0.0.20", + "keep_disk": "false", + "labels.%": "1", + "labels.testlabel": "hcloud_test", + "location": "fsn1", + "name": "twenty", + "server_type": "cx11", + "ssh_keys.#": "1", + "ssh_keys.0": "1337", + "status": "running" + }, + "meta": {}, + "tainted": false + }, + "deposed": [], + "provider": "provider.hcloud" } } } @@ -458,6 +486,7 @@ const expectedListOutput = ` "10.0.0.13", "10.0.0.16", "10.0.0.19", + "10.0.0.20", "10.0.0.7", "10.0.0.8", "10.0.0.9", @@ -499,6 +528,7 @@ const expectedListOutput = ` "sixteen": ["10.0.0.16"], "seventeen": ["50.0.0.17"], "eighteen": ["80.80.100.124"], + "twenty": ["10.0.0.20"], "one_0": ["10.0.0.1"], "dup_0": ["10.0.0.1"], @@ -520,6 +550,7 @@ const expectedListOutput = ` "sixteen_0": ["10.0.0.16"], "seventeen_0": ["50.0.0.17"], "eighteen_0": ["80.80.100.124"], + "twenty_0": ["10.0.0.20"], "type_aws_instance": ["10.0.0.1", "10.0.1.1", "50.0.0.1"], "type_digitalocean_droplet": ["192.168.0.3"], @@ -528,6 +559,7 @@ const expectedListOutput = ` "type_openstack_compute_instance_v2": ["10.120.0.226"], "type_opentelekomcloud_compute_instance_v2": ["10.0.0.19"], "type_profitbricks_server": ["10.0.0.16"], + "type_hcloud_server": ["10.0.0.20"], "type_softlayer_virtual_guest": ["10.0.0.7"], "type_exoscale_compute": ["10.0.0.9"], "type_google_compute_instance": ["10.0.0.8"], @@ -546,6 +578,7 @@ const expectedListOutput = ` "webserver": ["192.168.0.3"], "staging": ["192.168.0.3"], "status_superserver": ["10.120.0.226"], + "testlabel_hcloud_test": ["10.0.0.20"], "database": ["10.0.0.8"], "scw_test": ["10.0.0.11"], "tfinventory_rocks": ["10.0.0.19"] @@ -559,6 +592,7 @@ const expectedInventoryOutput = `[all] 10.0.0.13 10.0.0.16 10.0.0.19 +10.0.0.20 10.0.0.7 10.0.0.8 10.0.0.9 @@ -703,6 +737,9 @@ olddatacenter="\u003c0.7_format" [testTag1] 10.20.30.50 +[testlabel_hcloud_test] +10.0.0.20 + [tfinventory_rocks] 10.0.0.19 @@ -724,6 +761,12 @@ olddatacenter="\u003c0.7_format" [twelve_0] 10.20.30.50 +[twenty] +10.0.0.20 + +[twenty_0] +10.0.0.20 + [two] 50.0.0.1 @@ -750,6 +793,9 @@ olddatacenter="\u003c0.7_format" [type_google_compute_instance] 10.0.0.8 +[type_hcloud_server] +10.0.0.20 + [type_libvirt_domain] 192.168.102.14 diff --git a/resource.go b/resource.go index 2908fee..c4f1e1b 100644 --- a/resource.go +++ b/resource.go @@ -181,6 +181,15 @@ func (r Resource) Tags() map[string]string { t[kk] = vv } } + case "hcloud_server": + for k, v := range r.Attributes() { + parts := strings.SplitN(k, ".", 2) + if len(parts) == 2 && parts[0] == "labels" && parts[1] != "%" { + kk := strings.ToLower(parts[1]) + vv := strings.ToLower(v) + t[kk] = vv + } + } } return t }