TF-Associate-004 - Terraform fundamentals - Section 2c

Write Terraform configuration using multiple providers.

Multiple provider configurations are distinguished with alias, and a resource selects a non-default configuration through its provider meta-argument. Candidates should predict which provider configuration a resource uses given aliases, and know when a second configuration is needed (for example two regions).

provider aliasprovider meta-argumentdefault and additional provider configurationsmulti-region configuration

Practice question for this objective

Free sampleTerraform fundamentalseasy

An engineer needs to manage resources in two different AWS regions from a single configuration. They define one default aws provider for eu-west-1 and a second aws provider with an alias for us-east-1. How should a resource be told to use the us-east-1 configuration?

provider "aws" {
  region = "eu-west-1"
}
provider "aws" {
  alias  = "us"
  region = "us-east-1"
}
  • ASet region = "us-east-1" directly inside the resource block so it overrides the default provider.
  • BAdd a provider = aws.us meta-argument to the resource block to point it at the aliased provider. Correct
  • CAdd a depends_on = [aws.us] entry so the resource is associated with the second provider.
  • DRename the resource type to aws_us_instance so the alias is matched by the type prefix.
A resource selects a non-default provider configuration through the provider meta-argument referencing the provider local name and its alias. When multiple configurations of the same provider exist, one is default and the others carry an alias; a resource opts in to an aliased configuration by setting the provider meta-argument to localname.alias, here aws.us, rather than by any resource-level region setting.

Why A is wrong: Region is a provider argument, not a resource argument, and setting it on the resource is rejected; this confuses where regional configuration lives.

Why B is correct: The provider meta-argument with the local name and alias, written as aws.us, is exactly how a resource selects a non-default aliased provider configuration.

Why C is wrong: depends_on expresses ordering between resources or modules, not provider selection, so it cannot bind a resource to an aliased provider.

Why D is wrong: Resource type names are fixed by the provider schema and cannot encode an alias; inventing a type prefix would simply produce an unknown resource type error.

See more TF-Associate-004 practice questions, answers explained.

More in this domain

Back to all Terraform fundamentals objectives, or the TF-Associate-004 cert hub.

Examworthy is not affiliated with or endorsed by HashiCorp. Original, blueprint-aligned practice material only.