Skip to content

Instantly share code, notes, and snippets.

@geekzter
Last active May 13, 2024 19:49
Show Gist options
  • Save geekzter/77e29271d2677db2d854dadbdf25a77c to your computer and use it in GitHub Desktop.
Save geekzter/77e29271d2677db2d854dadbdf25a77c to your computer and use it in GitHub Desktop.
Terraform authentication re-uses GitHub Azure Action credentials
- name: Get Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Get Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 'latest'
terraform_wrapper: false
- name: Prepare environment variables
env:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
run: |
# Parse Azure secret into Terraform variables
$servicePrincipal = ($env:AZURE_CREDENTIALS | ConvertFrom-Json)
$env:ARM_CLIENT_ID = $servicePrincipal.clientId
$env:ARM_CLIENT_SECRET = $servicePrincipal.clientSecret
$env:ARM_SUBSCRIPTION_ID = $servicePrincipal.subscriptionId
$env:ARM_TENANT_ID = $servicePrincipal.tenantId
# Save environment variable setup for subsequent steps
Get-ChildItem -Path Env: -Recurse -Include ARM_*,TF_VAR_* | ForEach-Object {Write-Output "$($_.Name)=$($_.Value)"} >> $env:GITHUB_ENV
shell: pwsh
- name: Terraform Init
run: terraform init
shell: pwsh
@tp199314
Copy link

Hi, here is the same for bash. In case, someone needs it. It requires jq to be installed. https://gist.github.com/tp199314/c5a37eb3962b48a69d8275a41c6c7adb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment