Skip to content

Instantly share code, notes, and snippets.

View rudolphjacksonm's full-sized avatar

Jack Morris rudolphjacksonm

View GitHub Profile
@rudolphjacksonm
rudolphjacksonm / create_milestone.sh
Created March 10, 2023 14:26
script for creating well-architected milestones
#!/bin/bash
set -euo pipefail
# assuming MILESTONE_NAME is passed in via release pipeline
source config/test_workload.env
source helpers/lib.sh
main() {
local milestoneName=$1
local workloadId=$(get_workload_id "${WORKLOAD_NAME}")
check_milestone "${workloadId}" "${milestoneName}"
@rudolphjacksonm
rudolphjacksonm / test_workload.env
Created March 10, 2023 14:16
Sample workload environment file
#!/bin/bash
AWS_REGIONS='"eu-west-1" "eu-west-2"'
ACCOUNT_IDS='''
123456789012
123456789011
'''
APPLICATIONS='''
arn:aws:servicecatalog:us-east-1: XXXXXXXXXX:/application/0bwdgnibevsc5clgtm7hehuljh
'''
ARCHITECTURAL_DESIGN='https://www.confluence.com'
@rudolphjacksonm
rudolphjacksonm / lib.sh
Last active March 10, 2023 14:11
Helpers script for automating well-architected tool
#!/bin/bash
get_workload_id() {
local workloadNamePrefix=${1:-null}
workloadId=$(aws wellarchitected list-workloads --workload-name-prefix "${workloadNamePrefix}" --query "WorkloadSummaries[0].WorkloadId" --output text)
if [[ "${workloadId}" == "None" ]] || [[ "${workloadId}" == "null" ]]; then
echo "No workload with prefix ${workloadNamePrefix} exists."
exit 1
else
echo "${workloadId}"
fi
@rudolphjacksonm
rudolphjacksonm / create_workload.sh
Created March 10, 2023 14:08
Script for creating workloads in the AWS Well-Architected Tool
#!/bin/bash
set -euo pipefail
source config/test_workload.env
source helpers/lib.sh
main() {
aws wellarchitected create-workload \
--account-ids "${ACCOUNT_IDS}" \
--architectural-design "${ARCHITECTURAL_DESIGN}" \
--aws-regions "eu-west-1" "eu-west-2" \
@rudolphjacksonm
rudolphjacksonm / cosmosdb_main_func.sh
Created December 17, 2021 15:33
CosmosDB Rotation Main Function
function main() {
local keyKind=$1
local cosmosDBAccountName=$2
echo "Beginning key rotation on ${cosmosDBAccountName}"
echo "Key: ${keyKind}"
# Rotate key
newConnString=$(rotate_keys "${keyKind}" "${cosmosDBAccountName}" | tail -n 1)
# Test Connectivity with new key
@rudolphjacksonm
rudolphjacksonm / upload_cosmosdb_secret.sh
Created December 17, 2021 15:32
Upload CosmosDB account key to Key Vault
function update_keyvault_secret() {
local keyKind=$1 # The kind of CosmosDB account key, which must be either primary or secondary.
local secretValue=$2
local cosmosDBAccountName=$3
local vaultNames=("${cosmosDBAccountName%-mongo}" "${cosmosDBAccountName%-mongo}-ukw")
local secretName
if [[ "${keyKind}" == "primary" ]]; then
secretName='cosmosDBPrimaryConnectionString'
else
@rudolphjacksonm
rudolphjacksonm / cosmosdb_rotate_script_output.log
Created December 17, 2021 15:04
CosmosDB Key Rotation Script Output
Beginning key rotation on <account name>
Key: primary
INFO: Command ran in 213.162 seconds (init: 0.154, invoke: 213.007)
Testing connectivity with new primary key...
Connecting to: mongodb://<credentials>@
MongoServerError: Invalid key
Connection attempt 3 unsuccessful, retrying in 40 seconds...
Current Mongosh Log ID: 618b9f15c57e6ca91fc75a8e
Connecting to: mongodb://<credentials>@
MongoServerError: Invalid key
@rudolphjacksonm
rudolphjacksonm / test_cosmosdb_connectivity.sh
Created December 17, 2021 14:51
Test CosmosDB connectivity with newly generated key
# Test CosmosDB Connectivity with a given string
function test_connectivity() {
local connString=$1
local counter=0
local successCount=0 # count of successful attempts
local maxWait=120 # max time allowed between loops
local minWait=5 # start of process
local timeOut=$((120 * 60)) # max time allowed until the loop is cancelled
local waitTime=minWait # time to wait between loops
local requiredSuccessConnections=5 # Number of successful connections required
@rudolphjacksonm
rudolphjacksonm / rotate_keys_func.sh
Created December 17, 2021 14:49
Rotate CosmosDB Account Key Function
function rotate_keys() {
local keyKind=$1
local cosmosDBAccountName=$2
local rgName="${2%-mongo}"
currentConnString=$(az cosmosdb keys list -n "${cosmosDBAccountName}" -g "${rgName}" --type connection-strings -o tsv --query "connectionStrings[? contains(description, '${keyKind:1} MongoDB')].connectionString")
# Start key rotation
if az cosmosdb keys regenerate -n "${cosmosDBAccountName}" -g "${rgName}" --key-kind "${keyKind}" --verbose; then
echo "Key rotation for ${cosmosDBAccountName} succeeded, retrieving ${keyKind} key"
newConnString=$(az cosmosdb keys list -n "${cosmosDBAccountName}" -g "${rgName}" --type connection-strings -o tsv --query "connectionStrings[? contains(description, '${keyKind:1} MongoDB')].connectionString")
@rudolphjacksonm
rudolphjacksonm / prep_agent.sh
Created December 17, 2021 14:47
Prep Azure DevOps Agent for CosmosDB Key Rotation
#!/bin/bash
function install_mongo_shell() {
# Installation instructions: https://docs.mongodb.com/mongodb-shell/install/
# Check the Ubuntu version used and modify installation accordingly
osRelease=$(cat /etc/os-release | grep 'VERSION=')
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
case $osRelease in
*"Xenial"*)
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
;;