Service Principal in env
Once you create a service principal, you can specify its credentials to Terraform via environment variables.
Last updated
Once you create a service principal, you can specify its credentials to Terraform via environment variables.
Last updated
To securely authenticate Terraform to Azure, export your Service Principal credentials as environment variables. This is the recommended approach for automation, CI/CD, and cross-platform workflows (Linux, macOS, WSL, PowerShell).
Add the following to your ~/.bashrc
or ~/.zshrc
:
Reload your shell configuration:
Verify the environment variables:
Set variables for the current session:
Verify the variables:
Persist variables for all sessions: Add the export lines to your .
Store your Service Principal credentials as GitHub Actions secrets, then use them in your workflow:
Never hardcode credentials in your Terraform code or repository
Use environment variables or secret managers for sensitive values
Rotate Service Principal credentials regularly
Grant only the minimum RBAC permissions needed
Tip: For passwordless authentication in CI/CD, consider using OIDC with GitHub Actions or Azure Pipelines.