Last active
May 13, 2024 19:49
-
-
Save geekzter/77e29271d2677db2d854dadbdf25a77c to your computer and use it in GitHub Desktop.
Terraform authentication re-uses GitHub Azure Action credentials
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: 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, here is the same for bash. In case, someone needs it. It requires jq to be installed. https://gist.github.com/tp199314/c5a37eb3962b48a69d8275a41c6c7adb