2022-07-16 23:28:13 +05:30
|
|
|
# Terraform/Base
|
2021-10-27 15:23:28 +05:30
|
|
|
#
|
|
|
|
# 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
|
2022-07-23 23:45:48 +05:30
|
|
|
# create hidden jobs. See: https://docs.gitlab.com/ee/ci/jobs/#hide-jobs
|
2021-10-27 15:23:28 +05:30
|
|
|
#
|
|
|
|
# There is a more opinionated template which we suggest the users to abide,
|
2022-07-16 23:28:13 +05:30
|
|
|
# which is the lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
|
2021-10-27 15:23:28 +05:30
|
|
|
image:
|
2022-10-11 01:57:18 +05:30
|
|
|
name: "$CI_TEMPLATE_REGISTRY_HOST/gitlab-org/terraform-images/releases/1.1:v0.43.0"
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
variables:
|
|
|
|
TF_ROOT: ${CI_PROJECT_DIR} # The relative path to the root directory of the Terraform project
|
2023-01-13 00:05:48 +05:30
|
|
|
TF_STATE_NAME: default # The name of the state file used by the GitLab Managed Terraform state backend
|
2021-10-27 15:23:28 +05:30
|
|
|
|
|
|
|
cache:
|
|
|
|
key: "${TF_ROOT}"
|
|
|
|
paths:
|
|
|
|
- ${TF_ROOT}/.terraform/
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
.terraform:fmt: &terraform_fmt
|
|
|
|
stage: validate
|
2021-10-27 15:23:28 +05:30
|
|
|
script:
|
2022-05-07 20:08:51 +05:30
|
|
|
- cd "${TF_ROOT}"
|
2022-07-16 23:28:13 +05:30
|
|
|
- gitlab-terraform fmt
|
|
|
|
allow_failure: true
|
2021-10-27 15:23:28 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
.terraform:validate: &terraform_validate
|
2021-10-27 15:23:28 +05:30
|
|
|
stage: validate
|
|
|
|
script:
|
2022-05-07 20:08:51 +05:30
|
|
|
- cd "${TF_ROOT}"
|
2021-10-27 15:23:28 +05:30
|
|
|
- gitlab-terraform validate
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
.terraform:build: &terraform_build
|
2021-10-27 15:23:28 +05:30
|
|
|
stage: build
|
|
|
|
script:
|
2022-05-07 20:08:51 +05:30
|
|
|
- cd "${TF_ROOT}"
|
2021-10-27 15:23:28 +05:30
|
|
|
- gitlab-terraform plan
|
|
|
|
- gitlab-terraform plan-json
|
2022-07-16 23:28:13 +05:30
|
|
|
resource_group: ${TF_STATE_NAME}
|
2021-10-27 15:23:28 +05:30
|
|
|
artifacts:
|
|
|
|
paths:
|
|
|
|
- ${TF_ROOT}/plan.cache
|
|
|
|
reports:
|
|
|
|
terraform: ${TF_ROOT}/plan.json
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
.terraform:deploy: &terraform_deploy
|
2021-10-27 15:23:28 +05:30
|
|
|
stage: deploy
|
|
|
|
script:
|
2022-05-07 20:08:51 +05:30
|
|
|
- cd "${TF_ROOT}"
|
2021-10-27 15:23:28 +05:30
|
|
|
- gitlab-terraform apply
|
2022-07-16 23:28:13 +05:30
|
|
|
resource_group: ${TF_STATE_NAME}
|
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
|
|
when: manual
|
2021-10-27 15:23:28 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
.terraform:destroy: &terraform_destroy
|
2021-10-27 15:23:28 +05:30
|
|
|
stage: cleanup
|
|
|
|
script:
|
2022-05-07 20:08:51 +05:30
|
|
|
- cd "${TF_ROOT}"
|
2021-10-27 15:23:28 +05:30
|
|
|
- gitlab-terraform destroy
|
2022-07-16 23:28:13 +05:30
|
|
|
resource_group: ${TF_STATE_NAME}
|
2021-10-27 15:23:28 +05:30
|
|
|
when: manual
|