When using Terraform with Git, it's common to associate a Terraform workspace with a specific Git branch. This allows you to manage different environments and configurations for each branch.
Here's a general workflow:
- Create a new Git branch: Create a new branch from the main branch, e.g.,
git branch dev
. - Create a new Terraform workspace: Run
terraform workspace new dev
to create a new workspace named "dev". - Switch to the new Terraform workspace: Run
terraform workspace select dev
to switch to the "dev" workspace. - Make changes and commit to the Git branch: Make changes to your infrastructure configuration files and commit them to the "dev" branch using
git add
andgit commit
.