terraform modules auth using github app installation token #17
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 auth using github app installation token | |
on: | |
## push: | |
workflow_dispatch: | |
inputs: | |
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 auth using github app installation token | |
jobs: | |
terraform-modules-auth-using-github-app-installation-token: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout repo | |
uses: actions/checkout@v4 | |
- name: checking files | |
run: ls -la | |
- name: Token generator | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ secrets.TOKEN_GENERATOR_APPID }} | |
private-key: ${{ secrets.TOKEN_GENERATOR_PRIVATE_KEY }} | |
owner: 'devwithkrishna' | |
repositories: 'azure-terraform-modules' | |
- name: echo token | |
run: echo ${GH_APP_TOKEN} > txt.txt | |
# - name: clone manually | |
# uses: actions/checkout@v4 | |
# with: | |
# repository: 'devwithkrishna/azure-terraform-modules' | |
# token: ${{ env.GH_APP_TOKEN }} | |
# - name: text | |
# run: | | |
# ls -la | |
# cat txt.txt | |
- name: setup for tfmodule | |
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=storage-account init | |
- name: Terraform Plan | |
run: terraform -chdir=storage-account plan -out=planfile ${{ github.event.inputs.action == 'destroy' && '-destroy' || '' }} | |
- name: Terraform Apply | |
if: ${{ github.event.inputs.action == 'apply' }} | |
run: terraform -chdir=storage-account apply -auto-approve planfile | |
- name: Terraform Destroy | |
if: ${{ github.event.inputs.action == 'destroy' }} | |
run: terraform -chdir=storage-account apply -auto-approve planfile |