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:
Marcin Wyszynski 2025-01-09 15:36:56 +01:00 committed by GitHub
parent 76d388b340
commit f83849e95a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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],

View File

@ -0,0 +1,5 @@
terraform {
provider_meta "chunky_bacon" {
hello = "world"
}
}