- The OpenTofu Language
- Meta-Arguments
- The Resource provider Meta-Argument
The Resource provider
Meta-Argument
The provider
meta-argument specifies which provider instance is responsible for managing
each instance of a resource, overriding OpenTofu's default behavior of
automatically selecting a default provider configuration.
As described in Provider Configuration, you can optionally declare multiple configurations for a single provider, or multiple dynamic instances of a single provider configuration, such as when managing resources across different regions when using a provider which forces only a single region per provider instance.
By default, OpenTofu interprets the initial word in the resource type name (separated by
underscores) as the local name of a provider, and uses that provider's default
configuration. For example, the resource type google_compute_instance
is associated
automatically with the default configuration for the provider whose local name
in the current module is google
.
Using the provider
meta-argument you can select an alternate provider configuration
for a resource:
If you select a provider configuration that uses for_each
then you
must also dynamically select a different instance of the provider configuration for
each instance of the resource by including an instance key expression in brackets:
You can find more detail on the syntax used with the provider
argument in
Referring to Provider Instances.
The for_each
expression for a resource must not exactly match the
for_each
expression for its associated provider configuration.
OpenTofu uses a provider instance to plan and apply all actions related to a resource instance, including destroying a resource instance that has been removed from the configuration.
Therefore the provider instance associated with any resource instance must always remain in the configuration for at least one more plan/apply round after the resource instance has been removed, or OpenTofu will fail to plan to destroy the resource instance.
You can find more information on this constraint in Referring to Provider Instances.