Last active
May 3, 2024 13:09
-
-
Save goors/c27e9b15c23f6c5e67f349da69d9073e to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
while getopts ":c:t:s:v:i:" opt; do | |
case ${opt} in | |
c ) | |
client_id=$OPTARG | |
;; | |
t ) | |
tenant_id=$OPTARG | |
;; | |
s ) | |
client_secret=$OPTARG | |
;; | |
v ) | |
vault_name=$OPTARG | |
;; | |
i ) | |
subscription_id=$OPTARG | |
;; | |
\? ) | |
echo "Invalid option: $OPTARG" 1>&2 | |
exit 1 | |
;; | |
: ) | |
echo "Invalid option: $OPTARG requires an argument" 1>&2 | |
exit 1 | |
;; | |
esac | |
done | |
# Verify that all required options are provided | |
if [[ -z $client_id || -z $tenant_id || -z $client_secret || -z $vault_name || -z $subscription_id ]]; then | |
echo "Usage: $0 -c <client_id> -t <tenant_id> -s <client_secret> -v <vault_name> -i <subscription_id>" >&2 | |
exit 1 | |
fi | |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash | |
password=$(grep -oP 'The generated password for the elastic built-in superuser is : \K\S+' /var/log/cloud-init-output.log) | |
export AZURE_CLIENT_ID="$client_id" | |
export AZURE_TENANT_ID="$tenant_id" | |
export AZURE_CLIENT_SECRET="$client_secret" | |
az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID" | |
az account set --subscription "$subscription_id" | |
secret_name="elastic-superuser-password" | |
secret_value="$password" | |
az keyvault secret set --vault-name "$vault_name" --name "$secret_name" --value "$secret_value" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment