Skip to content

Commit ac8f80c

Browse files
feat: add workspace selection (#35)
## what - Update the terraform plan/apply/refresh to select a workspace ## why - This is the pattern we use for clients and have setup in mp-infra <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Enhanced Terraform deployment pipeline by adding automatic workspace initialization. Plan, apply, and refresh operations now automatically verify and create required workspaces for target environments before execution. This streamlines the deployment process and reduces manual setup requirements while preserving existing validation checks. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8c908c2 commit ac8f80c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/terraform/Taskfile.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ tasks:
1616
silent: true
1717
internal: true
1818
vars: &vars
19-
ENV:
19+
WORKSPACE:
2020
sh: echo "{{.CLI_ARGS}}" | cut -d ' ' -f1 | xargs
2121
TF_ARGS:
2222
sh: echo "{{.CLI_ARGS}}" | cut -s -d ' ' -f2- | xargs
2323
BACKEND_CONFIG_FILE:
24-
sh: echo "{{.BACKEND_CONFIG_PATH}}/{{.ENV}}.backend.tf"
24+
sh: echo "{{.BACKEND_CONFIG_PATH}}/{{.WORKSPACE}}.backend.tf"
2525
TFVARS_FILE:
26-
sh: echo "{{.TFVARS_PATH}}/{{.ENV}}.tfvars"
26+
sh: echo "{{.TFVARS_PATH}}/{{.WORKSPACE}}.tfvars"
2727

2828
init:
2929
desc: Initialize Terraform working directory with a backend configuration file.
@@ -56,6 +56,7 @@ tasks:
5656
- sh: test -f {{.TFVARS_FILE}}
5757
msg: "Variables file does not exist: {{.TFVARS_FILE}}"
5858
cmds:
59+
- terraform workspace select -or-create {{.WORKSPACE}}
5960
- terraform plan -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}
6061

6162
apply:
@@ -73,6 +74,7 @@ tasks:
7374
- sh: test -f {{.TFVARS_FILE}}
7475
msg: "Variables file does not exist: {{.TFVARS_FILE}}"
7576
cmds:
77+
- terraform workspace select -or-create {{.WORKSPACE}}
7678
- terraform apply -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}
7779

7880
refresh:
@@ -90,4 +92,5 @@ tasks:
9092
- sh: test -f {{.TFVARS_FILE}}
9193
msg: "Variables file does not exist: {{.TFVARS_FILE}}"
9294
cmds:
95+
- terraform workspace select -or-create {{.WORKSPACE}}
9396
- terraform apply -refresh-only -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}

0 commit comments

Comments
 (0)