Skip to content

Instantly share code, notes, and snippets.

@GuyBarros
Created July 9, 2025 12:33
Show Gist options
  • Save GuyBarros/ff5bf788c9acd92c2c2e37ee86d8c21d to your computer and use it in GitHub Desktop.
Save GuyBarros/ff5bf788c9acd92c2c2e37ee86d8c21d to your computer and use it in GitHub Desktop.
RUM Count for tfstate
#!/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