From d885d2628fa712d551d65ddc6ed0cd7e31d42d66 Mon Sep 17 00:00:00 2001 From: Danielkon96 Date: Wed, 20 Oct 2021 18:38:02 +0000 Subject: [PATCH] add alt tenant option for aad creation --- AutomationScripts/3-registerAADApp.sh | 14 +++++++++++++- main.sh | 9 +++++++-- test.sh | 9 +++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/AutomationScripts/3-registerAADApp.sh b/AutomationScripts/3-registerAADApp.sh index a828b91..dc29af5 100644 --- a/AutomationScripts/3-registerAADApp.sh +++ b/AutomationScripts/3-registerAADApp.sh @@ -2,7 +2,14 @@ echo "BEGIN @ $(date +"%T"): Register AAD Application..." -CLIENT_ID=$(az ad app create --display-name $AD_APP_NAME --homepage $HOMEPAGE --reply-urls $REPLY_URLS --required-resource-accesses @./TemplateFiles/manifest.json --debug -o json | jq -r '.appId') +if [ -n "$ALT_TENANT_ID" ]; then + echo "SETTING ALT_TENANT_ID: " $ALT_TENANT_ID + SUBSCRIPTION_ID=$(az account show | jq -r '.id') + echo "ORIGINAL SUBSCRIPTION_ID: " $SUBSCRIPTION_ID + az account set -s $ALT_TENANT_ID +fi + +CLIENT_ID=$(az ad app create --display-name $AD_APP_NAME --homepage $HOMEPAGE --reply-urls $REPLY_URLS --required-resource-accesses @./TemplateFiles/manifest.json -o json | jq -r '.appId') echo "CLIENT_ID: " $CLIENT_ID # AAD core store is eventually consistent. Usually we can retrieve the object on the first try after creation, @@ -43,4 +50,9 @@ done AZURE_TENANT_ID=$(az account show -o json | jq '.tenantId' -r) echo "AZURE_TENANT_ID: " $AZURE_TENANT_ID +if [ -n "$ALT_TENANT_ID" ]; then + echo "SETTING TENANT BACK TO ORIGINAL: " $SUBSCRIPTION_ID + az account set -s $SUBSCRIPTION_ID +fi + echo "COMPLETE @ $(date +"%T"): Register AAD Application" \ No newline at end of file diff --git a/main.sh b/main.sh index 09cabb6..5944798 100644 --- a/main.sh +++ b/main.sh @@ -40,9 +40,10 @@ CLUSTER_RG='' EMAIL='' LOCATION='' INPUTIMAGE='' +ALT_TENANT_ID='' SKIP_CLUSTER_CREATION='' -while getopts "a:c:r:e:d:l:i:n:s:ph" OPTION +while getopts "a:c:r:e:l:i:t:ph" OPTION do case $OPTION in a) @@ -63,6 +64,9 @@ do i) # echo "The value of -i is ${OPTARG} - INPUTIMAGE" INPUTIMAGE=$OPTARG ;; + t) + # echo "The value of -i is ${OPTARG} - INPUTIMAGE" + ALT_TENANT_ID=$OPTARG ;; p) # echo "The value of -p is ${OPTARG} - SKIP_CLUSTER_CREATION" SKIP_CLUSTER_CREATION="True" ;; @@ -75,6 +79,7 @@ do echo "REQUIRED: -e is for EMAIL" echo "REQUIRED: -l is for LOCATION" echo "OPTOINAL: -i is for INPUTIMAGE" + echo "OPTOINAL: -t is for ALT_TENANT_ID" echo "OPTOINAL: -p is for SKIP_CLUSTER_CREATION" exit ;; esac @@ -98,6 +103,7 @@ echo "The value of -r is $CLUSTER_RG - CLUSTER_RG" echo "The value of -e is $EMAIL - EMAIL" echo "The value of -l is $LOCATION - LOCATION" echo "The value of -i is $INPUTIMAGE - INPUTIMAGE" +echo "The value of -t is $ALT_TENANT_ID - ALT_TENANT_ID" echo "The value of -p is $SKIP_CLUSTER_CREATION - SKIP_CLUSTER_CREATION" echo "COMPLETE @ $(date +"%T"): Setting variables" @@ -137,7 +143,6 @@ echo "****BEGIN @ $(date +"%T"): Call Install Cert Manager script****" echo "****COMPLETE @ $(date +"%T"): Installed Cert Manager script****" echo "BEGIN @ $(date +"%T"): Deploy sample app..." -# INPUTIMAGE=$7 # If we have a parameter for an image install a custom image. If not, then we install kuard. if [ -z "$INPUTIMAGE" ]; then echo "No image input, installing kuard." diff --git a/test.sh b/test.sh index 90be8e4..00a4565 100644 --- a/test.sh +++ b/test.sh @@ -7,9 +7,10 @@ R='' E='' L='' I='' +T='' P='' -while getopts "a:c:r:e:d:l:i:n:s:p:h" OPTION +while getopts "a:c:r:e:l:i:t:ph" OPTION do case $OPTION in a) @@ -30,6 +31,9 @@ do i) # echo "The value of -i is ${OPTARG} - INPUTIMAGE" I=$OPTARG ;; + t) + # echo "The value of -i is ${OPTARG} - INPUTIMAGE" + T=$OPTARG ;; p) # echo "The value of -p is ${OPTARG} - SKIP_CLUSTER_CREATION" P=$OPTARG ;; @@ -42,6 +46,7 @@ do echo "REQUIRED: -e is for EMAIL" echo "REQUIRED: -l is for LOCATION" echo "OPTOINAL: -i is for INPUTIMAGE" + echo "OPTOINAL: -t is for ALT_TENANT_ID" echo "OPTOINAL: -p is for SKIP_CLUSTER_CREATION" exit ;; esac @@ -49,7 +54,7 @@ done echo "" echo "BEGIN @ $(date +"%T"): START OF END-TO-END TEST" -bash ./main.sh -a $A -c $C -r $R -e $E -l $L +bash ./main.sh -a $A -c $C -r $R -e $E -l $L -t $T APP_NAME="$A.$L.cloudapp.azure.com" WEBPAGE=https://$APP_NAME