debian-mirror-gitlab/lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml
2021-11-11 11:23:49 +05:30

74 lines
1.9 KiB
YAML

# 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:
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
cache:
key: "${TF_ROOT}"
paths:
- ${TF_ROOT}/.terraform/
.terraform:init: &terraform_init
stage: init
script:
- cd ${TF_ROOT}
- gitlab-terraform init
.terraform:fmt: &terraform_fmt
stage: validate
needs: []
script:
- cd ${TF_ROOT}
- gitlab-terraform fmt -check -recursive
allow_failure: true
.terraform:validate: &terraform_validate
stage: validate
script:
- cd ${TF_ROOT}
- gitlab-terraform validate
.terraform:build: &terraform_build
stage: build
script:
- cd ${TF_ROOT}
- gitlab-terraform plan
- gitlab-terraform plan-json
resource_group: ${TF_STATE_NAME}
artifacts:
paths:
- ${TF_ROOT}/plan.cache
reports:
terraform: ${TF_ROOT}/plan.json
.terraform:deploy: &terraform_deploy
stage: deploy
script:
- cd ${TF_ROOT}
- gitlab-terraform apply
resource_group: ${TF_STATE_NAME}
when: manual
only:
variables:
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
.terraform:destroy: &terraform_destroy
stage: cleanup
script:
- cd ${TF_ROOT}
- gitlab-terraform destroy
resource_group: ${TF_STATE_NAME}
when: manual