Hi @Bandela Siri Chandana , sorry for the delay. Here are the details. I want to accomplish this using Bicep with the Azure CLI via the deployment scripts module, or alternatively by using Microsoft.Graph/applications@v1.0
in Bicep. The attached script is executing, but it’s not registering the app and isn’t throwing any errors. Any help regarding this would be appreciated. Also, is there any other way to do this using Microsoft.Graph/applications@v1.0
?
Script:
@description('The Application (client) ID of the App Registration')
param clientAppId string
@description('The object ID of the Service Principal of App Registration')
param spObjectId string
@description('The GitHub subject in format repo:octo-org/octo-org:ref:refs/heads/master')
param githubSubject string
@description('Web App name')
param webAppName string
@description('Web App resource group')
param webAppResourceGroup string
@description('Role to be Assigned like Website Contributor')
param roleToAssign string
@description('Federated Credential name')
param federatedCredName string
@description('Azure location for deployment script')
param location string = resourceGroup().location
resource runScript 'Microsoft.Resources/deploymentScripts@2023-08-01' = {
name: 'runFederatedCredAndRoleAssignment'
location: location
kind: 'AzureCLI'
properties: {
azCliVersion: '2.52.0'
retentionInterval: 'P1D'
cleanupPreference: 'OnSuccess'
environmentVariables: [
{
name: 'CLIENT_APP_ID'
value: clientAppId
}
{
name: 'SP_OBJECT_ID'
value: spObjectId
}
{
name: 'GITHUB_SUBJECT'
value: githubSubject
}
{
name: 'WEBAPP_NAME'
value: webAppName
}
{
name: 'WEBAPP_RG'
value: webAppResourceGroup
}
{
name: 'CRED_NAME'
value: federatedCredName
}
{
name: 'ROLE_ASSIGNED'
value: roleToAssign
}
]
scriptContent: '''
echo "Creating federated identity credential\n"
az ad app federated-credential create --id $CLIENT_APP_ID --parameters '{
"name": "'$CRED_NAME'",
"issuer": "https://token.actions.githubusercontent.com/",
"subject": "'$GITHUB_SUBJECT'",
"description": "OIDC federated credential for GitHub Actions",
"audiences": ["api://AzureADTokenExchange"]
}'
echo "Getting Web App resource ID\n"
WEBAPP_ID=$(az webapp show --name $WEBAPP_NAME --resource-group $WEBAPP_RG --query id --output tsv)
echo "Assigning role\n"
az role assignment create --assignee $SP_OBJECT_ID --role $ROLE_ASSIGNED --scope $WEBAPP_ID
'''
}
}