Skip to content

Commit 5fbd4b4

Browse files
Merge pull request #55 from microsoft/psl-rg-tags
ci: Add support for tagging Resource Groups using GitHub variables
2 parents b421fc9 + e59c2c2 commit 5fbd4b4

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

.github/workflows/azd-ai-template-validation.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,29 @@ jobs:
1818
runs-on: ubuntu-latest
1919
name: Validation steps
2020
environment: 'rti-validate'
21+
env:
22+
RG_TAGS: ${{ vars.RG_TAGS }}
2123
steps:
2224
- name: Checkout
2325
uses: actions/checkout@v4
26+
27+
- name: Add RG tags into Bicep parameter file
28+
shell: bash
29+
run: |
30+
# Parse RG_TAGS (format: "Key=Value Key2=Value2") into a JSON object
31+
TAG_JSON="{}"
32+
for tag in ${{ env.RG_TAGS }}; do
33+
KEY="${tag%%=*}"
34+
VALUE="${tag#*=}"
35+
TAG_JSON=$(echo "$TAG_JSON" | jq --arg k "$KEY" --arg v "$VALUE" '. + {($k): $v}')
36+
done
37+
38+
jq --argjson tags "$TAG_JSON" '.parameters.tags = {"value": $tags}' \
39+
infra/main.parameters.json > infra/main.parameters.tmp.json
40+
mv infra/main.parameters.tmp.json infra/main.parameters.json
41+
echo "✅ Added tags into main.parameters.json"
42+
cat infra/main.parameters.json
43+
2444
- name: Validate AZD template
2545
uses: microsoft/template-validation-action@Latest
2646
id: validation
@@ -32,5 +52,5 @@ jobs:
3252
AZURE_ENV_NAME: '${{ vars.AZURE_ENV_NAME }}val'
3353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3454

35-
- name: print result
55+
- name: Print result
3656
run: cat ${{ steps.validation.outputs.resultFile }}

.github/workflows/azure-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ env:
3131
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
3232
AZURE_LOCATION: 'westus3'
3333
PYTHONIOENCODING: utf-8
34+
RG_TAGS: ${{ vars.RG_TAGS }}
3435

3536
jobs:
3637
build:
@@ -76,7 +77,7 @@ jobs:
7677
rg_exists=$(az group exists --name $RESOURCE_GROUP_NAME)
7778
if [ "$rg_exists" = "false" ]; then
7879
echo "📦 Resource group does not exist. Creating new resource group '$RESOURCE_GROUP_NAME' in location '$AZURE_LOCATION'..."
79-
az group create --name $RESOURCE_GROUP_NAME --location $AZURE_LOCATION || { echo "❌ Error creating resource group"; exit 1; }
80+
az group create --name $RESOURCE_GROUP_NAME --location $AZURE_LOCATION --tags ${{ env.RG_TAGS }} || { echo "❌ Error creating resource group"; exit 1; }
8081
echo "✅ Resource group '$RESOURCE_GROUP_NAME' created successfully."
8182
else
8283
echo "✅ Resource group '$RESOURCE_GROUP_NAME' already exists. Deploying to existing resource group."

0 commit comments

Comments
 (0)