Merge pull request #4752 from mitchellh/fix-4007
add sleep and retry to azure setup script
This commit is contained in:
commit
af9e7552db
|
@ -12,6 +12,7 @@ azure_tenant_id= # Derived from the account after login
|
||||||
location=
|
location=
|
||||||
azure_object_id=
|
azure_object_id=
|
||||||
azureversion=
|
azureversion=
|
||||||
|
create_sleep=10
|
||||||
|
|
||||||
showhelp() {
|
showhelp() {
|
||||||
echo "azure-setup"
|
echo "azure-setup"
|
||||||
|
@ -131,7 +132,7 @@ createResourceGroup() {
|
||||||
azure_group_name=$meta_name
|
azure_group_name=$meta_name
|
||||||
else
|
else
|
||||||
echo "Error creating resource group: $meta_name"
|
echo "Error creating resource group: $meta_name"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ createStorageAccount() {
|
||||||
azure_storage_name=$meta_name
|
azure_storage_name=$meta_name
|
||||||
else
|
else
|
||||||
echo "Error creating storage account: $meta_name"
|
echo "Error creating storage account: $meta_name"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +152,7 @@ createApplication() {
|
||||||
azure_client_id=$(azure ad app create -n $meta_name -i http://$meta_name --home-page http://$meta_name -p $azure_client_secret --json | jq -r .appId)
|
azure_client_id=$(azure ad app create -n $meta_name -i http://$meta_name --home-page http://$meta_name -p $azure_client_secret --json | jq -r .appId)
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error creating application: $meta_name @ http://$meta_name"
|
echo "Error creating application: $meta_name @ http://$meta_name"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +174,7 @@ createServicePrincipal() {
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error creating service principal: $azure_client_id"
|
echo "Error creating service principal: $azure_client_id"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ createPermissions() {
|
||||||
# azure role assignment create --spn http://$meta_name -g $azure_group_name -o "API Management Service Contributor"
|
# azure role assignment create --spn http://$meta_name -g $azure_group_name -o "API Management Service Contributor"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error creating permissions for: http://$meta_name"
|
echo "Error creating permissions for: http://$meta_name"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +206,31 @@ showConfigs() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doSleep() {
|
||||||
|
local sleep_time=${PACKER_SLEEP_TIME-$create_sleep}
|
||||||
|
echo ""
|
||||||
|
echo "Sleeping for ${sleep_time} seconds to wait for resources to be "
|
||||||
|
echo "created. If you get an error about a resource not existing, you can "
|
||||||
|
echo "try increasing the amount of time we wait after creating resources "
|
||||||
|
echo "by setting PACKER_SLEEP_TIME to something higher than the default."
|
||||||
|
echo ""
|
||||||
|
sleep $sleep_time
|
||||||
|
}
|
||||||
|
|
||||||
|
retryable() {
|
||||||
|
n=0
|
||||||
|
until [ $n -ge $1 ]
|
||||||
|
do
|
||||||
|
$2 && return 0
|
||||||
|
echo "$2 failed. Retrying..."
|
||||||
|
n=$[$n+1]
|
||||||
|
doSleep
|
||||||
|
done
|
||||||
|
echo "$2 failed after $1 tries. Exiting."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
requirements
|
requirements
|
||||||
|
|
||||||
|
@ -219,15 +245,11 @@ setup() {
|
||||||
# Some of the resources take a while to converge in the API. To make the
|
# Some of the resources take a while to converge in the API. To make the
|
||||||
# script more reliable we'll add a sleep after we create each resource.
|
# script more reliable we'll add a sleep after we create each resource.
|
||||||
|
|
||||||
createResourceGroup
|
retryable 3 createResourceGroup
|
||||||
sleep 5
|
retryable 3 createStorageAccount
|
||||||
createStorageAccount
|
retryable 3 createApplication
|
||||||
sleep 5
|
retryable 3 createServicePrincipal
|
||||||
createApplication
|
retryable 3 createPermissions
|
||||||
sleep 5
|
|
||||||
createServicePrincipal
|
|
||||||
sleep 5
|
|
||||||
createPermissions
|
|
||||||
|
|
||||||
showConfigs
|
showConfigs
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue