Skip to content

Example of how to use workspaces in Terraform to support multiple environments

Notifications You must be signed in to change notification settings

rbjoergensen/tf-workspaces

Repository files navigation

Terraform workspace example

First create the workspaces that we need, they were formerly known as environments but was changed since people found it too confusing.

terraform workspace new development
terraform workspace new production

We can then select a workspace and initialise and apply our configuration based on the tfvars for each environment. First we setup the development environment.

terraform workspace select development
terraform plan --var-file=development.tfvars
terraform apply --var-file=development.tfvars

And then we create the production environment.

terraform workspace select production
terraform plan --var-file=production.tfvars
terraform apply --var-file=production.tfvars

If we go to the S3 bucket containing our remote state files we can see that a new folder structured has been created. It will contain a folder for each environment with a subfolder for each terraform project and its state file.

  • env:/
    • development/
      • terraform-workspace-example/
        • terraform.state
    • production/
      • terraform-workspace-example/
        • terraform.state

Screenshot

About

Example of how to use workspaces in Terraform to support multiple environments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages