Dinamically creating backend's state file and selecting state file during runtime #1590
-
Hey, I want to ask how you guys handle multiple types of environment regarding terraform backend. Im writing a pipeline using github actions that can deploy multiple different dev/uat/prod environments using a given unique name (e.g: dev-my-env1, prod-disaster-recovey, uat-automation-tests). I want to be able to use this dinamic names to name my resources and split vpcs, internet gateways, subnets, ecs task definitions and etc, this would mean that each environment could have its own state. The problem is I can run terraform init passing the backend config on the CLI parameters, but I have not found a way to select which state file to point during the workflow run to run the plan and apply later. What I was expecting was something like this: ` Initialization steps above
` |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
hi @BrenonOrtega, as you showed in your example, you initialize Terraform with environment-specific backend configuration during the terraform init step. Ensure that this configuration is consistent across init, plan, and apply steps for the same environment. This is crucial to avoid inconsistencies and potential state corruption. here’s a refined example that sticks to best practices:
I hope, it'll help to you! 🙌🏻 |
Beta Was this translation helpful? Give feedback.
hi @BrenonOrtega,
as you showed in your example, you initialize Terraform with environment-specific backend configuration during the terraform init step. Ensure that this configuration is consistent across init, plan, and apply steps for the same environment. This is crucial to avoid inconsistencies and potential state corruption.
here’s a refined example that sticks to best practices: