Skip to content

Commit ec97453

Browse files
committed
CI: add simple Azure Login workflow
We currently depend on the azure/login GitHub Action in various places. It simply runs an "az login" and "az account set" behind the scenes, and has support for plenty of other scenarios. As we're moving away from azure/cli in more and more places, we could also replace the login script with our own. Let's create a Composite Workflow to achieve this goal. Signed-off-by: Dennis Ameling <dennis@dennisameling.com>
1 parent 72a1b0d commit ec97453

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Azure Login
2+
description: Logs into Azure using a service principal
3+
inputs:
4+
credentials:
5+
description: Your credentials in JSON format
6+
required: true
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Process Azure credentials
12+
uses: actions/github-script@v7
13+
env:
14+
AZURE_CREDENTIALS: ${{ inputs.credentials }}
15+
with:
16+
script: |
17+
if (!process.env.AZURE_CREDENTIALS) {
18+
core.setFailed('The AZURE_CREDENTIALS secret is required.')
19+
process.exit(1)
20+
}
21+
22+
const azureCredentials = JSON.parse(process.env.AZURE_CREDENTIALS)
23+
const {clientId, clientSecret, tenantId, subscriptionId} = azureCredentials
24+
25+
core.setSecret(clientId)
26+
core.exportVariable('AZURE_CLIENT_ID', clientId)
27+
28+
core.setSecret(clientSecret)
29+
core.exportVariable('AZURE_CLIENT_SECRET', clientSecret)
30+
31+
core.setSecret(tenantId)
32+
core.exportVariable('AZURE_TENANT_ID', tenantId)
33+
34+
core.setSecret(subscriptionId)
35+
core.exportVariable('AZURE_SUBSCRIPTION_ID', subscriptionId)
36+
37+
- name: Azure Login
38+
shell: bash
39+
run: |
40+
echo "Logging into Azure..."
41+
az login --service-principal -u ${{ env.AZURE_CLIENT_ID }} -p ${{ env.AZURE_CLIENT_SECRET }} --tenant ${{ env.AZURE_TENANT_ID }}
42+
echo "Setting subscription..."
43+
az account set --subscription ${{ env.AZURE_SUBSCRIPTION_ID }} --output none

0 commit comments

Comments
 (0)