Terraform0.12

nicolaw 4th December 2020 at 9:41am
AWS jq JSON json TechnicalNotes Terraform

List ARNs of Managed Resources

$ terraform show -json | jq -r '.values.root_module|..|select(.address? != null and .mode? == "managed" and .values.arn? != null)|.values.arn' | head -3
arn:aws:dynamodb:us-east-1:0123456789:table/nicolawdl-table1
arn:aws:s3:::acme-nicolawdl-bucket1
arn:aws:s3:::acme-nicolawdl-bucket2

List ARNs of Data Lookups

$ terraform show -json | jq -r '.values.root_module|..|select(.address? != null and .mode? == "data" and .values.arn? != null)|.values.arn' | head -3
arn:aws:iam::0123456789:user/Nicola.Worthington
arn:aws:ec2:us-east-1:0123456789:subnet/subnet-0abcdef1238db99b9
arn:aws:ec2:us-east-1:0123456789:subnet/subnet-0abcdef123c0effe1

List All ARNs (Unfiltered Union)

$ terraform show -json | jq -r '.values.root_module|..|select(.address? != null and .values.arn? != null)|.values.arn' | head -6
arn:aws:dynamodb:us-east-1:0123456789:table/nicolawdl-table1
arn:aws:s3:::acme-nicolawdl-bucket1
arn:aws:s3:::acme-nicolawdl-bucket2arn:aws:iam::0123456789:user/Nicola.Worthington
arn:aws:ec2:us-east-1:0123456789:subnet/subnet-0abcdef1238db99b9
arn:aws:ec2:us-east-1:0123456789:subnet/subnet-0abcdef123c0effe1

Miscellaneous

https://www.terraform.io/docs/configuration/meta-arguments/module-providers.html