Support for workspaces?
Does astro support checking out a new terraform workspace to run plan?
Astro doesn't have specific support for workspaces. Though, you could possibly run a hook to do it.
What workflow are you looking to support?
Terraform workspaces is essentially equivalent to your use of environment but built into terraform. We use the same terraform files but checkout workspace prod or staging before running terraform apply to provision the respective environments. https://www.terraform.io/docs/state/workspaces.html
We would like to be able to use the built in workspaces instead of a separate environment variable.
Given a config block:
- name: vpc
path: core/vpc
remote:
backend_config:
bucket: acme-terraform-states
key: "{{.aws_region}}/vpc.tfstate"
region: us-east-1
workspaces:
- prod
- staging
Running astro plan --workspace staging would result in:
cd core/vpc -> terraform workspace select staging -> terraform plan
Running astro plan would result in:
cd core/vpc -> terraform workspace select staging -> terraform plan AND
cd core/vpc -> terraform workspace select prod -> terraform plan
OK cool, I see. In that regard, workspaces act a bit like the variables, it's just that they need a special step.
Do you know of any way to switch workspace without running terraform workspace? Is there an env var or something? Do you have to re-init after switching workspace?
AFAIK the only way to switch workspaces is by running terraform workspace select prod, for example.
You only need to run init once and after that you can switch workspaces as often as you would like without having to re-init.
Indeed also think the only way to switch is the workspaces command. At first init only the workspace default exists when creating workspaces the remote states are saved with the prepended with workspace key.
It is possible to switch workspace via the TF_WORKSPACE environment variable, see the HashiCorp guide Using Terraform in automation.