'Cloudbuild - how to set a variable, looping multiples paths (folders)
i am trying to configure a variable in this case _PATH using cloudbuild. I've multiple paths (folders) on my github repo with tf files, and want to the terraform recognize any change that have been made on any folder at the moment to push and trigger.
I was wondering if there is any way to looping values separated by "comma" on trigger options and then use "for" in bash script.., or perhaps exists another better way that i dont really know yet,
Thanks for the help!
Solution 1:[1]
Sadly, I haven't found a way yet to set variables at the cloudbuild.yaml
level.
Note CloudBuild
was originally called Cloud Container Builder
, which is why it acts differently than other CI/CD tools.
I think there may be another way to get the behavior you want though:
- Implement the
bash looping logic
in a script (ie.sh/run_terraform_applys.sh
), and create a Dockerfile for it in your repo:
FROM hashicorp/terraform:1.0.0
WORKDIR /workspace
COPY sh/ /workspace/sh/
COPY requirements.txt /workspace/
RUN pip install -r requirements.txt
RUN . sh/run_terraform_applys.sh
COPY . /workspace/
RUN . sh/other_stuff_to_do.sh
- Use the cloud-builders image to build your image and as a consequence the
docker build
will runsh/run_terraform_applys.sh
within the Docker image (You canpush
your image to GCR to allow for layer-caching):
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |-
# Build Dockerfile
docker build -t ${MY_GCR_CACHE} --cache-from ${MY_GCR_CACHE} -f cicd/Dockerfile .
docker push ${MY_GCR_CACHE}
id: 'Run Terraform Apply'
waitFor: ['-']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |