Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve transient failure with creating Service Principals in MAG #122

Merged
merged 12 commits into from
Apr 7, 2021
13 changes: 13 additions & 0 deletions src/docs/ui-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ This process will build the user interface container image on your workstation u
Log in using the Azure CLI

```BASH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes are unrelated to the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just trying to cleanup the documentation some as I run across things that need to be fixed or modified for clarity. Should I not do that here in this PR?

chmod u+x ./scripts/setup_ezdeploy.sh
./scripts/setup_ezdeploy.sh \
-d build \
-s <subscription_id> \
-t <tenant_id> \
-l <location> \
-e <tf_env_name> \
-m <mlz_env_name> \
-p port \
-0 <saca_subscription_id> \
-1 <tier0_subscription_id> \
-2 <tier1_subscription_id> \
-3 <tier2_subscription_id>
az login
```

Expand Down
58 changes: 54 additions & 4 deletions src/scripts/config/mlz_config_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,46 @@ usage() {
error_log "usage: mlz_config_create.sh <mlz config>"
}

sp_exists () {

sp_name=$1
sp_property=$2

sp_query="az ad sp show \
--id http://${sp_name} \
--query ${sp_property}"

if ! $sp_query &> /dev/null; then

sleep_time_in_seconds=10
max_wait_in_minutes=3
max_wait_in_seconds=180
max_retries=$((max_wait_in_seconds/sleep_time_in_seconds))

echo "Maximum time to wait in seconds = ${max_wait_in_seconds}"
echo "Maximum number of retries = ${max_retries}"

count=1

while ! $sp_query &> /dev/null
do

echo "Waiting for Service Principal ${sp_property} to complete provisioning (${count}/${max_retries})"
echo "Trying again in ${sleep_time_in_seconds} seconds..."
sleep "${sleep_time_in_seconds}"

if [[ ${count} -eq max_retries ]]; then
echo "Provisioning the Service Principal ${sp_property} has exceeded ${max_wait_in_minutes} minutes. Investigate and re-run script."
exit 1
fi

count=$((count +1))

done
fi

}

if [[ "$#" -lt 1 ]]; then
usage
exit 1
Expand Down Expand Up @@ -70,12 +110,22 @@ if [[ -z $(az ad sp list --filter "displayName eq '${mlz_sp_name}'" --query "[].
--output tsv)

# Get Service Principal AppId
# Added the sleep below to accomodate for the transient behavior where the Service Principal creation
Phydeauxman marked this conversation as resolved.
Show resolved Hide resolved
# is complete but an immediate query for it will fail. The sleep loop will run for 3 minutes and then
# the script will exit due to a platform problem
sp_exists "${mlz_sp_name}" "appId"

sp_clientid=$(az ad sp show \
--id "http://${mlz_sp_name}" \
--query appId \
--output tsv)
--id "http://${mlz_sp_name}" \
--query appId \
--output tsv)

# Get Service Principal ObjectId
# Added the sleep below to accomodate for the transient behavior where the Service Principal creation
# is complete but an immediate query for it will fail. The sleep loop will run for 3 minutes and then
# the script will exit due to a platform problem
sp_exists "${mlz_sp_name}" "objectId"

# Get Service Principal ObjectId
sp_objid=$(az ad sp show \
--id "http://${mlz_sp_name}" \
--query objectId \
Expand Down