Skip to content

Commit 5b82d05

Browse files
committed
Added support for Hetzner Cloud (hcloud) provider.
1 parent a408e89 commit 5b82d05

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

parser_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,34 @@ const exampleStateFile = `
441441
"tags.#": "0"
442442
}
443443
}
444+
},
445+
"hcloud_server.twenty": {
446+
"type": "hcloud_server",
447+
"depends_on": [],
448+
"primary": {
449+
"id": "42",
450+
"attributes": {
451+
"backup_window": "",
452+
"backups": "false",
453+
"datacenter": "fsn1-dc14",
454+
"id": "42",
455+
"image": "1",
456+
"ipv4_address": "10.0.0.20",
457+
"keep_disk": "false",
458+
"labels.%": "1",
459+
"labels.testlabel": "hcloud_test",
460+
"location": "fsn1",
461+
"name": "twenty",
462+
"server_type": "cx11",
463+
"ssh_keys.#": "1",
464+
"ssh_keys.0": "1337",
465+
"status": "running"
466+
},
467+
"meta": {},
468+
"tainted": false
469+
},
470+
"deposed": [],
471+
"provider": "provider.hcloud"
444472
}
445473
}
446474
}
@@ -458,6 +486,7 @@ const expectedListOutput = `
458486
"10.0.0.13",
459487
"10.0.0.16",
460488
"10.0.0.19",
489+
"10.0.0.20",
461490
"10.0.0.7",
462491
"10.0.0.8",
463492
"10.0.0.9",
@@ -499,6 +528,7 @@ const expectedListOutput = `
499528
"sixteen": ["10.0.0.16"],
500529
"seventeen": ["50.0.0.17"],
501530
"eighteen": ["80.80.100.124"],
531+
"twenty": ["10.0.0.20"],
502532
503533
"one_0": ["10.0.0.1"],
504534
"dup_0": ["10.0.0.1"],
@@ -520,6 +550,7 @@ const expectedListOutput = `
520550
"sixteen_0": ["10.0.0.16"],
521551
"seventeen_0": ["50.0.0.17"],
522552
"eighteen_0": ["80.80.100.124"],
553+
"twenty_0": ["10.0.0.20"],
523554
524555
"type_aws_instance": ["10.0.0.1", "10.0.1.1", "50.0.0.1"],
525556
"type_digitalocean_droplet": ["192.168.0.3"],
@@ -528,6 +559,7 @@ const expectedListOutput = `
528559
"type_openstack_compute_instance_v2": ["10.120.0.226"],
529560
"type_opentelekomcloud_compute_instance_v2": ["10.0.0.19"],
530561
"type_profitbricks_server": ["10.0.0.16"],
562+
"type_hcloud_server": ["10.0.0.20"],
531563
"type_softlayer_virtual_guest": ["10.0.0.7"],
532564
"type_exoscale_compute": ["10.0.0.9"],
533565
"type_google_compute_instance": ["10.0.0.8"],
@@ -546,6 +578,7 @@ const expectedListOutput = `
546578
"webserver": ["192.168.0.3"],
547579
"staging": ["192.168.0.3"],
548580
"status_superserver": ["10.120.0.226"],
581+
"testlabel_hcloud_test": ["10.0.0.20"],
549582
"database": ["10.0.0.8"],
550583
"scw_test": ["10.0.0.11"],
551584
"tfinventory_rocks": ["10.0.0.19"]
@@ -559,6 +592,7 @@ const expectedInventoryOutput = `[all]
559592
10.0.0.13
560593
10.0.0.16
561594
10.0.0.19
595+
10.0.0.20
562596
10.0.0.7
563597
10.0.0.8
564598
10.0.0.9
@@ -703,6 +737,9 @@ olddatacenter="\u003c0.7_format"
703737
[testTag1]
704738
10.20.30.50
705739
740+
[testlabel_hcloud_test]
741+
10.0.0.20
742+
706743
[tfinventory_rocks]
707744
10.0.0.19
708745
@@ -724,6 +761,12 @@ olddatacenter="\u003c0.7_format"
724761
[twelve_0]
725762
10.20.30.50
726763
764+
[twenty]
765+
10.0.0.20
766+
767+
[twenty_0]
768+
10.0.0.20
769+
727770
[two]
728771
50.0.0.1
729772
@@ -750,6 +793,9 @@ olddatacenter="\u003c0.7_format"
750793
[type_google_compute_instance]
751794
10.0.0.8
752795
796+
[type_hcloud_server]
797+
10.0.0.20
798+
753799
[type_libvirt_domain]
754800
192.168.102.14
755801

resource.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ func (r Resource) Tags() map[string]string {
181181
t[kk] = vv
182182
}
183183
}
184+
case "hcloud_server":
185+
for k, v := range r.Attributes() {
186+
parts := strings.SplitN(k, ".", 2)
187+
if len(parts) == 2 && parts[0] == "labels" && parts[1] != "%" {
188+
kk := strings.ToLower(parts[1])
189+
vv := strings.ToLower(v)
190+
t[kk] = vv
191+
}
192+
}
184193
}
185194
return t
186195
}

0 commit comments

Comments
 (0)