configs: Fail early for invalid resource provider

If a resource's "provider" reference is invalid and cannot be parsed, we
should not store the reference as part of a `ProviderConfigRef`. Doing
so creates an invalid data structure, which prevents us from using
`MustParseProviderPart` with the name in later steps.

The invalid test files added in this commit will cause a panic without
the code change.
This commit is contained in:
Alisdair McDiarmid 2020-06-26 09:45:02 -04:00
parent 4459e6ea3a
commit 5e3d2dbdfa
3 changed files with 9 additions and 0 deletions

View File

@ -422,6 +422,9 @@ func decodeProviderConfigRef(expr hcl.Expression, argName string) (*ProviderConf
name := traversal.RootName()
nameDiags := checkProviderNameNormalized(name, traversal[0].SourceRange())
diags = append(diags, nameDiags...)
if diags.HasErrors() {
return nil, diags
}
ret := &ProviderConfigRef{
Name: name,

View File

@ -0,0 +1,3 @@
data "test_resource" "t" {
provider = my_test
}

View File

@ -0,0 +1,3 @@
resource "test_resource" "t" {
provider = my_test
}