-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path.gitlab-ci.yml
89 lines (80 loc) · 2.13 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
image:
name: hashicorp/terraform:light
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
services:
- name: docker:dind
variables:
TF_ROOT: ${CI_PROJECT_DIR}/infra_ci_test # 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
CI_CWM_CLIENTID: $CI_CWM_CLIENTID
CI_CWM_SECRET: $CI_CWM_SECRET
CI_CWM_TEST_PASSWORD: $CI_CWM_TEST_PASSWORD
DOCKER_DRIVER: overlay2
before_script:
- cd ${TF_ROOT}
- terraform init
- apk add gettext
- envsubst < terraform.tfvars.tmpl > terraform.tfvars
stages:
- validate
- build
- deploy
- cleanup
cache:
key: "${TF_ROOT}"
paths:
- ${TF_ROOT}/.terraform/
fmt:
stage: validate
script:
- terraform fmt -check -recursive
allow_failure: true
validate:
stage: validate
script:
- terraform validate
build:
stage: build
script:
- terraform plan --out plan
# resource_group: ${TF_STATE_NAME}
dependencies:
- validate
artifacts:
paths:
- ${TF_ROOT}/plan
reports:
terraform: ${TF_ROOT}/plan
deploy:
stage: deploy
script:
- terraform apply --auto-approve -parallelism=50 plan
# resource_group: ${TF_STATE_NAME}
dependencies:
- build
artifacts:
paths:
- ${TF_ROOT}/terraform.tfstate
reports:
terraform: ${TF_ROOT}/terraform.tfstate
allow_failure: true
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
destroy:
stage: cleanup
script:
- terraform destroy --auto-approve
# resource_group: ${TF_STATE_NAME}
dependencies:
- deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual