mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
backend/remote: do not panic if PrepareConfig or Configure receive null (#25135)
* backend/remote: do not panic if PrepareConfig or Configure receive null objects If a user cancels (ctrl-c) terraform init while it is requesting missing configuration options for the remote backend, the PrepareConfig and Configure functions would receive a null cty.Value which would result in panics. This PR adds a check for null objects to the two functions in question. Fixes #23992
This commit is contained in:
parent
023454a3a6
commit
e6cf6cd758
@ -142,6 +142,9 @@ func (b *Remote) ConfigSchema() *configschema.Block {
|
||||
// PrepareConfig implements backend.Backend.
|
||||
func (b *Remote) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
|
||||
var diags tfdiags.Diagnostics
|
||||
if obj.IsNull() {
|
||||
return obj, diags
|
||||
}
|
||||
|
||||
if val := obj.GetAttr("organization"); val.IsNull() || val.AsString() == "" {
|
||||
diags = diags.Append(tfdiags.AttributeValue(
|
||||
@ -188,6 +191,9 @@ func (b *Remote) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
|
||||
// Configure implements backend.Enhanced.
|
||||
func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
|
||||
var diags tfdiags.Diagnostics
|
||||
if obj.IsNull() {
|
||||
return diags
|
||||
}
|
||||
|
||||
// Get the hostname.
|
||||
if val := obj.GetAttr("hostname"); !val.IsNull() && val.AsString() != "" {
|
||||
|
@ -123,6 +123,9 @@ func TestRemote_config(t *testing.T) {
|
||||
}),
|
||||
valErr: `Only one of workspace "name" or "prefix" is allowed`,
|
||||
},
|
||||
"null config": {
|
||||
config: cty.NullVal(cty.EmptyObject),
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user