-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (127 loc) · 5.29 KB
/
stackql.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Demo of stackql GitHub Actions
on:
push:
branches:
- main
workflow_dispatch:
jobs:
stackql-actions-demo:
name: stackql actions demo
runs-on: ubuntu-latest
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
steps:
- uses: actions/checkout@v3
name: checkout repo
with:
fetch-depth: 0
- name: setup StackQL
uses: stackql/[email protected]
with:
use_wrapper: true
- name: pull Google docs
shell: bash
run: |
stackql exec "REGISTRY PULL google"
- name: dry run StackQL query
shell: bash
run: |
stackql exec \
-i ./stackql/scripts/deploy-instances/deploy-instances.iql \
--iqldata ./stackql/data/vars.jsonnet \
--var GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }} \
--output text -H --dryrun
- name: initial check for instances using stackql-assert
id: check_instances_initial
uses: stackql/[email protected]
with:
test_query_file_path: './stackql/scripts/check-instances/check-instances.iql'
data_file_path: './stackql/data/vars.jsonnet'
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
expected_rows: 4
continue-on-error: true
- name: deploy instances using stackql-exec
if: steps.check_instances_initial.outcome == 'failure' # Run if the initial check failed
id: deploy_instances
uses: stackql/[email protected]
with:
query_file_path: './stackql/scripts/deploy-instances/deploy-instances.iql'
data_file_path: './stackql/data/vars.jsonnet'
is_command: 'true'
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
- name: check if we have 4 instances using stackql-assert
if: steps.check_instances_initial.outcome == 'failure' && steps.deploy_instances.outcome == 'success'
uses: stackql/[email protected]
with:
test_query_file_path: './stackql/scripts/check-instances/check-instances.iql'
data_file_path: './stackql/data/vars.jsonnet'
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
expected_rows: 4
- name: stop running instances using stackql-exec
uses: stackql/[email protected]
with:
query_file_path: './stackql/scripts/stop-instances/stop-instances.iql'
is_command: 'true'
- name: "[CLEANUP] delete instances using stackql-exec"
uses: stackql/[email protected]
with:
query_file_path: './stackql/scripts/delete-instances/delete-instances.iql'
is_command: 'true'
data_file_path: './stackql/data/vars.jsonnet'
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }}
stackql-actions-with-terraform-demo:
name: stackql actions with terraform demo
runs-on: ubuntu-latest
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }}
steps:
- uses: actions/checkout@v3
name: checkout repo
with:
fetch-depth: 0
- name: setup StackQL
uses: stackql/[email protected]
with:
use_wrapper: true
- name: pull Google docs
shell: bash
run: |
stackql exec "REGISTRY PULL google"
- uses: hashicorp/setup-terraform@v2
- name: Terraform Init
id: init
run: cd terraform; terraform init
- name: Terraform Validate
env:
TF_VAR_google_credentials: ${{ secrets.GOOGLE_CREDENTIALS }}
id: validate
run: cd terraform; terraform validate -no-color
- name: Terraform Plan
env:
TF_VAR_google_credentials: ${{ secrets.GOOGLE_CREDENTIALS }}
id: plan
run: cd terraform; terraform plan -no-color -var-file=stackql-demo.tfvars
- name: Terraform Apply
env:
TF_VAR_google_credentials: ${{ secrets.GOOGLE_CREDENTIALS }}
id: apply
run: cd terraform; terraform apply -no-color -var-file=stackql-demo.tfvars -auto-approve
- name: check terraform deployment using stackql-assert - should pass
uses: stackql/[email protected]
with:
test_query_file_path: './stackql/scripts/check-terraform-instances/check-terraform-instances.iql'
expected_rows: 3
- name: run a compliance check using stackql-assert - should fail
uses: stackql/[email protected]
with:
test_query_file_path: './stackql/scripts/run-compliance-checks/run-compliance-checks.iql'
expected_rows: 0
- name: "[CLEANUP] delete instances and bucket using stackql-exec"
if: failure()
uses: stackql/[email protected]
with:
query_file_path: './stackql/scripts/terraform-cleanup/terraform-cleanup.iql'