Skip to content

Commit f5ec5ba

Browse files
committed
operations scripts cat out json templates
1 parent 04084f0 commit f5ec5ba

File tree

9 files changed

+125
-79
lines changed

9 files changed

+125
-79
lines changed

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@
2626
.vscode/
2727

2828
# Ignore Any Generated JSON Files
29+
operations/automation-script/apply.json
30+
operations/automation-script/configversion.json
31+
operations/automation-script/run.template.json
2932
operations/automation-script/run.json
30-
operations/automation-script/variables.json
33+
operations/automation-script/variable.template.json
34+
operations/automation-script/variable.json
35+
operations/automation-script/workspace.template.json
3136
operations/automation-script/workspace.json
32-
operations/sentinel-policies-scripts/create-policy.json
37+
operations/sentinel-policies-scripts/create-policy.template.json
38+
operations/sentinel-policies-scripts/create-policy.json
39+
operations/variable-scripts/variable.template.json
40+
operations/variable-scripts/variable.json

operations/automation-script/apply.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

operations/automation-script/configversion.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

operations/automation-script/loadAndRunWorkspace.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,81 @@ fi
109109
echo "Tarring configuration directory."
110110
tar -czf ${config_dir}.tar.gz -C ${config_dir} --exclude .git .
111111

112+
# Write out workspace.template.json
113+
cat > workspace.template.json <<EOF
114+
{
115+
"data":
116+
{
117+
"attributes": {
118+
"name":"placeholder",
119+
"terraform-version": "0.11.14"
120+
},
121+
"type":"workspaces"
122+
}
123+
}
124+
EOF
125+
126+
# Write out configversion.json
127+
cat > configversion.json <<EOF
128+
{
129+
"data": {
130+
"type": "configuration-versions",
131+
"attributes": {
132+
"auto-queue-runs": false
133+
}
134+
}
135+
}
136+
EOF
137+
138+
# Write out variable.template.json
139+
cat > variable.template.json <<EOF
140+
{
141+
"data": {
142+
"type":"vars",
143+
"attributes": {
144+
"key":"my-key",
145+
"value":"my-value",
146+
"category":"my-category",
147+
"hcl":my-hcl,
148+
"sensitive":my-sensitive
149+
}
150+
},
151+
"filter": {
152+
"organization": {
153+
"username":"my-organization"
154+
},
155+
"workspace": {
156+
"name":"my-workspace"
157+
}
158+
}
159+
}
160+
EOF
161+
162+
# Write out run.template.json
163+
cat > run.template.json <<EOF
164+
{
165+
"data": {
166+
"attributes": {
167+
"is-destroy":false
168+
},
169+
"type":"runs",
170+
"relationships": {
171+
"workspace": {
172+
"data": {
173+
"type": "workspaces",
174+
"id": "workspace_id"
175+
}
176+
}
177+
}
178+
}
179+
}
180+
EOF
181+
182+
# Write out apply.json
183+
cat > apply.json <<EOF
184+
{"comment": "apply via API"}
185+
EOF
186+
112187
#Set name of workspace in workspace.json
113188
sed "s/placeholder/${workspace}/" < workspace.template.json > workspace.json
114189

@@ -358,4 +433,14 @@ if [[ "$applied" == "true" ]]; then
358433

359434
fi
360435

436+
# Remove json files
437+
rm apply.json
438+
rm configversion.json
439+
rm run.template.json
440+
rm run.json
441+
rm variable.template.json
442+
rm variable.json
443+
rm workspace.template.json
444+
rm workspace.json
445+
361446
echo "Finished"

operations/automation-script/run.template.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

operations/automation-script/variable.template.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

operations/automation-script/workspace.template.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

operations/sentinel-policies-scripts/create-policy.template.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

operations/sentinel-policies-scripts/import_policies.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,32 @@ fi
5959
# Count the policies
6060
declare -i count=0
6161

62+
# Write out create-policy.template.json
63+
cat > create-policy.template.json <<EOF
64+
{
65+
"data": {
66+
"attributes": {
67+
"enforce": [
68+
{
69+
"path": "file-name",
70+
"mode": "advisory"
71+
}
72+
],
73+
"name": "policy-name",
74+
"description": "A Sentinel policy: policy-name"
75+
},
76+
"relationships": {
77+
"policy-sets": {
78+
"data": [
79+
{ "id": "policy-set-id", "type": "policy-sets" }
80+
]
81+
}
82+
},
83+
"type": "policies"
84+
}
85+
}
86+
EOF
87+
6288
# for loop to process all files with *.sentinel extension
6389
for f in *.sentinel; do
6490
echo "file is: $f"
@@ -81,4 +107,8 @@ for f in *.sentinel; do
81107

82108
done
83109

110+
# Remove create-policy.template.json and create-policy.json
111+
rm create-policy.template.json
112+
rm create-policy.json
113+
84114
echo "Found $count Sentinel policies"

0 commit comments

Comments
 (0)