2021-01-03 14:25:43 +05:30
|
|
|
# Terraform/Base.latest
|
|
|
|
#
|
|
|
|
# The purpose of this template is to provide flexibility to the user so
|
|
|
|
# they are able to only include the jobs that they find interesting.
|
|
|
|
#
|
|
|
|
# Therefore, this template is not supposed to run any jobs. The idea is to only
|
|
|
|
# create hidden jobs. See: https://docs.gitlab.com/ee/ci/yaml/#hide-jobs
|
|
|
|
#
|
|
|
|
# There is a more opinionated template which we suggest the users to abide,
|
|
|
|
# which is the lib/gitlab/ci/templates/Terraform.latest.gitlab-ci.yml
|
|
|
|
|
|
|
|
image:
|
|
|
|
name: registry.gitlab.com/gitlab-org/terraform-images/stable:latest
|
|
|
|
|
|
|
|
variables:
|
2021-10-27 15:23:28 +05:30
|
|
|
TF_ROOT: ${CI_PROJECT_DIR} # The relative path to the root directory of the Terraform project
|
|
|
|
TF_STATE_NAME: ${TF_STATE_NAME:-default} # The name of the state file used by the GitLab Managed Terraform state backend
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
cache:
|
|
|
|
key: "${TF_ROOT}"
|
|
|
|
paths:
|
|
|
|
- ${TF_ROOT}/.terraform/
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
.terraform:init: &terraform_init
|
2021-01-03 14:25:43 +05:30
|
|
|
stage: init
|
|
|
|
script:
|
2021-01-29 00:20:46 +05:30
|
|
|
- cd ${TF_ROOT}
|
2021-01-03 14:25:43 +05:30
|
|
|
- gitlab-terraform init
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
.terraform:fmt: &terraform_fmt
|
|
|
|
stage: validate
|
|
|
|
needs: []
|
|
|
|
script:
|
|
|
|
- cd ${TF_ROOT}
|
|
|
|
- gitlab-terraform fmt -check -recursive
|
|
|
|
allow_failure: true
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
.terraform:validate: &terraform_validate
|
2021-01-03 14:25:43 +05:30
|
|
|
stage: validate
|
|
|
|
script:
|
2021-01-29 00:20:46 +05:30
|
|
|
- cd ${TF_ROOT}
|
2021-01-03 14:25:43 +05:30
|
|
|
- gitlab-terraform validate
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
.terraform:build: &terraform_build
|
2021-01-03 14:25:43 +05:30
|
|
|
stage: build
|
|
|
|
script:
|
2021-01-29 00:20:46 +05:30
|
|
|
- cd ${TF_ROOT}
|
2021-01-03 14:25:43 +05:30
|
|
|
- gitlab-terraform plan
|
|
|
|
- gitlab-terraform plan-json
|
2021-10-27 15:23:28 +05:30
|
|
|
resource_group: ${TF_STATE_NAME}
|
2021-01-03 14:25:43 +05:30
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- ${TF_ROOT}/plan.cache
|
|
|
|
reports:
|
|
|
|
terraform: ${TF_ROOT}/plan.json
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
.terraform:deploy: &terraform_deploy
|
2021-01-03 14:25:43 +05:30
|
|
|
stage: deploy
|
|
|
|
script:
|
2021-01-29 00:20:46 +05:30
|
|
|
- cd ${TF_ROOT}
|
2021-01-03 14:25:43 +05:30
|
|
|
- gitlab-terraform apply
|
2021-10-27 15:23:28 +05:30
|
|
|
resource_group: ${TF_STATE_NAME}
|
2021-01-03 14:25:43 +05:30
|
|
|
when: manual
|
|
|
|
only:
|
2021-04-17 20:07:23 +05:30
|
|
|
variables:
|
|
|
|
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
.terraform:destroy: &terraform_destroy
|
2021-01-29 00:20:46 +05:30
|
|
|
stage: cleanup
|
|
|
|
script:
|
2021-02-22 17:27:13 +05:30
|
|
|
- cd ${TF_ROOT}
|
2021-01-29 00:20:46 +05:30
|
|
|
- gitlab-terraform destroy
|
2021-10-27 15:23:28 +05:30
|
|
|
resource_group: ${TF_STATE_NAME}
|
2021-01-29 00:20:46 +05:30
|
|
|
when: manual
|