Back to Terraform

Provider Aliases Across Accounts, Regions and Clouds

November 5, 2026 Wasil Zafar 28 min read

Pass provider configurations through modules and keep multi-provider ownership understandable

Table of Contents

  1. One Provider Type Can Have Multiple Configurations
  2. Pass the Right Configuration into Each Module
  3. Map Accounts and Regions to Real Trust Boundaries
  4. Avoid a Single Apply with Unrelated Failure Domains
  5. Coordinate Cloud Infrastructure with DNS and Edge Services
  6. Diagnose a Missing or Wrong Provider Configuration

One Provider Type Can Have Multiple Configurations

A provider block is not a label on a plugin. It is a connection profile: who is calling, which account pays, where the call lands, and which defaults follow every object created through it. One plugin can hold several profiles at once.

A provider type is a plugin; a block is a profile. The plugin here is hashicorp/aws. A provider block names a configuration of it inside one module. The block without an alias argument is the default configuration, and there can be one per provider per module. Each block that names an alias is an additional configuration, and that name is local to the module declaring it.

The selection rule itself is small. A resource chooses its configuration with the provider meta-argument: an alias name selects that configuration, and an omitted argument selects the default. Everything else is about what the chosen configuration carries, and that differs per provider.

ProviderWhat its configuration carriesGuard available
AWSregion, assume_role, default_tags, endpoint and retry overridesallowed_account_ids
Azuresubscription_id, tenant_id, and the required features blocksubscription data source plus a precondition
Googleproject, region, impersonate_service_accountproject data source plus a precondition
Cloudflarean API token that scopes zones and permissionsthe token scope itself

Credentials resolve per configuration. Provider arguments win, then environment variables, then shared files, then workload or instance metadata. Each alias walks that chain on its own, but all aliases inherit the same process environment. If neither pins a role, one exported AWS_PROFILE can make both of them the same principal. allowed_account_ids is checked while the provider configures itself, before any resource read, so it catches the wrong-account case early. No matching region guard exists: a wrong region is a perfectly valid configuration that reaches different infrastructure, or nothing.

The default you did not write

Provider configurations are not resources. They cannot be counted, repeated, imported or destroyed; Terraform wires them into the graph as configuration nodes, not as objects it plans.

An alias-only root is not automatically safe. Terraform assumes an empty default configuration for any provider declared in required_providers but never given an unaliased block. A resource that omits its provider argument uses that empty default, and if the shell supplies credentials and a region, the apply can succeed somewhere nobody intended.

Figure 1 follows one resource through the choice, including the two points where identity rather than syntax decides the outcome.

One Provider Type Can Have Multiple Configurations
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Resource block
needs an API client"] --> B{"provider argument
present?"} B -->|"no"| C["Default configuration
of this module"] B -->|"yes"| D["Named configuration
aws.secondary"] C --> E["Provider config object
region, role, guard, tags"] D --> E E --> F{"Where do credentials
come from?"} F -->|"provider arguments"| G["assume_role or token
pinned by the block"] F -->|"environment"| H["AWS_PROFILE or token
shared by every alias"] G --> I{"allowed_account_ids
matches?"} H --> I I -->|"no"| I1["Error before any
resource call"] I -->|"yes"| J["API call in the configured
account and region"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,E,J primary; class B,C,D,F,I secondary; class G ok; class H warn; class I1 danger;

Figure 2 separates the layers inside one alias. The resource sees a name; the provider turns that name into an identity, a destination and a set of defaults.

The four layers one provider alias carries A resource naming aws.secondary selects a provider configuration carrying a region, an assumed role, an account guard and default tags. That configuration resolves credentials and reaches an API in a specific account and region. A side panel shows two aliases sharing one shell environment, so an exported profile can fill either one. One alias, four layers 1. The resource chooses provider = aws.secondary 2. The configuration supplies context region us-east-1 · assume_role workload allowed_account_ids · default_tags 3. Credentials resolve for this alias arguments, environment, shared files, metadata 4. The API call lands somewhere specific account 111122223333, region us-east-1 Two aliases, one shell aws.primary eu-west-1 · workload role aws.secondary us-east-1 · workload role One alias omits credentials AWS_PROFILE fills it silently No guard, no warning A name is not a boundary. The configuration behind the name is. Name aliases by account and region, not by team or mood.
Configuration

One Provider Type Can Have Multiple Configurations

Worked trace. This is the provider set for the running example: two AWS connections and one Cloudflare connection. It creates nothing billable. Versions were checked on 5 November 2026. Read the output before you trust either alias.

terraform {
  required_version = "= 1.17.1"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "= 6.72.0"
    }
    cloudflare = {
      source  = "cloudflare/cloudflare"
      version = "= 5.28.1"
    }
  }
}

provider "aws" {
  alias  = "primary"
  region = "eu-west-1"

  allowed_account_ids = [var.workload_account_id]

  assume_role {
    role_arn     = var.workload_role_arn
    session_name = "tf-p17-${var.pipeline_id}"
  }

  default_tags {
    tags = {
      ManagedBy = "terraform"
      Root      = "p17"
    }
  }
}

provider "aws" {
  alias  = "secondary"
  region = "us-east-1"

  allowed_account_ids = [var.workload_account_id]

  assume_role {
    role_arn     = var.workload_role_arn
    session_name = "tf-p17-${var.pipeline_id}"
  }
}

provider "cloudflare" {
  alias     = "edge"
  api_token = var.cloudflare_dns_token
}

data "aws_caller_identity" "primary" {
  provider = aws.primary
}

data "aws_region" "primary" {
  provider = aws.primary
}

output "primary_identity" {
  value = {
    account = data.aws_caller_identity.primary.account_id
    arn     = data.aws_caller_identity.primary.arn
    region  = data.aws_region.primary.region
  }
}

What to check. First, the two AWS blocks must report the same account and different regions for this example. Cross-account aliases are legitimate, but they are a different design: they need trust relationships and usually a separate root, and the difference should never appear only in an output. Second, the ARN should name the role and the session, not a long-lived user. Third, the Cloudflare block has no region and no account argument; its token is its scope, which is why a separate token belongs here rather than a shared global key.

The output is safe to record after sanitizing the account digits. The credentials, session token and plan file are not.

Pass the Right Configuration into Each Module

A reusable module should describe what it needs, not where it runs. Provider blocks belong in the root; the child declares requirements and receives configurations at the call site. The rules are in Providers within modules.

The child declares a contract. A module that needs a named configuration lists it in its required_providers block as a configuration alias. That line is a promise, not a credential: the module will reference the name and expects its caller to supply something for it. The resources then write provider = aws.target on each block that needs it.

The caller supplies the mapping. Keys are names the child expects; values are configurations that exist in the caller. The map is evaluated per provider, so an AWS entry does not disturb an inherited Cloudflare default.

# modules/where/versions.tf — the contract
terraform {
  required_providers {
    aws = {
      source                = "hashicorp/aws"
      version               = "= 6.72.0"
      configuration_aliases = [aws.target]
    }
  }
}

# root main.tf — two calls, two configurations, identical child code
module "eu" {
  source = "./modules/where"

  providers = {
    aws.target = aws.primary
  }
}

module "us" {
  source = "./modules/where"

  providers = {
    aws.target = aws.secondary
  }
}
terraform init
terraform plan -out=p17.tfplan
terraform providers

A name is not a boundary; the configuration behind it is. Inheritance happens automatically only for an unaliased default configuration; an alias is never inherited. Remapping is the explicit form, where the caller gives the child's default name a different configuration, and the child code does not change.

AspectInheritanceRemapping
Triggerautomatican explicit mapping entry
Caller syntaxnothing to writeaws.target = aws.primary or aws = aws.secondary
What movesthe caller's default configurationthe configuration you name
Scopeunaliased defaults onlyany configuration the caller has
Typical useone account and one regionone module serving two regions
Failure modean alias is silently not inheriteda careless edit lands in the wrong account

A typo is worse than an omission

An omission fails loudly. If the child declares the alias and the caller omits the entry, Terraform stops with Missing required provider configuration, naming the module and the expected name.

A typo fails quietly. An extra key the child never declared produces only a Reference to undefined provider warning. Terraform ignores the entry and lets the child's resources use their default configuration, so the plan can still succeed as long as the required names are mapped.

One configuration per module call

Provider configurations cannot vary per module instance. A module call with count or for_each has one static provider association, so two regions need two module blocks, not one block with a loop.

A child that declares its own provider block is worse: it cannot be counted or looped, and it cannot carry an explicit dependency. Removing the module can then remove the configuration needed to destroy its resources.

Figure 3 follows the handoff and the three places it breaks.

Pass the Right Configuration into Each Module
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["module block
at the call site"] --> B{"providers map
present?"} B -->|"no"| C["Implicit inheritance
of default configs only"] B -->|"yes"| D["Keys must match child
local names and aliases"] D --> E{"Child declares it in
configuration_aliases?"} E -->|"no"| E1["Warning: reference to
undefined provider"] E -->|"yes"| F{"Caller passes an entry
for that name?"} F -->|"no"| F1["Error: missing required
provider configuration"] F -->|"yes"| G["Child provider = aws.target
resolves to aws.primary"] C --> H["Resource without provider
uses the inherited default"] E1 --> H G --> I["Plan resolves account
and region per alias"] H --> I I --> J{"Account guard and region
check pass?"} J -->|"no"| J1["Wrong target rejected
before resource calls"] J -->|"yes"| K["Apply through the
intended identity"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,G,I,K primary; class B,C,D,E,F,H,J secondary; class E1 warn; class F1,J1 danger;

Name the boundary, not the mood. A child module's documentation should list every configuration name it expects. A caller cannot guess whether a target alias means "the region to deploy into" or "the account that holds the shared certificate". aws.workload_eu makes the call site self-explanatory; aws.fast does not.

Map Accounts and Regions to Real Trust Boundaries

Two questions get tangled here: who may act, and where the action lands. An alias carries both, but they are not the same kind of boundary.

An AWS account is the strongest common boundary. A role inside it is the principal; its trust policy decides who may assume it, and the caller's identity policy must also allow sts:AssumeRole. Both sides are required, which is why a cross-account alias is a pair of permissions rather than one; a third-party trust should also demand sts:ExternalId. The region is placement. The same role can usually act in several regions, and a role that can act in one account cannot act in another without a trust relationship.

An Azure tenant is the identity boundary; a subscription is the RBAC and billing boundary. Resource groups sit inside the subscription, and a subscription-scoped role assignment does not follow you into another one. The azurerm provider pins the subscription and tenant in the block and requires a features block. A wrong subscription usually surfaces as "resource group not found", not as a clean guard, so read it with a data source and assert it in a precondition.

A GCP project is the IAM, policy and billing boundary, with folders and the organization above it. The google provider's project argument is a default, not a fence: many resources accept their own project argument and can target another project without changing the alias. That is the trap in the Google provider. Assert the project with a data source and a precondition, and treat the alias as convenience rather than control.

Cloudflare divides differently again. The account owns zones, and an API token is scoped to specific zones and permissions. There is no region and no subscription; the token is the trust boundary, so a separate alias is only meaningful when it carries a different token or account.

This article does not re-teach IAM, subscriptions or projects. The AWS provider and identity article covers role trust, session names and permission boundaries in detail. What matters here is the shape: an alias should name the boundary it crosses, and a guard should assert that boundary before the first API call.

Figure 4 puts the trust boundary above placement, because that is the order in which a plan should be read.

Trust boundaries and placement across AWS, Azure and GCP Three columns compare the AWS account, Azure subscription and GCP project as trust boundaries, with the principal and guard for each. A band below separates placement in a region or zone from the trust boundary above. A crimson strip states that moving an alias to another region does not change who can act. Who may act, then where it lands TRUST BOUNDARY — the principal and the scope it can reach AWS account principal: assumed role scope: account 1111… guard: allowed_account_ids crossing: trust policy plus sts:AssumeRole on the caller region: placement, not identity Azure subscription principal: service principal scope: tenant and subscription guard: subscription_id plus a subscription data source crossing: role assignment region: placement, not identity GCP project principal: service account scope: project under a folder guard: project data source trap: resources can override project per resource region: placement, not identity PLACEMENT — where the call lands, chosen per alias eu-west-1 / us-east-1 · West Europe / East US · europe-west1 / us-central1 Changing an alias from eu-west-1 to us-east-1 changes placement, not permission. If the new region is in another account, subscription or project, that is a different trust boundary and needs a different alias, credentials and usually a different state. A region guard is a policy you add. No cloud provider turns region into an account boundary for you.

Avoid a Single Apply with Unrelated Failure Domains

Aliases do not partition failure. A root with three aliases still has one state, one lock, one plan, one apply, one CI identity and one provider upgrade. The aliases decide where each call goes; they do nothing about what happens when one call fails.

That difference shows up in five ways. A partial apply can leave AWS changed and Cloudflare unchanged, with no rollback. A long database replacement holds the lock while a one-line DNS fix waits. The pipeline holds every credential in one process, so a compromised job can reach every account the aliases can reach. A provider upgrade anywhere in the root forces a new plan for everything in it, because one lock file and one plan cover everything. And terraform destroy removes everything in the state, not just the part you meant to retire.

The test for sharing a root is not "do these resources talk to each other". It is: same trust boundary, same lifecycle, same on-call rotation, and changes reviewed together. Two regions in an active-passive pair that are created and destroyed as one unit can share a root. Production and staging never should, even when one module creates both. Two regions with separate failover procedures and separate approvers should not either, because the moment one needs an emergency change, the other becomes a hostage.

Cross-provider dependencies do not require a shared root. Inside one root Terraform orders them; across roots you publish a value and accept an apply boundary. The handoff can be an input variable from the pipeline, a parameter in SSM or Secret Manager, a terraform_remote_state output, or a DNS delegation. Each trades convenience for coupling. A variable is explicit and can go stale. Remote state is convenient but exposes every value in that state and breaks when an output is renamed. A parameter drifts when the object and the parameter are updated separately. DNS delegation is often the cleanest multi-cloud contract: the parent zone holds only NS records, and each environment owns its own subdomain.

Write the contract in both repositories. The producing root lists what it publishes: the hostname, the certificate ARN, the parameter path, the alias it used. The consuming root records what it assumes and which variable carries it. That pair of notes is more useful during an incident than a diagram, because it names the failure.

Separate roots also separate credentials. An application root never needs the DNS token, and an edge root never needs the database password. That is the practical version of least privilege: not a smaller policy on one key, but fewer keys in one process.

Coordinate Cloud Infrastructure with DNS and Edge Services

Cloudflare in front of AWS is the common optional integration, and it tests the previous rule. Two providers, two credentials, one narrow lifecycle.

First decide which edge terminates TLS and caches. CloudFront already does both. Putting Cloudflare's proxy in front of CloudFront stacks two caches and two certificate terminators, and every cache bug becomes a debate about which layer is wrong. The example here uses Cloudflare for DNS only in front of CloudFront. The opposite choice, Cloudflare proxy in front of an ALB, is also valid; it is a different design, not a default.

The edge root holds two configurations, and neither credential can reach the other's estate. The AWS one lives in us-east-1 because an ACM certificate for CloudFront must live there, regardless of where the origin sits. CloudFront itself is global, but the same alias keeps the certificate and its consumer in one reviewable configuration. The Cloudflare token is scoped to Zone → DNS → Edit on one zone.

provider "aws" {
  alias  = "us_east_1"
  region = "us-east-1"

  allowed_account_ids = [var.edge_account_id]

  assume_role {
    role_arn     = var.edge_role_arn
    session_name = "tf-p17-${var.pipeline_id}"
  }
}

provider "cloudflare" {
  alias     = "edge"
  api_token = var.cloudflare_dns_token
}

The sequence is short. Four steps take the certificate from request to serving traffic.

  1. aws_acm_certificate requests a certificate for app.example.com with DNS validation.
  2. Its domain_validation_options give a CNAME name and value; a for_each over that set creates a cloudflare_dns_record of type CNAME with proxied = false and a low TTL.
  3. The ACM record name often ends in a trailing dot, so trim it before handing it to Cloudflare, then aws_acm_certificate_validation waits for the certificate to be issued.
  4. aws_cloudfront_distribution uses the validated ARN, and a final DNS record points the hostname at the distribution's domain name, again DNS-only.

This belongs in one root because the certificate and its validation record are one lifecycle. Splitting them means one apply waits for a human to copy a CNAME into another repository, and the certificate sits pending in between. The token is still narrow enough that the worst mistake in this root is a wrong record in one zone, not a deleted account.

The failure path is instructive. If the token cannot write DNS records, the apply stops at the Cloudflare record. If the record is created in the wrong zone or with the wrong value, the certificate never validates and the apply stops at aws_acm_certificate_validation, not at CloudFront. Nothing in AWS is rolled back in the second case: the certificate exists, unvalidated, and the distribution does not exist yet. In the first case the fix is to grant DNS Edit on that one zone; in the second it is to correct the record. Neither calls for a wider token. If the Cloudflare API is unavailable, the AWS certificate request may succeed while the record fails; the next apply resumes from state. That is a partial apply, and it is survivable because the blast radius is one certificate.

Figure 5 contrasts the scoped version with the shared-credential version that looks identical in a code review.

A scoped AWS and Cloudflare edge compared with one shared credential The top flow shows an ACM certificate in us-east-1 producing a validation CNAME that Cloudflare serves, after which the certificate validates and CloudFront uses it. The lower left panel shows one broad credential reaching several zones and accounts. The lower right panel shows an AWS role limited to the edge account and a Cloudflare token limited to DNS edit on one zone. Two clouds, two credentials, one narrow lifecycle live/edge root — one state, two provider configurations ACM certificate aws.us_east_1 Validation CNAME cloudflare.edge Certificate issued validation waiter CloudFront global service One credential for everything AWS role can reach prod and dev Cloudflare token can edit zones example.com, example.net, example.org The plan looks the same. A typo in one record name can break a zone nobody was reviewing. Blast radius: every zone in the token. Separately scoped credentials AWS role: edge account only Cloudflare token: Zone DNS Edit, one zone, no account-wide access The proxy stays off in DNS-only mode. A failed validation stops this root and leaves the app root running. Blast radius: one certificate, one zone. Failure path: wrong record → certificate pending → apply stops at validation. The fix is the right record in the right zone, not a wider token everywhere. Two clouds can share a state when they share one lifecycle and neither credential can exceed it.

The application root remains separate. It publishes the distribution hostname or the load balancer name through a variable or an SSM parameter, and the edge root consumes it. The order is explicit: deploy the app, publish the endpoint, update the edge. A failed edge apply leaves the previous endpoint serving; a failed app apply does not invalidate the certificate. That is the benefit of the apply boundary, even though the two clouds are tightly related.

Diagnose a Missing or Wrong Provider Configuration

Wrong-target plans are divided into two classes: the ones that fail, and the ones that succeed in the wrong place. The second class is the reason every alias needs a guard and a named owner.

An inherited default is a silent wrong target. A child module with no provider argument uses the default configuration of its own module. If the root's default points at staging and the production module is called without a mapping, the production resources are created in staging. The plan is valid, the diff is ordinary, and the only clue is an account ID in an output nobody read. Pass aliases explicitly, guard every configuration with allowed_account_ids, and publish the identity the alias reached as a plan output.

An environment leak can overrule a careful alias. The shell fills any gap the block leaves open: AWS_PROFILE, the AWS access-key and region variables, and their Azure and Google equivalents. A developer who exported a profile for another task changes the meaning of every unguarded alias in the configuration. Pin a profile or assume-role settings in the block where it matters, and remember that -refresh=false does not skip provider configuration; the guard still runs.

A misspelled mapping key is a warning, not an error. Passing a key the child never declared produces only an undefined-provider warning: Terraform ignores the entry, and the plan can still succeed as long as the names the child actually requires are mapped. If the child declared the name and the caller omits it, the failure is clean and names the module and the expected name. Read the mapping as a contract, not a hint.

A removed configuration. State records the provider configuration that last applied each resource. Removing or renaming that block while its resources remain produces Provider configuration not present, followed by "its original provider configuration at provider["registry.terraform.io/hashicorp/aws"].west is required, but it has been removed." Re-adding the block is the only way to destroy those objects; removing them from state first is a deliberate abandonment, not a cleanup. Destroy the resources, then remove the configuration.

A provider change is a migration

Changing a resource from one alias to another does not move the object between accounts or regions. Terraform refreshes through the new configuration, often finds nothing, and plans a create; the old object stays where it was, unmanaged, because no state entry points at it any more.

A provider change on existing infrastructure is a migration: destroy and recreate deliberately, or import the object into the new address, then remove the old one.

Requirements are not resolution. terraform providers lists requirements by module but not the resolved alias, so it answers "who requires this plugin" rather than "where did this resource go". A saved plan read as JSON adds configuration.provider_config, whose keys include the root aliases.

State is decisive. terraform state pull shows the provider address recorded for each resource, such as provider["registry.terraform.io/hashicorp/aws"].primary. Compare that with the alias you intended; when they differ, the configuration is not the only thing that needs fixing.

Lab

Wire two provider configurations

Status: design-only. The commands below were not run for this article. They target a disposable AWS sandbox with Terraform CLI 1.17.1, AWS provider 6.72.0, and optionally Cloudflare 5.28.1 with a token scoped to one test zone. Cost is zero: the lab creates two terraform_data objects and reads identity data only.

Setup. Two directories: a root at labs/p17/ and a child at labs/p17/modules/where/. The child declares one configuration alias and writes nothing to a cloud API.

# modules/where/versions.tf
terraform {
  required_providers {
    aws = {
      source                = "hashicorp/aws"
      version               = "= 6.72.0"
      configuration_aliases = [aws.target]
    }
  }
}

# modules/where/main.tf
data "aws_caller_identity" "target" {
  provider = aws.target
}

data "aws_region" "target" {
  provider = aws.target
}

resource "terraform_data" "where" {
  input = {
    account = data.aws_caller_identity.target.account_id
    region  = data.aws_region.target.region
  }
}

The root reuses the two AWS provider blocks from the first experiment card and calls the child twice.

module "eu" {
  source = "./modules/where"

  providers = {
    aws.target = aws.primary
  }
}

module "us" {
  source = "./modules/where"

  providers = {
    aws.target = aws.secondary
  }
}
  1. Run terraform init and keep the lock file. Run terraform providers and note that it reports the plugin requirement for the root and the child, not the alias each resource will use.
  2. Run terraform plan -out=p17.tfplan. Both module calls should plan one terraform_data object, and no AWS resource should be created.
  3. Apply the saved plan, then run terraform state pull and inspect the provider field of each resource. Each address should end in .primary or .secondary, proving the two calls resolved to different configurations even though the child code is identical.
  4. Run terraform show -json p17.tfplan and read configuration.provider_config. The root aliases should appear there; this is the plan-side view of the same mapping.
  5. Break the mapping on purpose: remove the providers map from one call and plan. Expect Missing required provider configuration, naming the module and aws.target. Restore the map.
  6. Break it differently: add a spare key, providers = { aws.target = aws.primary, aws.wrong = aws.primary }. Expect only a Reference to undefined provider warning and a plan that still succeeds, because aws.target is still mapped. This is the failure that a green pipeline will not catch.
  7. Test removal: apply with both aliases, then delete the secondary block while its resource remains. Expect Provider configuration not present on the next plan. Restore the block, destroy, and only then remove it.
  8. Optional: add provider "cloudflare" { alias = "edge" ... } and a data "cloudflare_zone" read through cloudflare.edge. Plan only. Confirm the token can read that one zone and fails against a zone it was not scoped to.
  9. Destroy the root and confirm both state addresses disappear. Delete the local state, remove the plan file, and revoke any temporary token.

Expected observation. Step 3 is the proof: the two child resources carry different provider addresses in state, not just different inputs. Step 6 is the warning: an extra mistyped key is ignored while the valid mapping still succeeds. Step 7 is the state dependency: a configuration cannot be removed while its objects still exist.

Failure check. If step 5 does not fail, the child never declared the alias in configuration_aliases. If step 7 succeeds after deleting the block, the resource was already gone or the state was never written. If both resources show the same provider address, the mapping was omitted from one call.

Evidence to keep. A sanitized provider-to-module mapping, the two state provider addresses, the terraform providers tree, the step 6 warning, and the step 7 error. Redact account IDs and zone IDs; never publish credentials or the plan file.

Next in the Series

In Adopt Existing Infrastructure with Reviewable Imports, we'll explore Move unmanaged resources under Terraform without accidentally replacing them.