Skip to content

Deploy Infrastructure #27

Deploy Infrastructure

Deploy Infrastructure #27

name: Deploy Infrastructure
on:
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
permissions:
id-token: write
contents: read
jobs:
create-resource-group:
name: Create Azure resource groups for VM images
runs-on: ubuntu-latest
steps:
- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Create resource group
uses: azure/CLI@v1
with:
azcliversion: latest
inlineScript: |
az group create -l germanywestcentral -n packer-images-rg
packer-build-IIS:
name: Build IIS VM image
runs-on: ubuntu-latest
needs: create-resource-group
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup Packer
uses: hashicorp/setup-packer@main
- name: Packer Init
run: packer init ./iis-vm.pkr.hcl
- name: Packer Build
run: packer build ./iis-vm.pkr.hcl
packer-build-agent:
name: Build Agent VM image
runs-on: ubuntu-latest
needs: create-resource-group
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup Packer
uses: hashicorp/setup-packer@main
- name: Packer Init
run: packer init ./iis-vm.pkr.hcl
- name: Packer Build
run: packer build -var "azure_devops_org=${{ secrets.AZURE_DEVOPS_ORG }}" -var "azure_devops_pat=${{ secrets.AZURE_DEVOPS_PAT }}" ./build-agent-vm.pkr.hcl
deploy-terraform:
name: Deploy terraform
runs-on: ubuntu-latest
needs: [packer-build-IIS, packer-build-agent]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform Init
run: terraform init
- name: Terraform Plan
run: terraform plan
- name: Terraform apply
run: terraform apply -auto-approve