Skip to content

Commit e6cf6cd

Browse files
authored
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
1 parent 023454a commit e6cf6cd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

backend/remote/backend.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func (b *Remote) ConfigSchema() *configschema.Block {
142142
// PrepareConfig implements backend.Backend.
143143
func (b *Remote) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
144144
var diags tfdiags.Diagnostics
145+
if obj.IsNull() {
146+
return obj, diags
147+
}
145148

146149
if val := obj.GetAttr("organization"); val.IsNull() || val.AsString() == "" {
147150
diags = diags.Append(tfdiags.AttributeValue(
@@ -188,6 +191,9 @@ func (b *Remote) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
188191
// Configure implements backend.Enhanced.
189192
func (b *Remote) Configure(obj cty.Value) tfdiags.Diagnostics {
190193
var diags tfdiags.Diagnostics
194+
if obj.IsNull() {
195+
return diags
196+
}
191197

192198
// Get the hostname.
193199
if val := obj.GetAttr("hostname"); !val.IsNull() && val.AsString() != "" {

backend/remote/backend_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ func TestRemote_config(t *testing.T) {
123123
}),
124124
valErr: `Only one of workspace "name" or "prefix" is allowed`,
125125
},
126+
"null config": {
127+
config: cty.NullVal(cty.EmptyObject),
128+
},
126129
}
127130

128131
for name, tc := range cases {

0 commit comments

Comments
 (0)