diff --git a/configs/resource.go b/configs/resource.go index e5cc8c606..a6946854d 100644 --- a/configs/resource.go +++ b/configs/resource.go @@ -66,8 +66,12 @@ func (r *Resource) Addr() addrs.Resource { // config addr if an explicit "provider" argument was not provided. func (r *Resource) ProviderConfigAddr() addrs.LocalProviderConfig { if r.ProviderConfigRef == nil { + // If no specific "provider" argument is given, we want to look up the + // provider config where the local name matches the implied provider + // from the resource type. This may be different from the resource's + // provider type. return addrs.LocalProviderConfig{ - LocalName: r.Provider.Type, + LocalName: r.Addr().ImpliedProvider(), } } diff --git a/terraform/evaluate_valid_test.go b/terraform/evaluate_valid_test.go index 9be7b278b..086ca3037 100644 --- a/terraform/evaluate_valid_test.go +++ b/terraform/evaluate_valid_test.go @@ -50,6 +50,14 @@ For example, to correlate with indices of a referring resource, use: aws_instance.count[count.index] - Unsupported attribute: This object has no argument, nested block, or exported attribute named "foo".`, }, + { + "boop_instance.yep", + ``, + }, + { + "boop_whatever.nope", + `Invalid resource type: A managed resource type "boop_whatever" is not supported by provider "registry.terraform.io/foobar/beep".`, + }, } cfg := testModule(t, "static-validate-refs") @@ -62,6 +70,12 @@ For example, to correlate with indices of a referring resource, use: "aws_instance": {}, }, }, + addrs.MustParseProviderSourceString("foobar/beep"): { + ResourceTypes: map[string]*configschema.Block{ + // intentional mismatch between resource type prefix and provider type + "boop_instance": {}, + }, + }, }, }, } diff --git a/terraform/testdata/static-validate-refs/static-validate-refs.tf b/terraform/testdata/static-validate-refs/static-validate-refs.tf index 9d945279c..e9f9344a8 100644 --- a/terraform/testdata/static-validate-refs/static-validate-refs.tf +++ b/terraform/testdata/static-validate-refs/static-validate-refs.tf @@ -1,6 +1,20 @@ +terraform { + required_providers { + boop = { + source = "foobar/beep" # intentional mismatch between local name and type + } + } +} + resource "aws_instance" "no_count" { } resource "aws_instance" "count" { count = 1 } + +resource "boop_instance" "yep" { +} + +resource "boop_whatever" "nope" { +}