Reputation: 1
Is there a way with Bitbucket Pipeline condition to cd into specific folder and execute commands? My idea is to have folder with Terraform project and environment (develop, staging and prod). Here is what I have as bitbucket repository structure:
myproject:
- /infra/prod/main.tf
- /infra/staging/main.tf
- /infra/develop/main.tf
My step:
- step:
name: Terraform initialization and plan
image: hashicorp/terraform
script:
- cd myproject # cd to the specific environment folder
- terraform init
- terraform plan -var-file="my-variables.tfvars"
condition:
changesets:
includePaths:
- "myproject/**" # Running the step this way only check for changes in the root folder of myproject/
Regards, Ivo
Upvotes: -1
Views: 345
Reputation: 1
It seems the solution was simple but for some reason VS code didn't update my Bitbucket repository folder names for the environment. The code below helped me to achieve what I want with parameters for each environment
image: docker:stable
pipelines:
custom:
Terraform:
- variables:
- name: ENVIRONMENT
default: dev
allowed-values:
- dev
- staging
- prod
- name: ACTION
default: "apply"
allowed-values:
- apply
- step:
name: Terraform initialization and plan
image: hashicorp/terraform
script:
- cd infra/$ENVIRONMENT
- terraform init
- terraform plan -var-file="my-variables.tfvars"
condition:
changesets:
includePaths:
- "infra/dev/**"
- "infra/staging/**"
- "infra/prod/**"
Upvotes: 0