Skip to content

Commit 75aff68

Browse files
committed
Allow empty scheduler_configuration block to enable the feature with default values
1 parent 364d9a1 commit 75aff68

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

internal/service/emrserverless/application.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ func resourceApplicationCreate(ctx context.Context, d *schema.ResourceData, meta
309309
input.NetworkConfiguration = expandNetworkConfiguration(v.([]any)[0].(map[string]any))
310310
}
311311

312-
if v, ok := d.GetOk("scheduler_configuration"); ok && len(v.([]any)) > 0 && v.([]any)[0] != nil {
313-
input.SchedulerConfiguration = expandSchedulerConfiguration(v.([]any)[0].(map[string]any))
312+
// Empty block (len(v.([]any)) > 0 but v.([]any)[0] == nil) is allowed to enable scheduler_configuration with default values
313+
if v, ok := d.GetOk("scheduler_configuration"); ok && len(v.([]any)) > 0 {
314+
input.SchedulerConfiguration = expandSchedulerConfiguration(v.([]any))
314315
}
315316

316317
output, err := conn.CreateApplication(ctx, input)
@@ -429,10 +430,14 @@ func resourceApplicationUpdate(ctx context.Context, d *schema.ResourceData, meta
429430
input.NetworkConfiguration = expandNetworkConfiguration(v.([]any)[0].(map[string]any))
430431
}
431432

432-
if v, ok := d.GetOk("scheduler_configuration"); ok && len(v.([]any)) > 0 && v.([]any)[0] != nil {
433-
input.SchedulerConfiguration = expandSchedulerConfiguration(v.([]any)[0].(map[string]any))
434-
} else {
435-
input.SchedulerConfiguration = &types.SchedulerConfiguration{}
433+
if d.HasChange("scheduler_configuration") {
434+
// Empty block (len(v.([]any)) > 0 but v.([]any)[0] == nil) is allowed to enable scheduler_configuration with default values
435+
if v, ok := d.GetOk("scheduler_configuration"); ok && len(v.([]any)) > 0 {
436+
input.SchedulerConfiguration = expandSchedulerConfiguration(v.([]any))
437+
} else {
438+
// scheduler_configuration block is removed
439+
input.SchedulerConfiguration = &types.SchedulerConfiguration{}
440+
}
436441
}
437442

438443
if v, ok := d.GetOk("release_label"); ok {
@@ -898,18 +903,24 @@ func flattenWorkerResourceConfig(apiObject *types.WorkerResourceConfig) map[stri
898903
return tfMap
899904
}
900905

901-
func expandSchedulerConfiguration(tfMap map[string]any) *types.SchedulerConfiguration {
902-
if tfMap == nil {
903-
return nil
906+
func expandSchedulerConfiguration(tfList []any) *types.SchedulerConfiguration {
907+
// SchedulerConfiguration without any attributes disables the scheduler_configuration.
908+
// If an empty block is specified, the scheduler_configuration is enabled with default values.
909+
if tfList[0] == nil {
910+
return &types.SchedulerConfiguration{
911+
MaxConcurrentRuns: aws.Int32(15), // default
912+
QueueTimeoutMinutes: aws.Int32(360), // default
913+
}
904914
}
905915

906916
apiObject := &types.SchedulerConfiguration{}
917+
m := tfList[0].(map[string]any)
907918

908-
if v, ok := tfMap["max_concurrent_runs"].(int); ok {
919+
if v, ok := m["max_concurrent_runs"].(int); ok && v != 0 {
909920
apiObject.MaxConcurrentRuns = aws.Int32(int32(v))
910921
}
911922

912-
if v, ok := tfMap["queue_timeout_minutes"].(int); ok {
923+
if v, ok := m["queue_timeout_minutes"].(int); ok && v != 0 {
913924
apiObject.QueueTimeoutMinutes = aws.Int32(int32(v))
914925
}
915926

0 commit comments

Comments
 (0)