File tree 3 files changed +50
-0
lines changed
internal/backend/backendbase
3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ kind : BUG FIXES
2
+ body : ' backends: Fix crash when interrupting during interactive prompt for values'
3
+ time : 2025-02-06T14:52:17.033964+01:00
4
+ custom :
5
+ Issue : " 36448"
Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ func (b Base) ConfigSchema() *configschema.Block {
57
57
func (b Base ) PrepareConfig (configVal cty.Value ) (cty.Value , tfdiags.Diagnostics ) {
58
58
var diags tfdiags.Diagnostics
59
59
60
+ if configVal .IsNull () {
61
+ // We expect the backend configuration to be an object, so if it's
62
+ // null for some reason (e.g. because of an interrupt), we'll turn
63
+ // it into an empty object so that we can still coerce it
64
+ configVal = cty .EmptyObjectVal
65
+ }
66
+
60
67
schema := b .Schema
61
68
62
69
v , err := schema .CoerceValue (configVal )
Original file line number Diff line number Diff line change @@ -214,3 +214,41 @@ func TestBase_deprecatedArg(t *testing.T) {
214
214
}
215
215
})
216
216
}
217
+
218
+ func TestBase_nullCrash (t * testing.T ) {
219
+ // This test ensures that we don't crash while applying defaults to
220
+ // a null value
221
+
222
+ b := Base {
223
+ Schema : & configschema.Block {
224
+ Attributes : map [string ]* configschema.Attribute {
225
+ "foo" : {
226
+ Type : cty .String ,
227
+ Required : true ,
228
+ },
229
+ },
230
+ },
231
+ SDKLikeDefaults : SDKLikeDefaults {
232
+ "foo" : {
233
+ Fallback : "fallback" ,
234
+ },
235
+ },
236
+ }
237
+
238
+ t .Run ("error" , func (t * testing.T ) {
239
+ // We pass an explicit null value here to simulate an interrupt
240
+ _ , gotDiags := b .PrepareConfig (cty .NullVal (cty .Object (map [string ]cty.Type {
241
+ "foo" : cty .String ,
242
+ })))
243
+ var wantDiags tfdiags.Diagnostics
244
+ wantDiags = wantDiags .Append (
245
+ & hcl.Diagnostic {
246
+ Severity : hcl .DiagError ,
247
+ Summary : "Invalid backend configuration" ,
248
+ Detail : "The backend configuration is incorrect: attribute \" foo\" is required." ,
249
+ })
250
+ if diff := cmp .Diff (wantDiags .ForRPC (), gotDiags .ForRPC ()); diff != "" {
251
+ t .Errorf ("wrong diagnostics\n %s" , diff )
252
+ }
253
+ })
254
+ }
You can’t perform that action at this time.
0 commit comments