Created
February 17, 2023 02:44
-
-
Save akmalharith/a1d890a8c966880886ebeb08be2d7e8b to your computer and use it in GitHub Desktop.
Bitbucket pipelines to run Terraform, with YAML anchors as DRY practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options: | |
docker: true | |
definitions: | |
commonItems: | |
- &getOidcToken export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token && echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token | |
- &terraformInit set -x && terraform -chdir=$TF_WORKDIR init | |
-backend-config="bucket=$TFSTATE_BUCKET" | |
-backend-config="key=$TFSTATE_KEY" | |
-backend-config="region=$TFSTATE_REGION" && | |
set +x | |
- &terraformValidate terraform -chdir=$TF_WORKDIR validate | |
- &terraformPlan set -x && | |
terraform -chdir=$TF_WORKDIR plan | |
-compact-warnings && | |
set +x | |
- &terraformApplyAutoApprove set -x && | |
terraform -chdir=$TF_WORKDIR apply -auto-approve | |
-compact-warnings && | |
set +x | |
- &terraformDestroyAutoApprove set -x && | |
terraform -chdir=$TF_WORKDIR destroy -auto-approve | |
-compact-warnings && | |
set +x | |
image: hashicorp/terraform:1.3.7 | |
pipelines: | |
branches: | |
'develop': | |
- step: | |
oidc: true | |
script: | |
- *getOidcToken | |
- *terraformInit | |
- *terraformValidate | |
- *terraformPlan | |
# - *terraformApplyAutoApprove | |
custom: | |
destroy: | |
- step: | |
oidc: true | |
script: | |
- *getOidcToken | |
- *terraformInit | |
- step: | |
oidc: true | |
script: | |
- *getOidcToken | |
- *terraformInit | |
- *terraformDestroyAutoApprove | |
trigger: manual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment