Skip to content

Commit ada3e86

Browse files
author
Roger Martinez
committed
add cloudbuild yaml
1 parent b7e6287 commit ada3e86

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

cloudbuild.yaml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
steps:
17+
- id: 'branch name'
18+
name: 'alpine'
19+
entrypoint: 'sh'
20+
args:
21+
- '-c'
22+
- |
23+
echo "***********************"
24+
echo "$BRANCH_NAME"
25+
echo "***********************"
26+
27+
- id: 'tf init'
28+
name: 'hashicorp/terraform:1.0.0'
29+
entrypoint: 'sh'
30+
args:
31+
- '-c'
32+
- |
33+
if [ -d "environments/$BRANCH_NAME/" ]; then
34+
cd environments/$BRANCH_NAME
35+
terraform init
36+
else
37+
for dir in environments/*/
38+
do
39+
cd ${dir}
40+
env=${dir%*/}
41+
env=${env#*/}
42+
echo ""
43+
echo "*************** TERRAFORM INIT ******************"
44+
echo "******* At environment: ${env} ********"
45+
echo "*************************************************"
46+
terraform init || exit 1
47+
cd ../../
48+
done
49+
fi
50+
51+
# [START tf-plan]
52+
- id: 'tf plan'
53+
name: 'hashicorp/terraform:1.0.0'
54+
entrypoint: 'sh'
55+
args:
56+
- '-c'
57+
- |
58+
if [ -d "environments/$BRANCH_NAME/" ]; then
59+
cd environments/$BRANCH_NAME
60+
terraform plan
61+
else
62+
for dir in environments/*/
63+
do
64+
cd ${dir}
65+
env=${dir%*/}
66+
env=${env#*/}
67+
echo ""
68+
echo "*************** TERRAFOM PLAN ******************"
69+
echo "******* At environment: ${env} ********"
70+
echo "*************************************************"
71+
terraform plan || exit 1
72+
cd ../../
73+
done
74+
fi
75+
# [END tf-plan]
76+
77+
# [START tf-apply]
78+
- id: 'tf apply'
79+
name: 'hashicorp/terraform:1.0.0'
80+
entrypoint: 'sh'
81+
args:
82+
- '-c'
83+
- |
84+
if [ -d "environments/$BRANCH_NAME/" ]; then
85+
cd environments/$BRANCH_NAME
86+
terraform apply -auto-approve
87+
else
88+
echo "***************************** SKIPPING APPLYING *******************************"
89+
echo "Branch '$BRANCH_NAME' does not represent an oficial environment."
90+
echo "*******************************************************************************"
91+
fi
92+
# [END tf-apply]

0 commit comments

Comments
 (0)