From 898a7270c48c6f942c35c079d1ae026595f8c346 Mon Sep 17 00:00:00 2001 From: drymonsoon Date: Fri, 9 Jun 2017 21:16:21 +0200 Subject: [PATCH] Add OpenStack metadata integration (#65) --- parser_test.go | 6 +++++- resource.go | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/parser_test.go b/parser_test.go index 5cd7b52..bcc8aa7 100644 --- a/parser_test.go +++ b/parser_test.go @@ -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"] } ` diff --git a/resource.go b/resource.go index af64b13..69d0cc3 100644 --- a/resource.go +++ b/resource.go @@ -98,7 +98,7 @@ func (r Resource) Groups() []string { if v == "" { g := k groups = append(groups, g) - // Key-value + // Key-value } else { g := fmt.Sprintf("%s_%s", k, v) groups = append(groups, g) @@ -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)