From c7e468f33c6f4195cd9d8e97fa0e8d54b5c61c29 Mon Sep 17 00:00:00 2001 From: Michael Hofer Date: Fri, 21 Feb 2020 18:46:37 +0100 Subject: [PATCH] Support OTC metadata parsing (#141) --- parser_test.go | 9 +++++++-- resource.go | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/parser_test.go b/parser_test.go index 0ac028a..2089b82 100644 --- a/parser_test.go +++ b/parser_test.go @@ -404,7 +404,8 @@ const exampleStateFile = ` "access_ip_v4": "10.0.0.19", "access_ip_v6": "", "tag.%": "1", - "tag.tfinventory": "rocks" + "tag.tfinventory": "rocks", + "metadata.superman": "clarkkent" } } }, @@ -548,7 +549,8 @@ const expectedListOutput = ` "status_superserver": ["10.120.0.226"], "database": ["10.0.0.8"], "scw_test": ["10.0.0.11"], - "tfinventory_rocks": ["10.0.0.19"] + "tfinventory_rocks": ["10.0.0.19"], + "superman_clarkkent": ["10.0.0.19"] } ` @@ -694,6 +696,9 @@ olddatacenter="\u003c0.7_format" [status_superserver] 10.120.0.226 +[superman_clarkkent] +10.0.0.19 + [ten] 10.0.0.10 diff --git a/resource.go b/resource.go index 55d66bf..d9bdc76 100644 --- a/resource.go +++ b/resource.go @@ -124,6 +124,10 @@ func (r Resource) Tags() map[string]string { kk := strings.ToLower(parts[1]) vv := strings.ToLower(v) t[kk] = vv + } else if len(parts) == 2 && parts[0] == "metadata" && parts[1] != "#" && parts[1] != "%" { + kk := strings.ToLower(parts[1]) + vv := strings.ToLower(v) + t[kk] = vv } } case "aws_instance", "linode_instance":