Skip to content

DTSPO 18475 Fix Up

DTSPO 18475 Fix Up #4

Workflow file for this run

name: Terraform CI/CD
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
env:
TF_LOG: INFO
permissions:
id-token: write
issues: write
pull-requests: write
contents: read
jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: 'Az CLI login'
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
- name: Install jq
run: sudo apt-get install jq -y
- name: List Repositories and Branches
run: |
echo "Checking Repositories and Branches"
cat ./production-repos.json
for repo in $(jq -r '.[]' ./production-repos.json); do
echo "Checking repository: $repo"
curl -H "Authorization: token ${{ secrets.OAUTH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/hmcts/$repo
- name: Terraform Init
working-directory: components
env:
STORAGE_ACCOUNT: ${{ secrets.STORAGE_ACCOUNT }}
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
RESOURCE_GROUP_NAME: ${{ secrets.RESOURCE_GROUP_NAME }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
run: terraform init -backend-config="storage_account_name=$STORAGE_ACCOUNT" -backend-config="container_name=$CONTAINER_NAME" -backend-config="resource_group_name=$RESOURCE_GROUP_NAME" -reconfigure
- name: Terraform format
working-directory: components
id: fmt
run: terraform fmt -check
- name: Terraform validate
working-directory: components
id: validate
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
run: terraform validate
- name: Terraform plan
working-directory: components
id: plan
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
GITHUB_TOKEN: ${{ secrets.OAUTH_TOKEN }}
run: terraform plan -var="oauth_token=${{ secrets.OAUTH_TOKEN }}"
- name: Terraform Apply
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
working-directory: components
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
GITHUB_TOKEN: ${{ secrets.OAUTH_TOKEN }}
run: terraform apply -var="oauth_token=${{ secrets.OAUTH_TOKEN }}" -auto-approve