Service Principal in block
The Azure provider block defines syntax that allows you to specify your Azure subscription's authentication information.
To authenticate Terraform to Azure in a secure, automated, and cloud-agnostic way, use a Service Principal and reference its credentials in your provider block. This is the recommended approach for CI/CD pipelines and IaC workflows.
Step-by-Step Example
Store your Service Principal credentials securely (e.g., as environment variables or in your CI/CD secret manager):
ARM_SUBSCRIPTION_ID
ARM_TENANT_ID
ARM_CLIENT_ID
ARM_CLIENT_SECRET
Reference these variables in your Terraform provider block:
Set the variables using environment variables or a
terraform.tfvars
file:
Or in terraform.tfvars
(not recommended for production):
Real-Life DevOps Example: GitHub Actions
Best Practices
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
References
Tip: For passwordless authentication in CI/CD, consider using OIDC with GitHub Actions or Azure Pipelines.
Add to SUMMARY.md
Last updated