opentofu/internal/configs/provider_meta.go
Martin Atkins 31349a9c3a Move configs/ to internal/configs/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

38 lines
977 B
Go

package configs
import "github.com/hashicorp/hcl/v2"
// ProviderMeta represents a "provider_meta" block inside a "terraform" block
// in a module or file.
type ProviderMeta struct {
Provider string
Config hcl.Body
ProviderRange hcl.Range
DeclRange hcl.Range
}
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 = append(diags, checkProviderNameNormalized(block.Labels[0], block.DefRange)...)
return &ProviderMeta{
Provider: block.Labels[0],
ProviderRange: block.LabelRanges[0],
Config: block.Body,
DeclRange: block.DefRange,
}, diags
}