terraform modules auth using github app installation token #30
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: githubofkrishnadhas/github-access-using-githubapp@bugfix/owner | |
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@bugfix/owner | |
#id: app-token1 | |
#with: | |
# github_app_id: ${{ secrets.TOKEN_GENERATOR_APPID }} | |
# github_app_private_key: ${{ secrets.TOKEN_GENERATOR_PRIVATE_KEY }} | |
- 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 | |
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=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 |