Created
July 9, 2025 12:33
-
-
Save GuyBarros/ff5bf788c9acd92c2c2e37ee86d8c21d to your computer and use it in GitHub Desktop.
RUM Count for tfstate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Usage: Pass in a Terraform State file through a pipe | |
# e.g. | |
# cat terraform.tfstate | count.sh | |
# For each resource in the TF State file... | |
# we only count managed resources (i.e. not data sources) | |
# we explicitly ignore null resources (terraform_data and null_resource) | |
# we count all instances of a resource (for those resources defined with count or for_each) | |
# then flatten the whole thing into a list and count the number of items | |
jq '[ | |
.resources[] | | |
select(.mode == "managed") | | |
select(.type == "terraform_data" or .type == "null_resource" | not) | | |
.instances | | |
flatten[] | |
] | length' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment