Estimate Terraform state file size based on managed resource count and attributes.
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.
stateSize = (resources × avgAttributes × bytesPerAttribute) + (modules × moduleOverhead)
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.
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.
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.
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.