-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
82 lines (75 loc) · 2.29 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
default:
image:
name: registry.gitlab.com/graph-node/images/deployer:latest
entrypoint:
- "/usr/bin/env"
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
stages:
- validate
- build
- deploy
.terragrunt_default:
variables:
PLAN: plan.tfplan
JSON_PLAN_FILE: tfplan.json
TF_ROOT: .
TG_ENVIRONMENT: dev
TF_WORKSPACE: default
cache:
key: ${TF_ROOT}-${TG_ENVIRONMENT}-${CI_JOB_NAME}
paths:
- "*/**/.terragrunt-cache"
- "*/**/.terraform.lock.hcl"
before_script:
- cd $TF_ROOT/$TG_ENVIRONMENT/$TG_MODULE
- terraform --version
- terragrunt --version
- export TFVARS=$(eval echo \$tfvars_${LOCATION}_$TF_WORKSPACE)
- test $TFVARS && test -f $TFVARS && mv $TFVARS terraform.tfvars
.plan:
extends: .terragrunt_default
stage: build
script:
- terragrunt $(if [ $TG_RUN_ALL ]; then echo "run-all"; fi) plan -out=$PLAN
artifacts:
paths:
- "*/$PLAN"
rules:
- if: '$CI_PIPELINE_SOURCE != "pipeline" && $PARENT_PIPELINE_SOURCE != "pipeline"'
.apply:
extends: .terragrunt_default
stage: deploy
script:
- CONTAINS_PLAN=$(find . -name $PLAN)
- echo "terragrunt $(if [ $TG_RUN_ALL ]; then echo "run-all"; fi) apply -input=false $(if [ $CONTAINS_PLAN ]; then echo $PLAN; else echo "--auto-approve"; fi)"
- terragrunt $(if [ $TG_RUN_ALL ]; then echo "run-all"; fi) apply -input=false $(if [ $CONTAINS_PLAN ]; then echo $PLAN; else echo "--auto-approve"; fi)
rules:
- if: '$CI_COMMIT_REF_PROTECTED != "true"'
when: never
- if: '$CI_PIPELINE_SOURCE != "pipeline" && $PARENT_PIPELINE_SOURCE != "pipeline"'
when: manual
allow_failure: true
frontend:deployment:
stage: deploy
extends: .apply
variables:
TG_MODULE: frontend
rules:
- !reference [.apply, rules]
- if: '$TRIGGER_JOB == $CI_JOB_NAME && $CI_PIPELINE_SOURCE == "pipeline"'
backend:migration:
stage: deploy
extends: .apply
variables:
TG_MODULE: migration
rules:
- !reference [.apply, rules]
- if: '$TRIGGER_JOB == $CI_JOB_NAME && $CI_PIPELINE_SOURCE == "pipeline"'
backend:deployment:
stage: deploy
extends: .apply
variables:
TG_MODULE: deployment
rules:
- !reference [.apply, rules]
- if: '$TRIGGER_JOB == $CI_JOB_NAME && $CI_PIPELINE_SOURCE == "pipeline"'