Join our Newsletter — 33% off our NHI Course
Home› Guides› How to fix Terraform cloud provider authentication errors…
Guide Secrets Management

How to fix Terraform cloud provider authentication errors without hard-coding credentials: AWS, Azure and Google Cloud

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 14 min read
On this page

A Terraform provider authentication error almost always means the provider could not find a credential source it expected, and the safe fix is to supply a short-lived identity through that source rather than paste an access key into the configuration. The AWS provider's "No valid credential sources found" error is the best known example, and the quickest answer people reach for is to add access_key and secret_key to the provider block or a .tfvars file. The run then succeeds, and a long-lived cloud credential is now in a file that will probably be committed, copied into CI variables and shared between workspaces.

This guide explains how the AWS, Azure and Google Cloud providers look for credentials, how to read the error, and how to fix it on a workstation, in CI and in HCP Terraform without static secrets. It is a troubleshooting how-to. For the wider design of credentials across state, plans and pipelines, see the Terraform and IaC Pipeline Credential Security Guide.

The three providers are covered in alphabetical order by cloud, each in its own section.

Key takeaways

  • Each provider searches a fixed chain of credential sources. An authentication error means every source in that chain was empty, expired or wrong. Find out which source should have worked before changing anything.
  • HashiCorp's AWS provider documentation states that hard-coded credentials are not recommended in any Terraform configuration, because they risk leakage if the file is committed.
  • On workstations, use the cloud's own CLI sign-in: AWS profiles or SSO, the Azure CLI, or Google Cloud Application Default Credentials.
  • In CI, use OIDC federation: assume_role_with_web_identity for AWS, use_oidc for Azure, and Workload Identity Federation credential configuration files for Google Cloud.
  • In HCP Terraform, use dynamic provider credentials, which issue fresh temporary credentials for each plan and apply and discard them when the run ends.
  • A credential that "works" may still be the wrong identity. Check which principal Terraform actually used before granting it more access.

Why the error appears and why keys are the wrong fix

Terraform does not authenticate to clouds itself. Each provider plugin uses the cloud's SDK conventions to find credentials. When nothing is found, or a source is present but invalid, the provider fails during terraform plan or terraform init with a backend, before any resource is touched.

Typical triggers are:

  • a new CI runner with no cloud identity configured;
  • an expired SSO session or CLI login on a workstation;
  • a profile name in the provider block that does not exist on the machine running Terraform;
  • environment variables set in one shell but not in the one running Terraform;
  • a federation trust whose conditions do not match the CI token's claims;
  • a state backend that authenticates separately from the provider and has no credential of its own.

Hard-coding a key fixes all of these by bypassing the chain, which is why it is tempting. It also creates the exposure that state and repository scanning programmes then have to clean up. Keys pasted into provider blocks, variables files or terraform.tfvars end up in version control, in plan output shared for review, and in CI logs. MITRE ATT&CK T1552.001, Credentials In Files, describes exactly this kind of material being harvested. If a key has already been committed, treat it as exposed, revoke it and follow How to find secrets in Terraform state to check what else it reached.

A provider-neutral triage procedure

  1. Read the full error. Note which provider and, if present, which backend failed. Backend authentication errors happen during init; provider errors happen during plan.
  2. Establish where Terraform is running. Laptop, self-hosted runner, hosted CI, HCP Terraform remote run or agent. Each has a different expected credential source.
  3. Write down the expected source. For example, "AWS profile dev-admin via SSO" or "GitHub Actions OIDC to an Azure app registration". If nobody can say what it should be, that is the real problem.
  4. Check that source directly with the cloud's CLI in the same shell or job: aws sts get-caller-identity, az account show, or gcloud auth application-default print-access-token.
  5. Check for overrides. Provider block arguments and environment variables outrank files and metadata. A stale variable can hide a working identity.
  6. Fix the source, not the configuration. Refresh the login, correct the federation trust or attach the identity to the runner.
  7. Confirm the identity after the fix. Make sure Terraform is using the principal you intended, with only the access that workspace needs.

AWS provider

How it finds credentials

The AWS provider documentation lists the order of precedence: parameters in the provider block, environment variables, shared credentials files, shared config files, container credentials, then instance profile credentials. It notes that this matches the AWS CLI and the AWS SDK for Go v2. The supported sources are:

  • provider block access_key, secret_key and optional token, which HashiCorp states are not recommended in any configuration;
  • AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and optional AWS_SESSION_TOKEN environment variables;
  • shared files at ~/.aws/config and ~/.aws/credentials, with a named profile chosen through profile or AWS_PROFILE;
  • container credentials, covering ECS and CodeBuild task roles and EKS IAM Roles for Service Accounts;
  • EC2 instance profile credentials from the Instance Metadata Service, supporting IMDSv1 and IMDSv2;
  • an assume_role block, with role chaining;
  • assume_role_with_web_identity, using an OIDC or OAuth token, set in the block or through environment variables, with block values taking precedence;
  • a credential_process entry in a named profile.

Fixing "No valid credential sources found" without keys

This error means every source above came up empty. Fix it according to where Terraform runs:

  • Workstation. Use a named profile backed by AWS IAM Identity Center or another short-lived sign-in, refresh it, and select it with AWS_PROFILE. Check the profile name in the provider block matches a profile that exists locally. If you need a different role, use the assume_role block rather than a second set of keys.
  • Self-hosted runner on AWS. Attach an instance profile, ECS task role or EKS service account role to the runner. The provider will find it through container or instance metadata. Make sure no leftover AWS_ACCESS_KEY_ID variable outranks it.
  • Hosted CI. Use assume_role_with_web_identity, or the CI platform's OIDC action that sets the equivalent environment variables, against an IAM role whose trust policy pins the issuer, audience and subject. The GitHub Actions OIDC Federation Hardening Guide covers the trust policy conditions.
  • Something external that already produces credentials. Use credential_process in a profile so a helper fetches short-lived credentials at run time.

If the error persists after a login refresh, check for a mismatched region or a role that cannot be assumed. Assume role failures produce a different error from missing credentials, and the fix is the trust policy, not a key.

Azure provider (azurerm)

Supported methods

The azurerm provider documentation lists these methods:

  • Azure CLI, through use_cli (default true) or ARM_USE_CLI;
  • Managed identity, through use_msi or ARM_USE_MSI, with the endpoint usually detected automatically;
  • Service principal with a client certificate, through client_certificate or client_certificate_path;
  • Service principal with a client secret, through client_secret, ARM_CLIENT_SECRET, or client_secret_file_path;
  • OpenID Connect, through use_oidc or ARM_USE_OIDC, with a token from oidc_token, oidc_token_file_path, or, on some CI systems, oidc_request_token and oidc_request_url;
  • AKS Workload Identity, through use_aks_workload_identity, with client ID, tenant ID and token file detected from the environment.

The documentation recommends the Azure CLI for local runs and a service principal or managed identity for non-interactive runs such as CI.

Fixing authentication errors without client secrets

  • Workstation. Run az login, then confirm the right tenant and subscription with az account show. Many azurerm errors on laptops are an expired CLI session or the wrong default subscription, not missing credentials. Set ARM_SUBSCRIPTION_ID explicitly if needed.
  • Runner on Azure. Assign a managed identity to the VM or container and set ARM_USE_MSI=true with ARM_CLIENT_ID if it is user-assigned.
  • Runner on AKS. Use AKS Workload Identity with ARM_USE_AKS_WORKLOAD_IDENTITY. Our AKS Workload Identity Guide explains the federated credential setup.
  • Hosted CI. Use OIDC with a federated credential on the app registration or user-assigned managed identity, and set ARM_USE_OIDC=true, ARM_CLIENT_ID, ARM_TENANT_ID and ARM_SUBSCRIPTION_ID. These identifiers are not secrets.

One OIDC behaviour causes confusing failures in long runs: the provider documentation states that the OIDC token is only read once from oidc_token_file_path, and the provider does not re-read it when the access token expires. Very long applies may need to be split. Also, if you enable storage_use_azuread, the identity needs the relevant Storage data roles; the documentation notes these were added to new Contributor and Owner assignments but not backported to existing ones, which explains storage authorisation errors that appear after the move away from storage account keys.

If a client secret is genuinely unavoidable, prefer client_secret_file_path or an environment variable sourced from a secrets manager over a value in the configuration, and set a short expiry on the secret. A certificate is preferable to a secret where the platform supports it.

Google Cloud provider

How it finds credentials

The Google provider reference describes these options:

  • credentials, a path to or the contents of a service account key file, also read from GOOGLE_CREDENTIALS, GOOGLE_CLOUD_KEYFILE_JSON or GCLOUD_KEYFILE_JSON;
  • access_token or GOOGLE_OAUTH_ACCESS_TOKEN, a temporary OAuth 2.0 token that Terraform cannot renew and that expires, by default after one hour;
  • impersonate_service_account or GOOGLE_IMPERSONATE_SERVICE_ACCOUNT, which requires roles/iam.serviceAccountTokenCreator on the target account, with optional delegation chains;
  • external_credentials, which takes precedence over other settings and needs an STS audience, a service account email and an identity token from the external provider;
  • Application Default Credentials, used when no Terraform-specific credentials are set.

Fixing authentication errors without key files

  • Workstation. Run gcloud auth application-default login. The provider reference lists this as the workstation ADC method. Add impersonate_service_account in the provider block so plans run as a dedicated Terraform service account rather than as you. This keeps the identity consistent with CI while avoiding a key.
  • Runner on Google Cloud. Attach a service account to the VM or use Workload Identity Federation for GKE, and ensure the scope includes https://www.googleapis.com/auth/cloud-platform, as the reference notes.
  • Runner outside Google Cloud. Generate an external credential configuration file for Workload Identity Federation and point GOOGLE_APPLICATION_CREDENTIALS at it. The provider reference offers this or a key file; the configuration file holds no standalone secret, so choose it.

The reference also describes pasting a key file, with newlines removed, into a sensitive GOOGLE_CREDENTIALS workspace variable in HCP Terraform. That works, but it is a static key. Dynamic provider credentials, below, avoid it. For ADC errors that are not specific to Terraform, see our guide How to fix Google Cloud Application Default Credentials errors without downloading keys.

HCP Terraform and Terraform Enterprise runs

Remote runs do not see your laptop's CLI session, so a configuration that plans locally will often fail authentication on its first remote run. The fix that avoids workspace variables full of keys is dynamic provider credentials.

According to HashiCorp's documentation, you set up a trust relationship between the cloud platform and HCP Terraform. For each plan and apply, HCP Terraform generates an OIDC workload identity token containing information about the organisation, workspace or Stack, and run stage. The cloud platform verifies it with HCP Terraform's public signing key and returns temporary credentials, which are placed in the run environment and discarded when the run finishes. Supported platforms include AWS, Azure, Google Cloud, Kubernetes, HCP, Tencent Cloud and Vault, and Vault-backed dynamic credentials can issue temporary AWS, Google Cloud or Azure credentials through Vault secrets engines. Self-hosted agents must be v1.7.0 or newer.

Two design points matter. Use separate roles for plan and apply where the platform allows it, because plans only need read access; HashiCorp's examples include plan-specific variables such as TFC_AWS_PLAN_ROLE_ARN. And scope each cloud trust to specific organisation, project and workspace claims, not to the whole HCP Terraform issuer. For AWS, the step-by-step setup is in How to federate Terraform Cloud to AWS.

Backend authentication is separate

State backends such as S3, azurerm and gcs authenticate on their own during terraform init. A working provider identity does not mean the backend has one. Backend blocks also cannot use variables, which pushes people towards hard-coding keys there. Instead, give the backend the same short-lived source as the provider: an AWS profile or role, use_oidc or use_azuread_auth for Azure storage, or ADC for Google Cloud Storage. Supply any remaining settings through -backend-config at init time from the CI environment. HashiCorp's azurerm backend documentation warns that values passed with -backend-config are written to the .terraform directory and plan files, so pass only non-secret settings such as storage account, container and key this way. The Terraform State Security Guide covers locking down the backend itself.

Checking the identity you ended up with

After a fix, confirm which principal ran the plan. On AWS, CloudTrail records the role session name; on Azure, sign-in and activity logs show the service principal or managed identity; on Google Cloud, Cloud Audit Logs show the principal and any impersonation delegation. If the answer is a human administrator, a shared "terraform" key or an over-privileged default identity, the error has been fixed in the least safe way. Give each workspace or pipeline its own identity with only the access its resources need, and separate plan from apply.

Common failure patterns

  • Keys in the provider block "just for now". They are committed in the next push and copied into every fork.
  • Keys in terraform.tfvars. The file is excluded from one repository's ignore rules but not another's, or is shared over chat.
  • Stale environment variables outranking a good identity. An old AWS_ACCESS_KEY_ID or GOOGLE_CREDENTIALS on a runner overrides the instance role or federation file.
  • One administrator key for every workspace. A single compromised workspace exposes every environment.
  • Federation trusts with no subject condition. Any repository or workspace on the platform can assume the role.
  • Backend keys hard-coded because backends cannot use variables. The state file's credential becomes the weakest link.
  • Short-lived tokens used for long applies. A Google access_token or an Azure OIDC token read once expires mid-run, and the team switches to a key rather than splitting the run.

Practitioner checklist

  • Document the expected credential source for each place Terraform runs.
  • Remove access_key, secret_key, client_secret and inline credentials values from all configurations and variables files.
  • Use CLI sign-in, SSO profiles or ADC with impersonation on workstations.
  • Use OIDC federation for CI, with issuer, audience and subject conditions.
  • Enable dynamic provider credentials for HCP Terraform workspaces, with separate plan and apply roles.
  • Give backends a short-lived identity and pass settings with -backend-config.
  • Clear stale credential environment variables from runners and images.
  • Scan repositories, plan output and state for provider credentials, and revoke any found.
  • Verify the principal used in cloud audit logs after every authentication fix.

Standards and references

Related NHI Mgmt Group resources: Terraform and IaC Pipeline Credential Security Guide · How to federate Terraform Cloud to AWS · Terraform State Security Guide · GitHub Actions OIDC Federation Hardening Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.