forked from dora-team/fourkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_tests_terraform.cloudbuild.yaml
121 lines (106 loc) · 4.04 KB
/
e2e_tests_terraform.cloudbuild.yaml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
steps:
# remove any detritus left from prior runs
- id: Clean
name: gcr.io/$PROJECT_ID/fourkeys-builder
entrypoint: /bin/bash
args:
- '-c'
- |
### Purge state using Terraform
# configure remote terraform backend GCS
cat > backend.tf <<EOF
terraform {
backend "gcs" {
bucket = "$_TARGET_PROJECT-tf-state"
prefix = "terraform/state"
}
}
EOF
terraform init
TF_LOG=$_TF_LOG \
TF_VAR_google_project_id='$_TARGET_PROJECT' \
TF_VAR_google_region='us-central1' \
TF_VAR_bigquery_region='US' \
TF_VAR_parsers='["cloud-build","github"]' \
terraform destroy --auto-approve
### Delete Terraform state
gsutil -m rm -r gs://$_TARGET_PROJECT-tf-state/terraform || true
### Use gcloud to ensure all resources are gone
./ci/project_cleaner.sh --project=$_TARGET_PROJECT || true
gcloud services disable compute.googleapis.com --project=$_TARGET_PROJECT --force
gcloud services disable run.googleapis.com --project=$_TARGET_PROJECT --force
gcloud services disable bigquery.googleapis.com --project=$_TARGET_PROJECT --force
gcloud services disable secretmanager.googleapis.com --project=$_TARGET_PROJECT --force
- id: Install
name: 'gcr.io/$PROJECT_ID/fourkeys-builder'
entrypoint: /bin/bash
dir: "setup"
args:
- '-c'
- |
# configure remote terraform backend GCS
cat > backend.tf <<EOF
terraform {
backend "gcs" {
bucket = "$_TARGET_PROJECT-tf-state"
prefix = "terraform/state"
}
}
EOF
terraform init
# invoke install script
GIT_SYSTEM='github' \
CICD_SYSTEM='cloud-build' \
PARENT_PROJECT='$PROJECT_ID' \
FOURKEYS_PROJECT='$_TARGET_PROJECT' \
FOURKEYS_REGION='us-central1' \
BIGQUERY_REGION='US' \
GENERATE_DATA='yes' \
INCIDENT_SYSTEM='pagerduty' \
TF_LOG=$_TF_LOG \
TF_VAR_google_project_id='$_TARGET_PROJECT' \
TF_VAR_google_region='us-central1' \
TF_VAR_bigquery_region='US' \
TF_VAR_parsers='["cloud-build","github"]' \
./install.sh
- id: Check Installation
name: 'gcr.io/$PROJECT_ID/fourkeys-builder'
entrypoint: /bin/bash
args:
- '-c'
- |
result_check="import sys, json
results = int(json.load(sys.stdin)[0]['vol'])
try:
if results < 1:
sys.exit('Table is empty')
except Exception as e:
sys.exit(e)"
echo "Checking events_raw table"
bq query --format=json --project_id=$_TARGET_PROJECT --use_legacy_sql=false \
'SELECT count(*) as vol FROM four_keys.events_raw' | \
python3 -c "$result_check"
echo "Checking deployments table"
bq query --format=json --project_id=$_TARGET_PROJECT --use_legacy_sql=false \
'SELECT count(*) as vol FROM four_keys.deployments' | \
python3 -c "$result_check"
echo "Checking changes table"
bq query --format=json --project_id=$_TARGET_PROJECT --use_legacy_sql=false \
'SELECT count(*) as vol FROM four_keys.changes' | \
python3 -c "$result_check"
echo "Checking incidents table"
bq query --format=json --project_id=$_TARGET_PROJECT --use_legacy_sql=false \
'SELECT count(*) as vol FROM four_keys.incidents' | \
python3 -c "$result_check"
echo "Checking connection to dashboard..."
DASHBOARD_URL="$(terraform output -raw dashboard_endpoint)"
DASHBOARD_HTTP_RESPONSE_CODE=$(curl -LI $${DASHBOARD_URL} -o /dev/null -w '%{http_code}\n' -s)
if [ $${DASHBOARD_HTTP_RESPONSE_CODE} == "200" ]; then
echo "success"
else
echo "Error validating dashboard URL; received $${DASHBOARD_HTTP_RESPONSE_CODE} from $${DASHBOARD_URL}"
exit 1
fi
substitutions:
_TF_LOG: ERROR
_TARGET_PROJECT: fourkeys-tf-tests