Specify service principal credentials in environment variables
-
Edit the
~/.bashrcfile by adding the following environment variables.BashCopy
bash export ARM_SUBSCRIPTION_ID="<azure_subscription_id>" export ARM_TENANT_ID="<azure_subscription_tenant_id>" export ARM_CLIENT_ID="<service_principal_appid>" export ARM_CLIENT_SECRET="<service_principal_password>"plaintext -
To execute the
~/.bashrcscript, runsource ~/.bashrc(or its abbreviated equivalent .~/.bashrc). You can also exit and reopen Cloud Shell for the script to run automatically.BashCopy
bash . ~/.bashrcplaintext -
Once the environment variables have been set, you can verify their values as follows:
BashCopy
bash printenv | grep ^ARM*plaintext
Using PowerShell:
-
To set the environment variables within a specific PowerShell session, use the following code. Replace the placeholders with the appropriate values for your environment.
PowerShellCopy
powershell $env:ARM_CLIENT_ID="<service_principal_app_id>" $env:ARM_SUBSCRIPTION_ID="<azure_subscription_id>" $env:ARM_TENANT_ID="<azure_subscription_tenant_id>" $env:ARM_CLIENT_SECRET="<service_principal_password>"plaintext -
Run the following PowerShell command to verify the Azure environment variables:
PowerShellCopy
powershell gci env:ARM_*plaintext -
To set the environment variables for every PowerShell session, create a PowerShell profile and set the environment variables within your profile.