terraform-modules-resource-creations - aks - destroy #13
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: terraform-modules-resource-creations-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-resource-creations - ${{ 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 |