-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
96 lines (86 loc) · 1.92 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
90
91
92
93
94
95
96
variables:
TF_USERNAME: $GITLAB_USER_LOGIN
TF_PASSWORD: $GITLAB_ACCESS_TOKEN
TF_STATE_NAME: default
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}
TF_ROOT: ${CI_PROJECT_DIR}/environments/${TF_STATE_NAME}
default:
image:
name: "$CI_TEMPLATE_REGISTRY_HOST/gitlab-org/terraform-images/releases/1.5:v1.8.0"
cache:
key: "${TF_STATE_NAME}"
paths:
- .terraform
stages:
- init
- validate
- plan
- deploy
- cleanup
init:
stage: init
before_script:
- terraform --version
- echo ${TF_USERNAME}
- echo ${TF_PASSWORD}
- echo ${TF_STATE_NAME}
- echo ${TF_ADDRESS}
- echo ${TF_ROOT}
script:
- |
terraform init -reconfigure \
-backend-config="address=${TF_ADDRESS}" \
-backend-config="lock_address=${TF_ADDRESS}/lock" \
-backend-config="unlock_address=${TF_ADDRESS}/lock" \
-backend-config="username=${TF_USERNAME}" \
-backend-config="password=${TF_PASSWORD}" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5"
when: manual
fmt:
stage: validate
allow_failure: true
script:
- ls -la
- terraform fmt -check
validate:
stage: validate
allow_failure: true
script:
- terraform validate
plan:
stage: plan
script:
- terraform plan -out plan.cache
- terraform show -json plan.cache
artifacts:
name: plan
paths:
- plan.cache
deploy:
stage: deploy
script:
- terraform apply -auto-approve plan.cache
dependencies:
- plan
environment:
name: $TF_STATE_NAME
when: manual
report:
stage: cleanup
script:
- terraform output > output.txt
environment:
name: $TF_STATE_NAME
when: manual
artifacts:
paths:
- output.txt
cleanup:
stage: cleanup
script:
- terraform destroy -auto-approve
environment:
name: $TF_STATE_NAME
when: manual