Open hakuno opened 2 months ago
+1. Each workspace represents separate env and we need to use separate set of Creds(scoped) for various TF providres. Like mongo atlas, auth0 and etc. I want to use some identification of workspace within pre-hook which will set proper env variables.
Pre-workflow hooks run before Terraform is initialised, so no workspace setting is available.
Wouldn't customizing the workflows solve this problem? Example:
version: 3
projects:
- name: dev
dir: .
workflow: dev
workspace: dev
apply_requirements: [mergeable, approved]
- name: prod
dir: .
workflow: prod
workspace: prod
apply_requirements: [mergeable, approved]
workflows:
dev:
plan:
steps:
- init:
extra_args:
- "-upgrade"
- plan:
extra_args:
- "-var"
- "aws_role_arn='arn:aws:iam::<DEV-ACCOUNT-ID>:role/TerraformDeployer'"
- "-var"
- "env=dev"
prod:
plan:
steps:
- init:
extra_args:
- "-upgrade"
- plan:
extra_args:
- "-var"
- "aws_role_arn='arn:aws:iam::<PROD-ACCOUNT-ID>:role/TerraformDeployer'"
- "-var"
- "env=prod"
@IuryAlves
so no workspace setting is available
Actually it has. Remember it inherits that from projects block (in Yaml manifest) like you've already shown:
projects:
- name: dev
dir: .
workflow: dev
workspace: dev
We just need to retrieve the workspace: dev
back.
The pre-workflow-hooks are defined at the repo level though, not at project level.
What if you create a custom workflow and add a run step:
version: 3
projects:
- name: dev
dir: .
workflow: dev
workspace: dev
apply_requirements: [mergeable, approved]
workflows:
dev:
plan:
steps:
- init:
extra_args:
- "-upgrade"
- run: echo $WORKSPACE # do something with workspace
- plan:
extra_args:
- "-var"
- "aws_role_arn='arn:aws:iam::<DEV-ACCOUNT-ID>:role/TerraformDeployer'"
- "-var"
- "env=dev"
@hakuno
Or maybe I misunderstood your use-case. Can you clarify it?
What do you mean by filter some commands (plan, apply etc) by workspace
?
Community Note
Describe the user story
As a Solutions Architect, I'd like to filter some commands (plan, apply etc) by workspace, but the docs say it doesn't have the WORKSPACE environment variable right there. Is it true?
Describe the solution you'd like
I'd like the WORKSPACE environment variable to be available in Pre Workflow Hooks.