File tree Expand file tree Collapse file tree 3 files changed +56
-1
lines changed
testdata/validate-required-provider-config Expand file tree Collapse file tree 3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -650,6 +650,38 @@ func TestContext2Validate_providerConfig_good(t *testing.T) {
650650 }
651651}
652652
653+ // In this test there is a mismatch between the provider's fqn (hashicorp/test)
654+ // and it's local name set in required_providers (arbitrary).
655+ func TestContext2Validate_requiredProviderConfig (t * testing.T ) {
656+ m := testModule (t , "validate-required-provider-config" )
657+ p := testProvider ("aws" )
658+
659+ p .GetSchemaReturn = & ProviderSchema {
660+ Provider : & configschema.Block {
661+ Attributes : map [string ]* configschema.Attribute {
662+ "required_attribute" : {Type : cty .String , Required : true },
663+ },
664+ },
665+ ResourceTypes : map [string ]* configschema.Block {
666+ "aws_instance" : {
667+ Attributes : map [string ]* configschema.Attribute {},
668+ },
669+ },
670+ }
671+
672+ c := testContext2 (t , & ContextOpts {
673+ Config : m ,
674+ Providers : map [addrs.Provider ]providers.Factory {
675+ addrs .NewDefaultProvider ("aws" ): testProviderFuncFixed (p ),
676+ },
677+ })
678+
679+ diags := c .Validate ()
680+ if diags .HasErrors () {
681+ t .Fatalf ("unexpected error: %s" , diags .Err ())
682+ }
683+ }
684+
653685func TestContext2Validate_provisionerConfig_bad (t * testing.T ) {
654686 m := testModule (t , "validate-bad-prov-conf" )
655687 p := testProvider ("aws" )
Original file line number Diff line number Diff line change 1+ # This test verifies that the provider local name, local config and fqn map
2+ # together properly when the local name does not match the type.
3+
4+ terraform {
5+ required_providers {
6+ arbitrary = {
7+ source = " hashicorp/aws"
8+ }
9+ }
10+ }
11+
12+ # hashicorp/test has required provider config attributes. This "arbitrary"
13+ # provider configuration block should map to hashicorp/test.
14+ provider "arbitrary" {
15+ required_attribute = " bloop"
16+ }
17+
18+ resource "aws_instance" "test" {
19+ provider = " arbitrary"
20+ }
Original file line number Diff line number Diff line change @@ -721,9 +721,12 @@ func (t *ProviderConfigTransformer) attachProviderConfigs(g *Graph) error {
721721 continue
722722 }
723723
724+ // Find the localName for the provider fqn
725+ localName := mc .Module .LocalNameForProvider (addr .Provider )
726+
724727 // Go through the provider configs to find the matching config
725728 for _ , p := range mc .Module .ProviderConfigs {
726- if p .Name == addr . Provider . Type && p .Alias == addr .Alias {
729+ if p .Name == localName && p .Alias == addr .Alias {
727730 log .Printf ("[TRACE] ProviderConfigTransformer: attaching to %q provider configuration from %s" , dag .VertexName (v ), p .DeclRange )
728731 apn .AttachProvider (p )
729732 break
You can’t perform that action at this time.
0 commit comments