1
1
mirror of https://github.com/adammck/terraform-inventory synced 2024-11-22 20:01:58 +01:00

Add OpenStack metadata integration (#65)

This commit is contained in:
drymonsoon 2017-06-09 21:16:21 +02:00 committed by Adam Mckaig
parent 6f4c1a9983
commit 898a7270c4
2 changed files with 15 additions and 2 deletions

@ -142,7 +142,10 @@ const exampleStateFile = `
"attributes": {
"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"access_ip_v4": "10.120.0.226",
"access_ip_v6": ""
"access_ip_v6": "",
"metadata.status": "superServer",
"metadata.#": "very bad",
"metadata_toes": "faada2142412jhb1j2"
}
}
},
@ -231,6 +234,7 @@ const expectedListOutput = `
"role_web": ["10.0.0.1"],
"webserver": ["192.168.0.3"],
"staging": ["192.168.0.3"],
"status_superserver": ["10.120.0.226"],
"database": ["10.0.0.8"]
}
`

@ -115,6 +115,15 @@ func (r Resource) Tags() map[string]string {
t := map[string]string{}
switch r.resourceType {
case "openstack_compute_instance_v2":
for k, v := range r.Attributes() {
parts := strings.SplitN(k, ".", 2)
if len(parts) == 2 && parts[0] == "metadata" && parts[1] != "#" {
kk := strings.ToLower(parts[1])
vv := strings.ToLower(v)
t[kk] = vv
}
}
case "aws_instance":
for k, v := range r.Attributes() {
parts := strings.SplitN(k, ".", 2)