GitHub Action Workflow hashicorp/setup-terraform@v2 ERROR: Please run ‘az login’ to setup accountGitHub Action Workflow hashicorp/setup-terraform@v2 error:

A quick blog post on assisting with a couple of errors I came across when using workflow hashicorp/setup-terraform@v2 – this also remediates hashicorp/setup-terraform@v1 also.

Two errors found, relating to the same fix:

First error:

Error: building AzureRM Client: obtain subscription() from Azure CLI: parsing json result from the Azure CLI: waiting for the Azure CLI: exit status 1: ERROR: Please run 'az login' to setup account.

Second error:

Error: Error building ARM Config: obtain subscription() from Azure CLI: parsing json result from the Azure CLI: waiting for the Azure CLI: exit status 1: ERROR: Please run 'az login' to setup account.

The fix

As detailed here in standard terraform usage is:

The issue is resolved after setting the environment variables -> ARM_SUBSCRIPTION_ID, ARM_TENANT_ID, ARM_CLIENT_ID and ARM_CLIENT_SECRET.

Within my GitHub action, here is my remediation example showing a successful run of Terraform init:

name: 'Terraform'

on:
  push:
    branches:
    - main
  pull_request:

jobs:
  terraform:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v1

      - name: Terraform Init
        run: |
          export ARM_CLIENT_ID=$ARM_CLIENT_ID
          export ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET
          export ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID
          export ARM_TENANT_ID=$ARM_TENANT_ID

          terraform init
        env:
          ARM_CLIENT_ID: ${{secrets.ARM_CLIENT_ID}}
          ARM_CLIENT_SECRET: ${{secrets.ARM_CLIENT_SECRET}}
          ARM_SUBSCRIPTION_ID: ${{secrets.ARM_SUBSCRIPTION_ID}}
          ARM_TENANT_ID: ${{secrets.ARM_TENANT_ID}}

Notice the highlighted above? I have used export to resolve the error, exporting in the required values of ARM_CLIENT_ID , ARM_CLIENT_SECRET , ARM_SUBSCRIPTION_ID , ARM_TENANT_ID

with a successful run as shown below.

A quick blog post to assist you in relation to the two errors noted above. Let me know if you found this useful!

Leave a Reply

Discover more from Thomas Thornton Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Thomas Thornton Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading