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
|
{
"image": {
"name": "registry.gitlab.com/gitlab-org/gitlab-build-images:terraform",
"entrypoint": [
"/usr/bin/env",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
]
},
"variables": {
"PLAN": "plan.tfplan",
"JSON_PLAN_FILE": "tfplan.json"
},
"cache": {
"paths": [".terraform"]
},
"before_script": [
"alias convert_report=\"jq -r '([.resource_changes[]?.change.actions?]|flatten)|{\"create\":(map(select(.==\"create\"))|length),\"update\":(map(select(.==\"update\"))|length),\"delete\":(map(select(.==\"delete\"))|length)}'\"",
"terraform --version",
"terraform init"
],
"stages": ["validate", "build", "test", "deploy"],
"validate": {
"stage": "validate",
"script": ["terraform validate"]
},
"plan": {
"stage": "build",
"script": [
"terraform plan -out=$PLAN",
"terraform show --json $PLAN | convert_report > $JSON_PLAN_FILE"
],
"artifacts": {
"name": "plan",
"paths": ["$PLAN"],
"reports": {
"terraform": "$JSON_PLAN_FILE"
}
}
},
"apply": {
"stage": "deploy",
"environment": {
"name": "production"
},
"script": ["terraform apply -input=false $PLAN"],
"dependencies": ["plan"],
"when": "manual",
"only": ["master"]
}
}
|