-
Notifications
You must be signed in to change notification settings - Fork 10
/
.gitlab-ci.yml
91 lines (83 loc) · 2.4 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
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
image:
name: gcr.io/cloud-foundation-cicd/cft/developer-tools-light:1
variables:
REPO_FOLDER: "web_app_protection_example"
STATE_BUCKET_NAME: "$STATE_BUCKET_NAME"
TF_SA_EMAIL: "$TF_SA_EMAIL"
before_script:
- |
echo "Setting up gcloud for impersonation"
gcloud config set auth/impersonate_service_account "$TF_SA_EMAIL"
echo "Adding bucket information to backends"
for i in `find -name 'backend.tf'`; do sed -r -i "s/_BUCKET_GCS_/"$STATE_BUCKET_NAME"/" $i; done
for i in `find -name 'pipeline-functions.sh'`;do chmod +x $i; done
cd examples/"$REPO_FOLDER" ; cp -Prf ../../modules .
for i in `find environments/ -mindepth 1 -maxdepth 1 -type d` ; do cp -Prf *.tf ./scripts/ $i ; done
stages:
- tf_init
- tf_plan_all
- tf_plan
- tf_apply
tf_init:
stage: tf_init
script:
- export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT="$TF_SA_EMAIL"
- build/pipeline-functions.sh init "$CI_COMMIT_BRANCH"
only:
- dev
- prd
- npd
artifacts:
paths:
- $CI_PROJECT_DIR/examples/$REPO_FOLDER/environments
tags:
- gitlab-runner
tf_plan_all:
stage: tf_plan_all
script:
- export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT="$TF_SA_EMAIL"
- build/pipeline-functions.sh plan_validate_all "$CI_COMMIT_BRANCH"
except:
- dev
- prd
- npd
tags:
- gitlab-runner
tf_plan:
stage: tf_plan
script:
- export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT="$TF_SA_EMAIL"
- build/pipeline-functions.sh plan "$CI_COMMIT_BRANCH"
only:
- dev
- prd
- npd
artifacts:
paths:
- $CI_PROJECT_DIR/examples/$REPO_FOLDER/tmp_plan/*.tfplan
tags:
- gitlab-runner
tf_apply:
stage: tf_apply
script:
- export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT="$TF_SA_EMAIL"
- build/pipeline-functions.sh apply "$CI_COMMIT_BRANCH"
only:
- dev
- prd
- npd
tags:
- gitlab-runner