Terraform Professional (002): Dynamic Provider Credentials and Variable Files
Dynamic provider credentials are short-lived cloud credentials that HCP Terraform and Terraform Enterprise obtain for each run by exchanging a signed workload identity token, so no static keys are stored in workspaces. This lesson covers objectives 4c and 4d of the Terraform Infrastructure Engineer Professional exam: enabling and scoping those credentials across teams, projects and workspaces (trust conditions, plan/apply roles, multiple configurations, variable sets, Vault-backed credentials), and predicting which value wins when variables are overridden with .tfvars and auto.tfvars files, command-line flags and HCP Terraform variables.
On this page10 sections
- How dynamic provider credentials work
- Enabling AWS dynamic credentials in a workspace
- Trust conditions and workload identity token claims
- Separate identities for plan and apply
- Azure and Google Cloud differences
- Multiple credential configurations in one workspace
- Managing credentials across teams, projects and workspaces
- Vault-backed dynamic credentials
- Overriding variables with .tfvars and auto.tfvars files
- Variable precedence in HCP Terraform and Terraform Enterprise
- Enable AWS, Azure and Google Cloud dynamic credentials with the right environment variables and diagnose a run that never attempted authentication versus one the trust policy denied
- Write trust conditions on the workload identity token’s sub and aud claims that admit exactly one workspace, a whole project or one team’s workspaces, and keep them valid through renames and audience changes
- Separate plan and apply identities and predict which role each phase assumes from the RUN, PLAN and APPLY variables
- Configure several credential sets in one workspace with tags, TFC_DEFAULT_ values and the tfc_<provider>_dynamic_credentials variable
- Deliver credentials across teams, projects and workspaces with variable sets and workspace overrides, and choose Vault-backed credentials when Vault should issue them
- Predict the winning value across terraform.tfvars, *.auto.tfvars, -var and -var-file, knowing that maps and objects are replaced whole
- Apply HCP Terraform’s variable precedence to VCS-driven and CLI-driven runs, priority variable sets and Terraform Enterprise
How dynamic provider credentials work
Dynamic provider credentials let an HCP Terraform or Terraform Enterprise run authenticate to a cloud with short-lived credentials created for that run, instead of static keys stored as workspace variables. Nothing long-lived is stored, so there is nothing to rotate or leak.
The flow has four steps:
- For each run phase (plan and apply), HCP Terraform signs a workload identity token — an OIDC-compliant JWT — describing the run: which organization, project and workspace it belongs to and which phase it is in.
- The cloud (or Vault) has been configured to trust HCP Terraform as an identity provider: an IAM OIDC identity provider in AWS, a federated identity credential on a Microsoft Entra ID app registration, a workload identity pool provider in Google Cloud, or a JWT auth method in Vault. The issuer is the HCP Terraform address,
https://app.terraform.io, or your Terraform Enterprise hostname. - The trust configuration checks the token's claims — at minimum the audience and the organization, usually also the project, workspace and phase — and, if they match, exchanges the token for temporary credentials.
- HCP Terraform hands those credentials to the provider outside your configuration (for AWS, as a generated shared config file), so the provider block needs no authentication arguments.
Two places therefore have to agree for a run to authenticate: the workspace variables that tell HCP Terraform to request a token and which identity to use, and the trust conditions in the cloud that decide which tokens may use that identity. Most troubleshooting comes down to telling these apart. If no token exchange was even attempted (for AWS, no AssumeRoleWithWebIdentity call in CloudTrail), the workspace side is wrong; if the exchange was attempted and denied, the trust side is wrong.
Native integrations include AWS, Microsoft Azure, Google Cloud, Vault, and Kubernetes and Helm, plus Vault-backed variants for AWS, Azure and Google Cloud (covered below). Securing the pipeline identities that run outside HCP Terraform, such as a GitHub Actions role, is part of the security domain; this lesson covers the HCP Terraform side.
Enabling AWS dynamic credentials in a workspace
AWS dynamic credentials are enabled with two environment variables on the workspace: TFC_AWS_PROVIDER_AUTH=true and TFC_AWS_RUN_ROLE_ARN set to the IAM role to assume. The role must trust an IAM OIDC identity provider for the HCP Terraform address whose audience list contains the token's audience (aws.workload.identity by default).
| Variable | Purpose |
|---|---|
TFC_AWS_PROVIDER_AUTH | The switch. HCP Terraform attempts AWS authentication only when it is present and true. |
TFC_AWS_RUN_ROLE_ARN | Role assumed for both plan and apply, unless a phase-specific role is set. |
TFC_AWS_PLAN_ROLE_ARN / TFC_AWS_APPLY_ROLE_ARN | Optional per-phase roles; each falls back to the run role. |
TFC_AWS_WORKLOAD_IDENTITY_AUDIENCE | Optional custom audience for the token (default aws.workload.identity). |
Three details trip up migrations:
- Category. These settings are read from the run's environment, so they must be in the environment variable category. Entered as Terraform variables, they become values for input variables and HCP Terraform ignores them for authentication. The category is the only setting that decides how HCP Terraform reads the variable.
- HCP Terraform's names, not the AWS SDK's. HCP Terraform creates and places the token itself. SDK variables such as
AWS_ROLE_ARNorAWS_WEB_IDENTITY_TOKEN_FILEare not how you configure it, and noassume_role_with_web_identityblock is needed in the provider. - Leftover static keys win. The AWS provider looks for credentials in a fixed order: provider arguments, then environment variables such as
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, then shared config and credentials files. Dynamic credentials arrive as a shared config file, so old access-key variables still on the workspace (or in a variable set) silently take precedence, and CloudTrail shows the old IAM user instead of the role. Delete them; HashiCorp warns against combining other authentication methods with dynamic credentials.
With a single configuration the provider block can be as small as provider "aws" { region = "us-east-2" }; HCP Terraform supplies the credentials implicitly.
Trust conditions and workload identity token claims
The trust policy decides which runs may use a role, and it does so by matching claims in the workload identity token. The most important claim is sub, which always has this fixed order:
organization:<ORG>:project:<PROJECT>:workspace:<WORKSPACE>:run_phase:<plan|apply>
The token also carries aud (the audience), the issuer, and individual claims such as terraform_organization_name, terraform_project_name, terraform_workspace_name and terraform_run_phase, plus ID claims (terraform_organization_id, terraform_project_id, terraform_workspace_id). An AWS trust policy for one workspace, both phases, looks like this:
"Condition": {
"StringEquals": { "app.terraform.io:aud": "aws.workload.identity" },
"StringLike": { "app.terraform.io:sub":
"organization:example-org:project:billing:workspace:billing-api:run_phase:*" }
}
- StringLike vs StringEquals. Only
StringLikeevaluates*as a wildcard. UnderStringEqualsthe asterisk is literal, so a pattern matches no real token and every run is refused. - Scope by wildcarding segments. Wildcard only the phase to admit one workspace; wildcard the workspace segment (
workspace:*) to admit every current and future workspace in a project; use a name pattern (workspace:dns-*) to separate teams that share a project. HashiCorp's guidance is to always check at least the audience and the organization name — a project or workspace name alone is not unique across organizations. - The audience lives in
aud, the path lives insub. Neither appears in the other.
When the claims change
Tokens are built from the names that exist at run time. Renaming an organization, project or workspace, or moving a workspace to another project, changes sub immediately, and every trust condition that matched the old name starts denying the exchange (an AccessDenied on sts:AssumeRoleWithWebIdentity). The issuer and audience do not change with a rename. Plan renames and moves together with trust-policy updates.
The ID claims are the durable alternative: an organization, project or workspace keeps its ID when renamed. A trust system that can match custom claims (a Google Cloud attribute mapping and condition, or a Vault JWT role's bound claims) can pin IDs instead of names and survive renames. An AWS IAM trust policy can only test the standard OIDC condition keys such as sub and aud, so on AWS the name-based sub remains what you match.
A custom audience (TFC_AWS_WORKLOAD_IDENTITY_AUDIENCE) changes the token's aud, which AWS checks in two places: STS accepts the token only if its aud is in the IAM OIDC identity provider's audience list, and the role's trust policy compares aud in its condition. Both must be updated to the new value.
Tokens for tools without a native integration
For a custom workflow such as an agent hook that must authenticate to an internal system, set TFC_WORKLOAD_IDENTITY_AUDIENCE to the audience that system expects. HCP Terraform then generates a token with that audience and exposes it to the run as TFC_WORKLOAD_IDENTITY_TOKEN. Each integration-specific audience variable shapes only the token for that integration.
Separate identities for plan and apply
Separate plan and apply identities let a workspace plan with a read-only role and apply with a write role. HCP Terraform issues a different token for each phase (run_phase:plan and run_phase:apply), so each role can trust only its own phase.
The phase-specific variables always win, and each falls back to the run role only when it is missing:
| Variables set | Plan uses | Apply uses |
|---|---|---|
| RUN only | RUN | RUN |
| PLAN + APPLY | PLAN | APPLY |
| RUN + PLAN | PLAN | RUN (fallback) |
| RUN + APPLY | RUN (fallback) | APPLY |
| RUN + PLAN + APPLY | PLAN | APPLY (RUN unused) |
| PLAN only | PLAN | none — applies cannot authenticate |
The rule behind the table: a phase-specific value is read first and the run role is consulted only for a phase that has none. Different combinations can therefore produce the same outcome.
Each role's trust policy must match the phase it serves. A frequent failure is creating both trust policies from one template: if the apply role still trusts run_phase:plan, plans succeed and every apply is denied. The fix is on the apply role's trust condition, not in the variable names. Naming matters: the phase is written inside the variable name (TFC_AWS_PLAN_ROLE_ARN), while anything appended at the end is a tag that defines a separate configuration (see the multiple-configurations section).
Azure and Google Cloud differences
Azure and Google Cloud follow the same token-and-trust model as AWS, with their own variable names and one important difference in how matching works.
| Microsoft Azure | Google Cloud | |
|---|---|---|
| Trust object | Federated identity credential on an app registration or managed identity | Workload identity pool + provider, attribute condition |
| Matching | Standard federated credential subject is a direct string match — no wildcards | CEL condition, e.g. assertion.sub.startsWith("organization:example-org:project:research:") |
| Consequence | One federated credential per workspace per phase (plan and apply) | A prefix can admit every workspace in a project, including future ones |
| Switch + identity | TFC_AZURE_PROVIDER_AUTH=true, TFC_AZURE_RUN_CLIENT_ID (PLAN/APPLY variants) | TFC_GCP_PROVIDER_AUTH=true, TFC_GCP_RUN_SERVICE_ACCOUNT_EMAIL (PLAN/APPLY variants) |
| Other required | Provider uses OIDC; HashiCorp recommends use_cli = false for clearer errors | TFC_GCP_PROJECT_NUMBER (the numeric project number, not the project ID), TFC_GCP_WORKLOAD_POOL_ID, TFC_GCP_WORKLOAD_PROVIDER_ID |
On Azure, an app registration with only a run_phase:plan credential lets plans through and refuses applies; the fix is a second credential with a run_phase:apply subject. Wildcards are not evaluated in a standard credential's subject. (Entra's newer flexible federated identity credentials are a separate feature; the standard credential is exact-match.)
On Google Cloud, write conditions on assertion.sub so the organization is pinned along with the project; a condition on terraform_project_name alone would admit a same-named project in another organization. TFC_GCP_PRINCIPAL_TYPE defaults to service_account, which is what a run service account email needs. Remove any GOOGLE_CREDENTIALS or GOOGLE_APPLICATION_CREDENTIALS variable left from a key-file setup — HashiCorp warns they conflict with dynamic credentials.
Multiple credential configurations in one workspace
One workspace can hold several configurations for the same provider — for example a default AWS account plus a central logging account used by an aliased provider. Each extra configuration is defined by appending a tag to the variable names, and each must be switched on with its own variable:
TFC_AWS_PROVIDER_AUTH=true # default (untagged) configuration
TFC_AWS_RUN_ROLE_ARN=arn:aws:iam::123456789012:role/app
TFC_AWS_PROVIDER_AUTH_LOGGING=true # tagged configuration "LOGGING"
TFC_AWS_RUN_ROLE_ARN_LOGGING=arn:aws:iam::210987654321:role/logs
HCP Terraform passes the credentials for every configuration in one root-module variable that you declare, tfc_aws_dynamic_credentials: default holds the untagged configuration and aliases is a map keyed by tag. For AWS each entry has a shared_config_file:
variable "tfc_aws_dynamic_credentials" {
type = object({
default = object({ shared_config_file = string })
aliases = map(object({ shared_config_file = string }))
})
}
provider "aws" {
shared_config_files = [var.tfc_aws_dynamic_credentials.default.shared_config_file]
}
provider "aws" {
alias = "logs"
shared_config_files = [var.tfc_aws_dynamic_credentials.aliases["LOGGING"].shared_config_file]
}
- Map every provider by hand. With one configuration, credentials reach the provider implicitly. Once you add a second, HashiCorp requires mapping authentication for all providers, including the unaliased default one — otherwise the default provider stops authenticating.
- The key is the variable tag, not the provider alias. HCP Terraform never sees the
aliaslabel in your HCL;aliases["LOGGING"]comes from the_LOGGINGsuffix, even though the provider alias islogs. - Per-provider object shapes differ. Azure's object carries
client_idandoidc_token_file_path(intfc_azure_dynamic_credentials); Google Cloud's carries credentials for the provider. Each provider has its owntfc_<provider>_dynamic_credentialsvariable.
Shared defaults with TFC_DEFAULT_
Most dynamic-credential variables have a TFC_DEFAULT_ counterpart (for example TFC_DEFAULT_AWS_RUN_ROLE_ARN) whose value applies to every configuration that does not set its own. An explicit value — tagged or untagged — always wins over the default. The exception is the switch: TFC_AWS_PROVIDER_AUTH (and its Azure/GCP/Vault equivalents) has no default form, so TFC_DEFAULT_AWS_PROVIDER_AUTH enables nothing. Every tagged configuration needs its own TFC_AWS_PROVIDER_AUTH_<TAG>=true, and the untagged switch enables only the default configuration.
Managing credentials across teams, projects and workspaces
Credentials are delivered across many workspaces with variable sets holding the TFC_ environment variables, matched on the cloud side by trust conditions with the same scope. Getting the two halves to line up is the core of objective 4c.
| Requirement | Delivery in HCP Terraform | Trust condition |
|---|---|---|
| Every current and future workspace in one project | Variable set scoped to the project | …:project:analytics:workspace:*:run_phase:* |
| Two teams sharing one project | A variable set per team, applied to that team's workspaces only | Workspace name pattern, e.g. workspace:dns-* |
| One workspace needs a different role | A workspace variable with the same key | The other role trusts that workspace |
| Organization-wide default | Global variable set | Organization-level pattern, still checking aud |
Which value a run receives follows HCP Terraform's precedence:
- Workspace variables override variable sets with the same key — the least-effort way to give one workspace a different role while it stays in the project.
- Among non-priority sets, the more specific scope wins: sets applied to the workspace and project-scoped sets outrank global sets. Lexical order of set names only breaks ties between sets at the same rank.
- Ownership also counts. Variable sets can be owned by the organization or by a project, and HashiCorp's full list ranks them by owner as well as scope — for example a project-owned set scoped to the project ranks above an organization-owned set applied to the workspace. Check the current precedence table when sets of both owners overlap.
- A priority variable set overrides everything at more specific scopes, including workspace variables and command-line values; it is a guardrail for values that must not be changed, not a tool for per-workspace exceptions.
- A
TFC_DEFAULT_value never overrides an explicit value from a set; it only fills gaps.
Scoping traps to avoid: a global set reaches every workspace in the organization (too wide for a project requirement); per-workspace variables do not reach workspaces created later; and moving a workspace to another project to pick up a different set also changes the project segment of its sub claim, so the role's trust may stop matching. A role ARN is not a secret: the trust policy, not the variable, controls who can use the role.
Vault-backed dynamic credentials
Vault-backed dynamic credentials route authentication through Vault: the run authenticates to Vault with its workload identity token, and Vault's AWS, Azure or Google Cloud secrets engine issues the cloud credentials. The cloud never validates an HCP Terraform token; Vault does.
Reasons to choose it over direct dynamic credentials: credential issuing and auditing stay centralised in Vault; and the cloud does not need to reach HCP Terraform's OIDC metadata, which matters for a Terraform Enterprise instance on a private network that the cloud provider cannot reach.
Setup is layered:
- Vault dynamic credentials first — a JWT auth method and role in Vault trusting HCP Terraform's tokens, plus
TFC_VAULT_PROVIDER_AUTH=true,TFC_VAULT_ADDRandTFC_VAULT_RUN_ROLE(andTFC_VAULT_NAMESPACEif used). - Then the Vault-backed variables, e.g. for AWS:
TFC_VAULT_BACKED_AWS_AUTH=true,TFC_VAULT_BACKED_AWS_AUTH_TYPE(iam_user,assumed_roleorfederation_token),TFC_VAULT_BACKED_AWS_RUN_VAULT_ROLE(the role in the secrets engine) and, optionally,TFC_VAULT_BACKED_AWS_MOUNT_PATH, which defaults toaws. - For
assumed_role, alsoTFC_VAULT_BACKED_AWS_RUN_ROLE_ARN— the AWS role Vault should assume — unless both thePLAN_ROLE_ARNandAPPLY_ROLE_ARNvariants are set. It matters especially when the Vault role lists more than one role ARN.
The direct TFC_AWS_PROVIDER_AUTH/TFC_AWS_RUN_ROLE_ARN variables belong to the other integration and are not read here. When migrating from code that reads keys with a data source such as vault_aws_access_credentials and passes them to access_key/secret_key, HashiCorp requires removing that secrets-engine usage and the provider's own authentication arguments; data source results are written to state even when values are marked sensitive. The aim is that no Vault token or cloud key is stored in the workspace at all: the workload identity token is the only credential the run starts with.
Overriding variables with .tfvars and auto.tfvars files
Terraform CLI resolves an input variable from several sources and keeps the last value found, in this order from lowest to highest:
- The
defaultin the variable block (used only when nothing sets it) - Environment variables
TF_VAR_<name> terraform.tfvarsterraform.tfvars.json*.auto.tfvarsand*.auto.tfvars.json, together, in lexical order of file name-varand-var-fileoptions, in the order given on the command line
What this means in practice:
- Command-line position decides, not flag type.
-varhas no rank over-var-file. Whichever option that sets the variable comes later on the line wins, whether it is a flag or a file:-var="node_pool_size=4" -var-file=region-b.tfvarstakes the file's value, and swapping their order takes the flag's. Layering-var-file=common.tfvars -var-file=prod.tfvarsis the usual pipeline pattern for environment overrides. - Among auto files, only the name matters.
net.auto.tfvarsbeatsbase-config.auto.tfvars.jsonbecause "n" sorts after "b"; the.jsonform only ranksterraform.tfvars.jsonaboveterraform.tfvars. - Auto-loading is root-directory only.
terraform.tfvars,terraform.tfvars.jsonand*.auto.tfvars(.json)are read from the root module's working directory; files in subdirectories are never auto-loaded. A file without.auto(such asprod.tfvars) loads only when named with-var-file. A pipeline that needs a per-run override can write a generatedci-values.auto.tfvarsinto the root directory or pass a generated file with-var-file. TF_VAR_cannot beat a file. Environment variables rank below every variable file, so exporting one does not override a committedterraform.tfvars.- No errors for layering. The same variable in different files is resolved by precedence without a warning; assigning it twice inside one file is an error.
Maps and objects are replaced whole
Since Terraform 0.12, map and object values behave like any other value: a higher-precedence source replaces the whole value; nothing is merged across files. If terraform.tfvars sets labels = { team = "data" } and region.auto.tfvars sets labels = { tier = "gold" }, the result has only tier. For an object type with optional(type, default) attributes, the winning value is taken whole and then the declared defaults fill the attributes it omits — they never pull values from the losing file. To layer shared and per-environment keys, declare two variables and combine them in configuration:
locals {
labels = merge(var.common_labels, var.env_labels)
}
Basic variable declaration and type handling are covered in the variables lesson of the configuration-design domain.
Variable precedence in HCP Terraform and Terraform Enterprise
In HCP Terraform, values from the workspace and from variable sets join the file and command-line sources. HashiCorp's precedence, from highest to lowest:
- Priority variable sets (they override same-key values at every more specific scope, including command-line flags)
- Command-line
-var/-var-filevalues (CLI-driven runs only) - Local
TF_VAR_environment variables (CLI-driven runs only) - Workspace-specific variables
- Variable sets applied to the workspace, then project-scoped sets, then global sets (ranked also by whether the organization or a project owns the set)
*.auto.tfvarsfiles in the configurationterraform.tfvarsin the configuration
Consequences worth knowing:
- Workspace variables beat committed files. A workspace variable overrides a value in the repository's
*.auto.tfvarsorterraform.tfvars; edit time plays no part. - VCS-driven workspaces need per-environment values in workspace variables. Nobody passes
-var-filein a VCS-driven run, so a committedprod.tfvarsis never read; committed*.auto.tfvarsfiles load in every workspace that uses the branch, sodev.auto.tfvarsandqa.auto.tfvarswould both load and lexical order would pick one for both environments. - A priority set beats even
-var. Only changing the configuration itself bypasses it, which is why HashiCorp pairs priority sets with policy checks where that matters. Priority sets in project design are covered in the workspaces and environments lesson. - JSON variable files. HashiCorp's HCP Terraform list names
*.auto.tfvarsandterraform.tfvars; the JSON forms follow the same file rules as the CLI. - Terraform Enterprise and
terraform.tfvars. HashiCorp's variables documentation currently states that Terraform Enterprise ignoresterraform.tfvars, while HCP Terraform reads it. A value that must hold on both products belongs in a*.auto.tfvarsfile or a workspace variable; otherwise a migrated workspace silently falls back to the variable's default.
Tip. Expect production scenarios built around a stated constraint — least effort, no long-lived secrets, every future workspace in a project but none outside it, teams sharing a project, a workspace that must stay where it is — with options that are all real variables, claims or files. Items give a set of TFC_ environment variables or a trust condition and ask which role each run phase assumes, why plans work but applies fail, what broke after a rename, move or audience change, or which provider argument maps a tagged configuration. Azure, Google Cloud and Vault-backed items test the integration-specific rules. Variable-file items show command lines, file listings or HCL and ask which value wins, including JSON and auto files, subdirectories, map and object replacement, VCS-driven versus CLI-driven runs, priority variable sets and Terraform Enterprise. Several are Select TWO, pairing the HCP Terraform side with the cloud side.
- AWS dynamic credentials need TFC_AWS_PROVIDER_AUTH=true and a role ARN, set as environment variables; no STS call at all means the switch is missing, a denied call means the trust policy is wrong
- The sub claim is organization:ORG:project:PROJECT:workspace:WORKSPACE:run_phase:PHASE; wildcard it only with StringLike and always check aud and the organization
- Renaming or moving an organization, project or workspace changes sub (the ID claims do not); a custom AWS audience must be added to both the OIDC provider and the trust policy
- PLAN and APPLY role variables beat the RUN role, which is only a fallback; each role must trust its own run phase
- Azure federated credentials match exactly (one per workspace per phase); Google Cloud uses assertion.sub conditions and the numeric project number
- Tagged configurations need their own PROVIDER_AUTH_<TAG>=true, live under aliases["<TAG>"], and force you to map every provider, the default one included; TFC_DEFAULT_ values only fill gaps
- Workspace variables override variable sets; more specific sets beat global sets; priority sets beat everything, including -var
- Vault-backed credentials need Vault dynamic credentials first, then TFC_VAULT_BACKED_ variables, with secrets-engine reads removed from code
- On the command line, the last -var or -var-file wins; auto files load from the root directory only, in name order, above terraform.tfvars(.json) and TF_VAR_
- Maps and objects are never merged across variable sources; combine separate variables with merge() instead
Frequently asked questions
What are dynamic provider credentials in HCP Terraform?
Dynamic provider credentials are temporary cloud credentials that HCP Terraform or Terraform Enterprise obtains for each plan and apply. The run receives a signed workload identity token, the cloud (or Vault) checks the token’s claims against a trust configuration, and returns short-lived credentials. No static access keys are stored in the workspace, so nothing long-lived needs rotating.
Which variables enable AWS dynamic credentials in an HCP Terraform workspace?
Set TFC_AWS_PROVIDER_AUTH=true and TFC_AWS_RUN_ROLE_ARN to the IAM role as environment variables, either on the workspace or in a variable set. Optional TFC_AWS_PLAN_ROLE_ARN and TFC_AWS_APPLY_ROLE_ARN give each phase its own role and fall back to the run role. The provider block needs no authentication arguments, and leftover AWS access-key environment variables should be deleted because they take precedence.
What does the sub claim of an HCP Terraform workload identity token contain?
The sub claim has the fixed form organization:ORG:project:PROJECT:workspace:WORKSPACE:run_phase:PHASE, built from the names at run time. Trust policies match it, usually with a StringLike wildcard for the run phase or workspace. Because it contains names, renaming or moving an organization, project or workspace changes it.
Why do my Azure applies fail while plans succeed with dynamic credentials?
A standard Azure federated identity credential matches the token subject exactly, and plan and apply tokens have different subjects. A workspace therefore needs two federated credentials, one ending in run_phase:plan and one ending in run_phase:apply. A wildcard subject does not work because the asterisk is taken literally.
How do I use two AWS accounts with dynamic credentials in one workspace?
Add a tagged configuration by suffixing the variables, for example TFC_AWS_PROVIDER_AUTH_LOGGING=true and TFC_AWS_RUN_ROLE_ARN_LOGGING. Declare the tfc_aws_dynamic_credentials variable in the root module and set shared_config_files on every aws provider: the default provider uses .default.shared_config_file and the aliased one uses .aliases["LOGGING"].shared_config_file, keyed by the tag rather than the provider alias.
Does -var override -var-file in Terraform?
No. Terraform processes -var and -var-file options together in the order they appear on the command line, and the last one that sets a variable wins. Both rank above *.auto.tfvars, terraform.tfvars.json, terraform.tfvars and TF_VAR_ environment variables.
Does Terraform merge map variables from different tfvars files?
No. Since Terraform 0.12, a map or object value from a higher-precedence source replaces the lower one entirely; keys are not merged across files. To combine shared and environment-specific keys, declare two variables and join them with merge() in a local value.
Which wins in HCP Terraform: a workspace variable or a value in an auto.tfvars file?
The workspace variable wins. HCP Terraform ranks workspace variables above variable sets, and both above *.auto.tfvars and terraform.tfvars files in the configuration. Only command-line values and local TF_VAR_ variables in CLI-driven runs, and priority variable sets, rank higher.
Source
This lesson covers the "CI/CD and automation workflows" domain of the official Terraform Pro 002 exam guide. Vendors revise their guides — check the source for the current version.
Sign up free to mark lessons complete, bookmark topics and track your exam readiness.