Skip to content

Commit 9103095

Browse files
committed
Added support for Hetzner Cloud (hcloud) provider.
1 parent dd5c915 commit 9103095

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
@@ -407,6 +407,34 @@ const exampleStateFile = `
407407
"tags.Role": "worker"
408408
}
409409
}
410+
},
411+
"hcloud_server.eightteen": {
412+
"type": "hcloud_server",
413+
"depends_on": [],
414+
"primary": {
415+
"id": "42",
416+
"attributes": {
417+
"backup_window": "",
418+
"backups": "false",
419+
"datacenter": "fsn1-dc14",
420+
"id": "42",
421+
"image": "1",
422+
"ipv4_address": "10.0.0.18",
423+
"keep_disk": "false",
424+
"labels.%": "1",
425+
"labels.testlabel": "hcloud_test",
426+
"location": "fsn1",
427+
"name": "seventeen",
428+
"server_type": "cx11",
429+
"ssh_keys.#": "1",
430+
"ssh_keys.0": "1337",
431+
"status": "running"
432+
},
433+
"meta": {},
434+
"tainted": false
435+
},
436+
"deposed": [],
437+
"provider": "provider.hcloud"
410438
}
411439
}
412440
}
@@ -423,6 +451,7 @@ const expectedListOutput = `
423451
"10.0.0.11",
424452
"10.0.0.13",
425453
"10.0.0.16",
454+
"10.0.0.18",
426455
"10.0.0.7",
427456
"10.0.0.8",
428457
"10.0.0.9",
@@ -461,6 +490,7 @@ const expectedListOutput = `
461490
"fourteen": ["192.168.102.14"],
462491
"sixteen": ["10.0.0.16"],
463492
"seventeen": ["50.0.0.17"],
493+
"eightteen": ["10.0.0.18"],
464494
465495
"one.0": ["10.0.0.1"],
466496
"dup.0": ["10.0.0.1"],
@@ -480,13 +510,15 @@ const expectedListOutput = `
480510
"fourteen.0": ["192.168.102.14"],
481511
"sixteen.0": ["10.0.0.16"],
482512
"seventeen.0": ["50.0.0.17"],
513+
"eightteen.0": ["10.0.0.18"],
483514
484515
"type_aws_instance": ["10.0.0.1", "10.0.1.1", "50.0.0.1"],
485516
"type_digitalocean_droplet": ["192.168.0.3"],
486517
"type_cloudstack_instance": ["10.2.1.5"],
487518
"type_vsphere_virtual_machine": ["10.20.30.40", "10.20.30.50"],
488519
"type_openstack_compute_instance_v2": ["10.120.0.226"],
489520
"type_profitbricks_server": ["10.0.0.16"],
521+
"type_hcloud_server": ["10.0.0.18"],
490522
"type_softlayer_virtual_guest": ["10.0.0.7"],
491523
"type_exoscale_compute": ["10.0.0.9"],
492524
"type_google_compute_instance": ["10.0.0.8"],
@@ -503,6 +535,7 @@ const expectedListOutput = `
503535
"webserver": ["192.168.0.3"],
504536
"staging": ["192.168.0.3"],
505537
"status_superserver": ["10.120.0.226"],
538+
"testlabel_hcloud_test": ["10.0.0.18"],
506539
"database": ["10.0.0.8"],
507540
"scw_test": ["10.0.0.11"]
508541
}
@@ -514,6 +547,7 @@ const expectedInventoryOutput = `[all]
514547
10.0.0.11
515548
10.0.0.13
516549
10.0.0.16
550+
10.0.0.18
517551
10.0.0.7
518552
10.0.0.8
519553
10.0.0.9
@@ -548,6 +582,12 @@ olddatacenter="\u003c0.7_format"
548582
[eight.0]
549583
10.0.0.8
550584
585+
[eightteen]
586+
10.0.0.18
587+
588+
[eightteen.0]
589+
10.0.0.18
590+
551591
[eleven]
552592
10.0.0.11
553593
@@ -642,6 +682,9 @@ olddatacenter="\u003c0.7_format"
642682
[testTag1]
643683
10.20.30.50
644684
685+
[testlabel_hcloud_test]
686+
10.0.0.18
687+
645688
[thirteen]
646689
10.0.0.13
647690
@@ -686,6 +729,9 @@ olddatacenter="\u003c0.7_format"
686729
[type_google_compute_instance]
687730
10.0.0.8
688731
732+
[type_hcloud_server]
733+
10.0.0.18
734+
689735
[type_libvirt_domain]
690736
192.168.102.14
691737

resource.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ func (r Resource) Tags() map[string]string {
168168
t[kk] = vv
169169
}
170170
}
171+
case "hcloud_server":
172+
for k, v := range r.Attributes() {
173+
parts := strings.SplitN(k, ".", 2)
174+
if len(parts) == 2 && parts[0] == "labels" && parts[1] != "%" {
175+
kk := strings.ToLower(parts[1])
176+
vv := strings.ToLower(v)
177+
t[kk] = vv
178+
}
179+
}
171180
}
172181
return t
173182
}

0 commit comments

Comments
 (0)