Skip to content

Always specify subscription id in AzureRM provider #16

Always specify subscription id in AzureRM provider

Always specify subscription id in AzureRM provider #16

# Runs terraform apply/plan for each cluster in ./terraform/clusters
name: Apply/Plan clusters
on:
push:
branches:
- master
paths:
- 'terraform/clusters/**'
pull_request:
types: [labeled, opened, synchronize, reopened]
paths:
- 'terraform/clusters/**'
jobs:
get_subscriptions:
if: contains(github.event.pull_request.labels.*.name, 'deploy') || github.event_name == 'push'
name: Get subscriptions
runs-on: ubuntu-latest
outputs:
subscriptions: ${{ steps.set-matrix.outputs.subscriptions }}
env:
path: terraform/clusters
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: echo "subscriptions=$(ls ${{ env.path }} | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
get_radix_environments:
needs: get_subscriptions
if: contains(github.event.pull_request.labels.*.name, 'deploy') || github.event_name == 'push'
name: Get radix environments
runs-on: ubuntu-latest
strategy:
matrix:
subscriptions: ${{ fromJson(needs.get_subscriptions.outputs.subscriptions) }}
outputs:
radix_environment: ${{ steps.set-matrix.outputs.radix_environment }}
env:
path: terraform/clusters/${{ matrix.subscriptions }}
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: echo "radix_environment=$(ls ${{ env.path }} | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
get_clusters:
needs: [get_radix_environments, get_subscriptions]
name: Get clusters
runs-on: ubuntu-latest
strategy:
matrix:
radix_environment: ${{ fromJson(needs.get_radix_environments.outputs.radix_environment) }}
subscriptions: ${{ fromJson(needs.get_subscriptions.outputs.subscriptions) }}
outputs:
matrix: ${{ steps.set-matrix.outputs.list_of_environments_and_clusters_fmt }}
env:
path: terraform/clusters/${{ matrix.subscriptions }}/${{ matrix.radix_environment }}
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: |
cd ${{ env.path }}
mapfile -t radix_environments < <(ls .)
list_of_environments_and_clusters=$(for radix_environment in "${radix_environments[@]}"; do
if [[ -z $(ls "$radix_environment") ]]; then continue; fi
mapfile -t cluster_names < <(ls "$radix_environment")
for cluster_name in "${cluster_names[@]}"; do
jq -n \
--arg radix_environment "$radix_environment" \
--arg cluster_name "$cluster_name" \
'{radix_environment:$radix_environment, cluster_name:$cluster_name}';
done
done)
echo "list_of_environments_and_clusters_fmt=$(echo "$list_of_environments_and_clusters" | jq -sc .)" >> $GITHUB_OUTPUT
Terraform:
needs: [get_clusters, get_radix_environments, get_subscriptions]
name: Terraform
uses: ./.github/workflows/terraform.yml
strategy:
fail-fast: false
matrix:
cluster_info: ${{ fromJSON(needs.get_clusters.outputs.matrix) }}
radix_environment: ${{ fromJson(needs.get_radix_environments.outputs.radix_environment) }}
subscriptions: ${{ fromJson(needs.get_subscriptions.outputs.subscriptions) }}
with:
cluster_name: ${{ matrix.cluster_info.cluster_name }}
environment: operations
radix_environment: ${{ matrix.radix_environment }}
subscription: ${{ matrix.subscriptions }}
terraform_version: ~1.3.0
working_directory: terraform/clusters/${{ matrix.subscriptions }}/${{ matrix.radix_environment }}/${{ matrix.cluster_info.radix_environment }}/${{ matrix.cluster_info.cluster_name }}
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}