mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Catch invalid name in provider_meta before it causes a crash (#2347)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
This commit is contained in:
parent
76d388b340
commit
f83849e95a
@ -17,6 +17,7 @@ ENHANCEMENTS:
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
- Fixed an issue where an invalid provider name in the `provider_meta` block would crash OpenTofu rather than report an error ([#2347](https://github.com/opentofu/opentofu/pull/2347))
|
||||
|
||||
## Previous Releases
|
||||
|
||||
|
@ -30,8 +30,11 @@ func decodeProviderMetaBlock(block *hcl.Block) (*ProviderMeta, hcl.Diagnostics)
|
||||
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)...)
|
||||
// If the name is invalid, we return an error early, lest the invalid value
|
||||
// is used by the caller and causes a panic further down the line.
|
||||
if diags = append(diags, checkProviderNameNormalized(block.Labels[0], block.DefRange)...); diags.HasErrors() {
|
||||
return nil, diags
|
||||
}
|
||||
|
||||
return &ProviderMeta{
|
||||
Provider: block.Labels[0],
|
||||
|
@ -7,4 +7,3 @@ terraform {
|
||||
variable "name" {
|
||||
type = string
|
||||
}
|
||||
|
5
internal/configs/testdata/invalid-modules/provider-meta-invalid-name/main.tf
vendored
Normal file
5
internal/configs/testdata/invalid-modules/provider-meta-invalid-name/main.tf
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
terraform {
|
||||
provider_meta "chunky_bacon" {
|
||||
hello = "world"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user