Skip to content

Commit

Permalink
update workflow DEVOPS-302
Browse files Browse the repository at this point in the history
  • Loading branch information
githubofkrishnadhas committed Dec 27, 2024
1 parent add175e commit 2176267
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/terraform-modules-test-runs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: terraform-modules-test-runs
on:
## push:
workflow_dispatch:
inputs:
directory:
description: 'Which resource to create'
required: true
default: ''
type: choice
options:
- aks
- loganalytics-ws
- managed-identity
- storage-account
- vmss-linux
- vnet

action:
description: 'Choose action: apply or destroy'
required: true
default: 'apply'
type: choice
options:
- apply
- destroy

#These environment variables are used by the terraform azure provider to setup OIDD authenticate.
env:
ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}"
ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
ARM_TENANT_ID: "${{ secrets.ARM_TENANT_ID }}"
ARM_CLIENT_SECRET: "${{ secrets.ARM_CLIENT_SECRET }}"

run-name: terraform-modules-runs - ${{ inputs.directory }} - ${{ inputs.action }}
jobs:
terraform-modules-test-runs:
runs-on: ubuntu-latest

steps:
- name: checkout repo
uses: actions/checkout@v4

- name: checking files
run: ls -la

- name: Token generator
uses: githubofkrishnadhas/github-access-using-githubapp@v2
id: app-token
with:
github_app_id: ${{ secrets.TOKEN_GENERATOR_APPID }}
github_app_private_key: ${{ secrets.TOKEN_GENERATOR_PRIVATE_KEY }}
owner: 'devwithkrishna'
repositories: 'azure-terraform-modules'

- name: Print the token
run: echo "Generated token ${{ steps.app-token.outputs.token }}"

- name: Token generator current repo
uses: githubofkrishnadhas/github-access-using-githubapp@v2
id: app-token1
with:
github_app_id: ${{ secrets.TOKEN_GENERATOR_APPID }}
github_app_private_key: ${{ secrets.TOKEN_GENERATOR_PRIVATE_KEY }}

- name: Print the token1
run: echo "Generated token ${{ steps.app-token1.outputs.token }}"

- name: setup for tfmodule
env:
token: ${{ steps.app-token.outputs.token }}
run: |
git config --local --remove-section http."https://github.com/"
git config --global url."https://githubofkrishnadhas:${{ steps.app-token.outputs.token }}@github.com/devwithkrishna".insteadOf "https://github.com/devwithkrishna"
- name: git config
run: git config --list --show-origin

- name: terraform setup

uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.5.7"

- name: terraform checking
run: |
terraform --version
- name: terraform init
run: terraform -chdir=${{ inputs.directory }} init

- name: Terraform Plan
run: terraform -chdir=${{ inputs.directory }} plan -out=planfile ${{ github.event.inputs.action == 'destroy' && '-destroy' || '' }}

- name: Terraform Apply
if: ${{ github.event.inputs.action == 'apply' }}
run: terraform -chdir=${{ inputs.directory }} apply -auto-approve planfile

- name: Terraform Destroy
if: ${{ github.event.inputs.action == 'destroy' }}
run: terraform -chdir=${{ inputs.directory }} apply -auto-approve planfile

0 comments on commit 2176267

Please sign in to comment.