Last active
February 7, 2022 19:15
-
-
Save rdemoraes/2862982de29669c575f9a1d53561550b to your computer and use it in GitHub Desktop.
Terraform.gitlab-ci.yml
This file contains hidden or 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
| --- | |
| include: | |
| - local: /jobs/terraform-prepare.yml | |
| image: 111111111111.dkr.ecr.us-east-1.amazonaws.com/devops/iac/terraform:${IMAGE_TAG} | |
| variables: | |
| TF_ROOT: ${CI_PROJECT_DIR}/${TF_ENV_PATH} # The relative path to the root directory of the Terraform project | |
| PLAN: plan.cache | |
| PLAN_JSON: plan.json | |
| before_script: | |
| - cd ${TF_ROOT} | |
| stages: | |
| - prepare | |
| - init | |
| - validate | |
| - plan | |
| - apply | |
| init: | |
| stage: init | |
| tags: [devops] | |
| extends: .prepare | |
| script: | |
| - terraform init | |
| artifacts: | |
| paths: | |
| - .terraform/ | |
| fmt: | |
| stage: validate | |
| tags: [devops] | |
| needs: | |
| - job: init | |
| dependencies: | |
| - init | |
| script: | |
| - terraform fmt -check -recursive | |
| allow_failure: false | |
| validate: | |
| stage: validate | |
| tags: [devops] | |
| needs: | |
| - job: init | |
| dependencies: | |
| - init | |
| extends: .prepare | |
| script: | |
| - terraform validate | |
| allow_failure: false | |
| plan: | |
| stage: plan | |
| tags: [devops] | |
| needs: | |
| - job: init | |
| - job: validate | |
| - job: fmt | |
| dependencies: | |
| - init | |
| extends: .prepare | |
| script: | |
| - terraform plan -var-file="$TF_ROOT/terraform.tfvars" -out "terraform.tfplan" | |
| - terraform show --json "terraform.tfplan" | convert_report > $PLAN_JSON | |
| artifacts: | |
| name: plan | |
| paths: | |
| - terraform.tfplan | |
| reports: | |
| terraform: $PLAN_JSON | |
| allow_failure: false | |
| apply: | |
| stage: apply | |
| tags: [devops] | |
| needs: | |
| - job: init | |
| - job: plan | |
| dependencies: | |
| - init | |
| - plan | |
| extends: .prepare | |
| script: | |
| - | | |
| terraform apply \ | |
| -auto-approve \ | |
| -var-file="terraform.tfvars" \ | |
| -input=false "terraform.tfplan" | |
| when: manual | |
| only: | |
| - main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment