Skip to content

Allow per-stack state file name via TF_STATE_FILE_NAME#3

Open
gsavage wants to merge 1 commit intomainfrom
handle-different-statefile-names
Open

Allow per-stack state file name via TF_STATE_FILE_NAME#3
gsavage wants to merge 1 commit intomainfrom
handle-different-statefile-names

Conversation

@gsavage
Copy link
Copy Markdown
Contributor

@gsavage gsavage commented Apr 29, 2026

When a single repo contains multiple Terraform stacks (e.g. the sub-stacks under terraform-server), each stack needs its own state file under the same S3 backend bucket. The original fivexl tf.sh supports this through a TF_STATE_FILE_NAME env var (defaulting to main.tfstate), sourced from a per-stack tf.sh.env file. Our Python rewrite hardcoded main.tfstate, which would have caused every stack in the same repo to collide on one state file.

Plumb a state_file_name argument through TfBackend and resolve it from TF_STATE_FILE_NAME (default main.tfstate) when building the backend. The variable can be set in the shell or in tf.env, which tf already loads on startup.

When a single repo contains multiple Terraform stacks (e.g. the
sub-stacks under terraform-server), each stack needs its own state file
under the same S3 backend bucket. The original fivexl tf.sh supports
this through a TF_STATE_FILE_NAME env var (defaulting to main.tfstate),
sourced from a per-stack tf.sh.env file. Our Python rewrite hardcoded
main.tfstate, which would have caused every stack in the same repo to
collide on one state file.

Plumb a state_file_name argument through TfBackend and resolve it from
TF_STATE_FILE_NAME (default main.tfstate) when building the backend.
The variable can be set in the shell or in tf.env, which tf already
loads on startup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gsavage gsavage enabled auto-merge April 29, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant