Skip to content

Update the workflow #32

Update the workflow

Update the workflow #32

name: Infrastructure CI/CD pipeline
on:
push:
branches: [ "main" ]
paths-ignore: ["**/*.md"]
pull_request:
branches: [ "main" ]
paths-ignore: ["**/*.md"]
workflow_dispatch:
jobs:
CI:
permissions:
actions: read
contents: read
id-token: write
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
TF_VAR_ssh_pub_key_file: "./id_rsa.pub"
defaults:
run:
working-directory: ./infrastructure
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Init
run: |
terraform init
- name: Validate
run: |
terraform validate
- name: Install tfsec for scanning
run:
go install github.com/aquasecurity/tfsec/cmd/tfsec@latest > /dev/null 2>&1
- name: scan
run: |
export PATH=$PATH:$HOME/go/bin
tfsec
continue-on-error: true
- name: setup SSH
run: |
echo ${{ secrets.SSH_PUB_KEY }} > ./id_rsa.pub
chmod 600 ./id_rsa.pub
- name: plan
run: |
terraform plan
- name: apply
if: github.event_name == 'push'
run: |
terraform apply -auto-approve
- name: save azure VMs public ip address
if: github.event_name == 'push'
run: terraform output > virtual_machines.ini
- name: Upload virtual_machines.ini
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: virtual machines ip address
path: ./infrastructure/virtual_machines.ini
retention-days: 1