Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

work around AAD service principal race condition #716

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/deployment/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,33 @@ def setup_rbac(self) -> None:
service_principal_type="Application",
app_id=app.app_id,
)
client.service_principals.create(service_principal_params)

def try_sp_create() -> None:
error: Optional[Exception] = None
for _ in range(10):
try:
client.service_principals.create(service_principal_params)
return
except GraphErrorException as err:
# work around timing issue when creating service principal
# https://github.com/Azure/azure-cli/issues/14767
if (
"service principal being created must in the local tenant"
not in str(err)
):
raise err
logging.warning(
"creating service principal failed with an error that occurs "
"due to AAD race conditions"
)
time.sleep(60)
if error is None:
raise Exception("service principal creation failed")
else:
raise error

try_sp_create()

else:
app = existing[0]
existing_role_values = [app_role.value for app_role in app.app_roles]
Expand Down