Skip to content
Calcrivo

Terraform State Size Calculator

Estimate the size of a Terraform state file from managed resource count, average attributes per resource, and module count.

Inputs

resources

Total number of resources tracked in state.

attributes

Average number of tracked attributes per resource (including nested blocks).

bytes

Average serialized JSON bytes per attribute (key, value, and metadata).

modules

Number of module instances in the configuration.

bytes

Fixed JSON overhead (module path, metadata, dependency lock info) per module instance.

Estimated State Size

349.1KB

Estimated State Size

0.341MB

Resource Data Size

350,000bytes

Module Overhead

7,500bytes

Avg Bytes per Resource

1,430bytes

Step by step

  1. Resource bytes: resources × attrs × bytes/attr

    250 × 40 × 35

    = 350,000 bytes

  2. Module overhead bytes

    15 × 500

    = 7,500 bytes

  3. Total state size

    350,000 + 7,500

    = 349.1 KB

How it works

Terraform serializes all managed resource attributes plus module metadata into a single JSON state file: size ≈ resources × avg_attributes × bytes_per_attribute + modules × module_overhead. As infrastructure grows, state file size grows roughly linearly with resource count, which directly impacts `terraform plan`/`apply` performance and remote backend costs.

Formula

stateSize = (resources × avgAttributes × bytesPerAttribute) + (modules × moduleOverhead)

R
Number of managed resources
A
Average attributes per resource
B
Bytes per attribute
M
Number of module instances
O_m
Overhead bytes per module
S
Total state file size in bytes

Frequently Asked Questions

Why does state file size matter?

Larger state files take longer to read, lock, and refresh on every plan/apply, and some remote backends charge per-request or per-GB, so state growth directly affects both performance and cost.

How can I reduce Terraform state size?

Split large monoliths into smaller state files per service/environment using workspaces or separate root modules, and use `terraform state rm` to remove resources that no longer need tracking.

Does resource count grow linearly with state size?

Approximately yes, assuming similar resource types. Resources with large embedded data (e.g. IAM policy JSON, big user_data scripts) will skew the average attribute size higher than typical resources.

What's a reasonable bytes-per-attribute estimate?

20-50 bytes is typical for simple string/number attributes; complex nested blocks (e.g. security group rules, IAM policies) can push individual resources well above the average.

You might also need