From ccc077fc3601edbc37d3742bf181dc0322c781bd Mon Sep 17 00:00:00 2001 From: Connor O'Kane Date: Sun, 7 Jul 2024 22:35:24 +0100 Subject: [PATCH] adding config + pipeline --- .github/workflows/pr.yaml | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/pr.yaml diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 000000000..3410ea60f --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,75 @@ +name: Pull Request + +on: + pull_request: + branches: + - rule-sets-DTSPO-17918 + +env: + TF_LOG: INFO + +permissions: + id-token: write + issues: write + pull-requests: write + contents: read +jobs: + pr-infra-check: + runs-on: ubuntu-latest + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v3 + + # Install the latest version of Terraform CLI + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + + # Log into Azure with OIDC integration + - 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 }} + + # Run az commands to confirm sub access + - name: 'Run az commands' + run: | + az account show + + # Run Terraform init + - name: Terraform Init + id: init + 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_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" + + # Run a Terraform fmt + - name: Terraform format + id: fmt + run: terraform fmt -check + + # Run a Terraform validate + - name: Terraform validate + id: validate + if: success() || failure() + env: + ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }} + ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + run: terraform validate -no-color + + # Run a Terraform plan + - name: Terraform plan + id: plan + env: + ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }} + ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + run: terraform plan -no-color \ No newline at end of file