mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
041f4dd8ca
* addrs: replace NewLegacyProvider with NewDefaultProvider in ParseProviderSourceString ParseProviderSourceString was still defaulting to NewLegacyProvider when encountering single-part strings. This has been fixed. This commit also adds a new function, IsProviderPartNormalized, which returns a bool indicating if the string given is the same as a normalized version (as normalized by ParseProviderPart) or an error. This is intended for use by the configs package when decoding provider configurations. * terraform: fix provider local names in tests * configs: validate that all provider names are normalized The addrs package normalizes all source strings, but not the local names. This caused very odd behavior if for e.g. a provider local name was capitalized in one place and not another. We considered enabling case-sensitivity for provider local names, but decided that since this was not something that worked in previous versions of terraform (and we have yet to encounter any use cases for this feature) we could generate an error if the provider local name is not normalized. This error also provides instructions on how to fix it. * configs: refactor decodeProviderRequirements to consistently not set an FQN when there are errors
26 lines
671 B
Go
26 lines
671 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) {
|
|
// verify that the local name is already localized or produce an error.
|
|
diags := checkProviderNameNormalized(block.Labels[0], block.DefRange)
|
|
|
|
return &ProviderMeta{
|
|
Provider: block.Labels[0],
|
|
ProviderRange: block.LabelRanges[0],
|
|
Config: block.Body,
|
|
DeclRange: block.DefRange,
|
|
}, diags
|
|
}
|