Intro
In this part of the blog series, I want to focus on the GitHub Actions I created in the first part and explain what the Action performs. I will also add the vNet resources to my deployments.
GitHub Actions explained
To explain what is going on in the GitHub Action, I have added comments to each code section.
# Name of the action
name: rg-connectivity-001
# Controls when the workflow will run
on:
# Triggers the workflow on changes to the terraform files in the path
# Subscriptions/Sub-MVP-Sponsorship/rg-connectivity-001/
# Action will only trigger on the main branch
push:
paths:
- 'Subscriptions/Sub-MVP-Sponsorship/rg-connectivity-001/*.tf'
branches:
- main
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This action only has one job called Connectivity
Connectivity:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Setting environment variables
# Variables are used by Terraform to authenticate to Azure
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.MVP_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Initialize Terraform
- name: 'Terraform init'
id: init
run: |
cd Subscriptions/Sub-MVP-Sponsorship/rg-connectivity-001
terraform init
# Create Terraform plan
- name: 'Terraform plan'
id: plan
run: |
cd Subscriptions/Sub-MVP-Sponsorship/rg-connectivity-001
terraform plan
# Deploy the planned resources to Azure using Terraform
- name: 'Terraform apply'
id: apply
run: |
cd Subscriptions/Sub-MVP-Sponsorship/rg-connectivity-001
terraform apply -auto-approve
You might have noticed that I have added a few things to the actions since part 1, but please update your Actions with these changes if you haven’t. The main difference is adding the filter “braches: main,” the rest is cosmetic and only comments.