Skip to content

Instantly share code, notes, and snippets.

@riosengineer
Created November 12, 2025 16:44
Show Gist options
  • Select an option

  • Save riosengineer/205b41ade344fd59835cdf8c6adff22b to your computer and use it in GitHub Desktop.

Select an option

Save riosengineer/205b41ade344fd59835cdf8c6adff22b to your computer and use it in GitHub Desktop.
Bicep Ephemeral CI Setup
# Set variables
SUBSCRIPTION_ID="<YOUR_APP_SUBSCRIPTION_ID>"
HUB_SUBSCRIPTION_ID="<YOUR_HUB_SUBSCRIPTION_ID>"
HUB_RG="<YOUR_HUB_RG>"
APP_NAME="<YOUR_APP_REG_NAME>"
GITHUB_ORG="<YOUR_GITHUB_NAME>"
GITHUB_REPO="<YOUR_GITHUB_REPO>"
# Create Azure AD application and service principal
APP_ID=$(az ad app create --display-name "$APP_NAME" --query appId -o tsv)
az ad sp create --id $APP_ID
# Assign Contributor on app subscription
az role assignment create \
--assignee $APP_ID \
--role Contributor \
--scope /subscriptions/$SUBSCRIPTION_ID
# Assign Reader on hub subscription
az role assignment create \
--assignee $APP_ID \
--role Reader \
--scope /subscriptions/$HUB_SUBSCRIPTION_ID
# Assign Network Contributor on hub resource group
az role assignment create \
--assignee $APP_ID \
--role "Network Contributor" \
--scope /subscriptions/$HUB_SUBSCRIPTION_ID/resourceGroups/$HUB_RG
# Add OIDC federated credential for pull requests
az ad app federated-credential create \
--id $APP_ID \
--parameters "{
\"name\": \"github-pr\",
\"issuer\": \"https://token.actions.githubusercontent.com\",
\"subject\": \"repo:${GITHUB_ORG}/${GITHUB_REPO}:pull_request\",
\"audiences\": [\"api://AzureADTokenExchange\"]
}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment