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

Support default tags for the AWS Terraform provider. (#156)

In recent versions of the AWS Terraform provider, it is possible to attach default tags to every resource. Those tags aren't stored in the `tags` field in the Terraform state but as a special field `tags_all`. Accept tags for AWS resources from both fields to also export tags defined as default tags.
This commit is contained in:
Sören Bohn 2021-07-30 23:09:38 +02:00 committed by GitHub
parent 693e714ab7
commit a4d1a11de8
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

@ -966,6 +966,9 @@ const exampleStateFileTerraform0dot12 = `
"tags": {
"Name": "one-aws-instance"
},
"tags_all": {
"Additional": "another-tag"
},
"volume_tags": {
"Ignored": "stuff"
}
@ -1291,6 +1294,8 @@ const expectedListOutputTerraform0dot12 = `
"name_two-aws-instance": ["10.0.0.2"],
"name_three-aws-instance": ["10.0.0.3", "10.0.1.3"],
"additional_another-tag": ["35.159.25.34"],
"foo_bar": ["12.34.56.78"],
"type_vsphere_virtual_machine": ["12.34.56.78"],
"vm_0": ["12.34.56.78"],
@ -1298,7 +1303,10 @@ const expectedListOutputTerraform0dot12 = `
}
`
const expectedInventoryOutputTerraform0dot12 = `[all]
const expectedInventoryOutputTerraform0dot12 = `[additional_another-tag]
35.159.25.34
[all]
10.0.0.2
10.0.0.3
10.0.0.4
@ -1389,6 +1397,8 @@ const expectedHostOneOutputTerraform0dot12 = `
"public_ip": "35.159.25.34",
"tags.#": "1",
"tags.Name": "one-aws-instance",
"tags_all.#": "1",
"tags_all.Additional": "another-tag",
"volume_tags.#":"1",
"volume_tags.Ignored":"stuff"
}

@ -33,7 +33,10 @@
"private_ip": "10.0.0.1",
"public_ip": "35.159.25.34",
"tags": {
"Name": "one-aws-instance"
"Name": "one-aws-instance",
},
"tags_all": {
"Additional": "another-tag"
},
"volume_tags": {
"Ignored": "stuff"

@ -150,7 +150,7 @@ func (r Resource) Tags() map[string]string {
// At some point Terraform changed the key for counts of attributes to end with ".%"
// instead of ".#". Both need to be considered as Terraform still supports state
// files using the old format.
if len(parts) == 2 && parts[0] == "tags" && parts[1] != "#" && parts[1] != "%" {
if len(parts) == 2 && (parts[0] == "tags" || parts[0] == "tags_all") && parts[1] != "#" && parts[1] != "%" {
kk := strings.ToLower(parts[1])
vv := strings.ToLower(v)
t[kk] = vv
@ -162,7 +162,7 @@ func (r Resource) Tags() map[string]string {
// At some point Terraform changed the key for counts of attributes to end with ".%"
// instead of ".#". Both need to be considered as Terraform still supports state
// files using the old format.
if len(parts) == 2 && parts[0] == "tags" && parts[1] != "#" && parts[1] != "%" {
if len(parts) == 2 && (parts[0] == "tags" || parts[0] == "tags_all") && parts[1] != "#" && parts[1] != "%" {
kk := strings.ToLower(parts[1])
vv := strings.ToLower(v)
t[kk] = vv