Skip to content

Commit

Permalink
fix: Add nil check for empty blocks to fix crashes for aws_ecs_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
acwwat committed Mar 13, 2024
1 parent 331d948 commit 008e409
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/36341.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecs_cluster: Add nil checks for the `configuration`, `execute_command_configuration`, and `log_configuration` blocks to prevent provider crashes when empty blocks are supplied
```
7 changes: 4 additions & 3 deletions internal/service/ecs/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func ResourceCluster() *schema.Resource {
"logging": {
Type: schema.TypeString,
Optional: true,
Default: ecs.ExecuteCommandLoggingDefault,
ValidateFunc: validation.StringInSlice(ecs.ExecuteCommandLogging_Values(), false),
},
},
Expand Down Expand Up @@ -576,7 +577,7 @@ func flattenClusterConfigurationExecuteCommandConfigurationLogConfiguration(apiO
}

func expandClusterConfiguration(nc []interface{}) *ecs.ClusterConfiguration {
if len(nc) == 0 {
if len(nc) == 0 || nc[0] == nil {
return &ecs.ClusterConfiguration{}
}
raw := nc[0].(map[string]interface{})
Expand All @@ -590,7 +591,7 @@ func expandClusterConfiguration(nc []interface{}) *ecs.ClusterConfiguration {
}

func expandClusterConfigurationExecuteCommandConfiguration(nc []interface{}) *ecs.ExecuteCommandConfiguration {
if len(nc) == 0 {
if len(nc) == 0 || nc[0] == nil {
return &ecs.ExecuteCommandConfiguration{}
}
raw := nc[0].(map[string]interface{})
Expand All @@ -612,7 +613,7 @@ func expandClusterConfigurationExecuteCommandConfiguration(nc []interface{}) *ec
}

func expandClusterConfigurationExecuteCommandLogConfiguration(nc []interface{}) *ecs.ExecuteCommandLogConfiguration {
if len(nc) == 0 {
if len(nc) == 0 || nc[0] == nil {
return &ecs.ExecuteCommandLogConfiguration{}
}
raw := nc[0].(map[string]interface{})
Expand Down

0 comments on commit 008e409

Please sign in to comment.