generated from cloud-gov/.github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts for creating and deleting resources locally
Resolves cloud-gov/product#3118
- Loading branch information
1 parent
ac1c88f
commit b714f7f
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
*.tfvars | ||
*.brokerpak | ||
# Configuration for the CSB CLI client. | ||
clientconfig.yml | ||
# Configuration for the CSB server. | ||
secrets.env | ||
zscaler.crt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
bindings.txt | ||
bindings.txt.history | ||
credentials.json | ||
instances.txt | ||
instances.txt.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
# Work around the broker not having a command like `csb client list` by tracking the | ||
# instances and bindings we've created. | ||
|
||
if [ "$#" -lt 1 ]; then | ||
printf "Usage:\n\n\t\$./down.sh /path/to/workdir\n\nWorking directory must match the directory passed to up.sh." | ||
exit 1 | ||
fi | ||
|
||
workdir=$1 | ||
|
||
cat "${workdir}/bindings.txt" | xargs -n 2 bash -c 'cloud-service-broker client unbind --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid $1 --bindingid $2' - | ||
echo "\n\n$(date)" >> bindings.txt.history | ||
cat ${workdir}/bindings.txt >> ${workdir}/bindings.txt.history | ||
rm ${workdir}/bindings.txt | ||
|
||
cat "${workdir}/instances.txt" | xargs -I % cloud-service-broker client deprovision --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid % | ||
echo "\n$(date)" >> instances.txt.history | ||
cat ${workdir}/instances.txt >> ${workdir}/instances.txt.history | ||
rm ${workdir}/instances.txt | ||
|
||
echo "Done. instances.txt and bindings.txt cleared. History recorded in instances.txt.history and bindings.txt.history." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
if [ "$#" -lt 2 ]; then | ||
printf "Usage:\n\n\t\$./up.sh [email protected] /path/to/workdir\n\n" | ||
exit 1 | ||
fi | ||
|
||
recipient=$1 | ||
workdir=$2 | ||
|
||
csb=cloud-service-broker | ||
|
||
# Instance IDs must be unique, so generate a new one | ||
instanceid=$(uuidgen | tr "[A-Z]" "[a-z]") | ||
echo "Instance ID: $instanceid" | ||
|
||
# Start provisioning | ||
$csb client provision --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid $instanceid --params "{\"dmarc_report_uri_aggregate\": \"mailto:${recipient}\", \"dmarc_report_uri_failure\": \"${recipient}\"}" | ||
|
||
# Wait on provisioning to finish | ||
state="" | ||
while [[ "$state" != "succeeded" ]]; do | ||
sleep 10 | ||
state=$($csb client --config clientconfig.yml last --instanceid $instanceid | jq -r '.response.state') | ||
echo "State: $state" | ||
done | ||
|
||
touch "$workdir/instances.txt" | ||
echo $instanceid >> "$workdir/instances.txt" | ||
|
||
# Let the broker settle | ||
sleep 1 | ||
|
||
# Binding IDs must be unique, so generate a new one | ||
bindingid=$(uuidgen | tr "[A-Z]" "[a-z]") | ||
echo "Binding ID: $bindingid" | ||
touch "$workdir/bindings.txt" | ||
echo "$instanceid $bindingid" >> "$workdir/bindings.txt" | ||
|
||
# Update smtp-client with new credentials | ||
$csb client bind --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid $instanceid --bindingid $bindingid | jq '.response.credentials' > "$workdir/credentials.json" | ||
|
||
echo "Done. Credentials saved to credentials.json for use with the client. GUIDs saved to instances.txt and bindings.txt. Deprovision later with down.sh." |