Bitzu

Terraform Associate 004 ยท Providers and state fundamentals

How do you use several providers, or several configurations of one provider?

Several different providers in one configuration, provider aliases, the provider meta-argument, passing providers to resources (2c).

Key points

  • Different providers: a required_providers entry each (and a provider block if configured); resources pick by type prefix.
  • Same provider twice (e.g. two regions): second provider block with an alias.
  • Selection: provider = <name>.<alias>, e.g. provider = aws.west, on a resource, data source or module.
  • Block without an alias: the default configuration.
  • Child modules: get aliased configurations via the providers argument.

Source: https://developer.hashicorp.com/terraform/language/block/provider

Practice questions

Single choice

Which argument lets you define a second configuration of the same provider in one module?

  1. alias
  2. source
  3. version
  4. depends_on
Show answer

Answer: A. alias

alias on the extra provider block gives that configuration a name. version is a constraint, source is a location, and depends_on is about ordering.

Select all that apply

Which statements about provider aliases are correct?

  1. A provider block without alias is the default configuration
  2. Aliases are mandatory whenever two different providers are used
  3. A module block can pass an aliased configuration via providers
  4. The alias argument is set on each resource that uses it
  5. An alias must be globally unique across the registry
Show answer

Answer: A. A provider block without alias is the default configuration, C. A module block can pass an aliased configuration via providers

The provider block without an alias is the default that resources use when they omit the meta-argument. A module is given an aliased configuration through the providers argument. Aliases are not required for different providers, and the alias is set on the provider block, not on resources.

True or false

True or false: to use the aws and random providers in one configuration, you must give one of them an alias.

Show answer

Answer: False

False. Aliases are only for multiple configurations of the same provider. Different providers are told apart by their own names and resource type prefixes.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module