Merge pull request #28072 from hashicorp/jbardin/provider-meta-interpolation

validate provider_meta contains no interpolations
This commit is contained in:
James Bardin 2021-03-12 17:12:58 -05:00 committed by GitHub
commit 0750a16cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -13,8 +13,20 @@ type ProviderMeta struct {
}
func decodeProviderMetaBlock(block *hcl.Block) (*ProviderMeta, hcl.Diagnostics) {
// provider_meta must be a static map. We can verify this by attempting to
// evaluate the values.
attrs, diags := block.Body.JustAttributes()
if diags.HasErrors() {
return nil, diags
}
for _, attr := range attrs {
_, d := attr.Expr.Value(nil)
diags = append(diags, d...)
}
// verify that the local name is already localized or produce an error.
diags := checkProviderNameNormalized(block.Labels[0], block.DefRange)
diags = append(diags, checkProviderNameNormalized(block.Labels[0], block.DefRange)...)
return &ProviderMeta{
Provider: block.Labels[0],

View File

@ -0,0 +1,10 @@
terraform {
provider_meta "my-provider" {
hello = var.name
}
}
variable "name" {
type = string
}

View File

@ -0,0 +1,5 @@
terraform {
provider_meta "my-provider" {
hello = "test-module"
}
}