adding config + pipeline #136
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rule Sets Pipeline | |
on: | |
pull_request: | |
branches: | |
- rule-sets-DTSPO-17918 | |
push: | |
branches: | |
- rule-sets-DTSPO-17918 | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
plan: | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Log in to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Generate GitHub Token | |
id: generate_token | |
run: | | |
echo "GITHUB_TOKEN=$(curl -s -X POST \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: Bearer ${{ secrets.GH_API_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/token | jq -r .token)" >> $GITHUB_ENV | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.5.7 | |
- name: Initialize and Plan Terraform | |
working-directory: ./components | |
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: ${{ env.GITHUB_TOKEN }} | |
run: | | |
terraform init -backend-config="resource_group_name=rule-set-rg" \ | |
-backend-config="storage_account_name=rulesetsa" \ | |
-backend-config="container_name=tfstate" \ | |
-backend-config="key=terraform.tfstate" | |
terraform plan -out=tfplan \ | |
-var="location=UK South" \ | |
-var="override_action=plan" \ | |
-var="github_token=${{ env.GITHUB_TOKEN }}" | |
- name: Upload Terraform plan | |
uses: actions/upload-artifact@v2 | |
with: | |
name: tfplan | |
path: components/tfplan | |
apply: | |
runs-on: ubuntu-latest | |
needs: plan | |
timeout-minutes: 60 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Log in to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.5.7 | |
- name: Download Terraform plan | |
uses: actions/download-artifact@v2 | |
with: | |
name: tfplan | |
path: components | |
- name: Initialize and Apply Terraform | |
working-directory: ./components | |
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: ${{ env.GITHUB_TOKEN }} | |
run: | | |
terraform init -backend-config="resource_group_name=rule-set-rg" \ | |
-backend-config="storage_account_name=rulesetsa" \ | |
-backend-config="container_name=tfstate" \ | |
-backend-config="key=terraform.tfstate" | |
terraform apply -auto-approve tfplan |