mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-14 01:13:59 -06:00
Previously, resources without explicit provider configuration (i.e. a `provider =` attribute) would be assigned a default provider based upon the resource type. For example, a resource `foo_bar` would be assigned provider `hashicorp/foo`. This behaviour did not work well with community or partner providers, with sources configured in `terraform.required_providers` blocks. With the following configuration: terraform { required_providers { foo = { source = "acme/foo" } } } resource foo_bar "a" { } the resource would be configured with the `hashicorp/foo` provider. This commit fixes this implied provider behaviour. First we look for a provider with local name matching the resource type in the module's required providers map. If one is found, this provider is assigned to the resource. Otherwise, we still fall back to a default provider.
22 lines
786 B
HCL
22 lines
786 B
HCL
terraform {
|
|
required_providers {
|
|
// This is an expected "real world" example of a community provider, which
|
|
// has resources named "foo_*" and will likely be used in configurations
|
|
// with the local name of "foo".
|
|
foo = {
|
|
source = "registry.acme.corp/acme/foo"
|
|
}
|
|
|
|
// However, implied provider lookups are based on local name, not provider
|
|
// type, and this example clarifies that. Only resources with addresses
|
|
// starting "whatever_" will be assigned this provider implicitly.
|
|
//
|
|
// This is _not_ a recommended usage pattern. The best practice is for
|
|
// local name and type to be the same, and only use a different local name
|
|
// if there are provider type collisions.
|
|
whatever = {
|
|
source = "acme/something"
|
|
}
|
|
}
|
|
}
|