validate provider_meta contains no interpolations

The provider_meta specification does not allow interpolation, but we
were not preventing it in the configuration.
This commit is contained in:
James Bardin 2021-03-12 12:10:25 -05:00
parent b26ae9cf48
commit 759b76436a
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"
}
}