Skip to content

Commit

Permalink
Added timeout configuration for ECS Service Connect
Browse files Browse the repository at this point in the history
  • Loading branch information
O327903 committed Feb 9, 2024
1 parent 0c0ded0 commit f8ba1b6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changelog/35684.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
```release-note:enhancement
resource/aws_ecs_service: Add TLS support for ECS Service Connect
resource/aws_ecs_service: Add timeout configuration for ECS Service Connect
```
38 changes: 38 additions & 0 deletions internal/service/ecs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,25 @@ func ResourceService() *schema.Resource {
},
},
},
"timeout": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"idle_timeout_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 2147483647),
},
"per_request_timeout_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 2147483647),
},
},
},
},
},
},
},
Expand Down Expand Up @@ -1475,12 +1494,31 @@ func expandServices(srv []interface{}) []*ecs.ServiceConnectService {
config.Tls = expandTls(v)
}

if v, ok := raw["timeout"].([]interface{}); ok && len(v) > 0 {
config.Timeout = expandTimeout(v)
}

out = append(out, &config)
}

return out
}

func expandTimeout(timeout []interface{}) *ecs.TimeoutConfiguration {
if len(timeout) == 0 {
return nil
}
raw := timeout[0].(map[string]interface{})
timeoutConfig := &ecs.TimeoutConfiguration{}
if v, ok := raw["idle_timeout_seconds"].(int); ok {
timeoutConfig.IdleTimeoutSeconds = aws.Int64(int64(v))
}
if v, ok := raw["per_request_timeout_seconds"].(int); ok {
timeoutConfig.PerRequestTimeoutSeconds = aws.Int64(int64(v))
}
return timeoutConfig
}

func expandTls(tls []interface{}) *ecs.ServiceConnectTlsConfiguration {
if len(tls) == 0 {
return nil
Expand Down
9 changes: 7 additions & 2 deletions internal/service/ecs/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4320,9 +4320,10 @@ resource "aws_ecs_task_definition" "test" {
"portMappings": [
{
"hostPort": 0,
"protocol": "tcp",
"appProtocol": "http",
"containerPort": 27017,
"name": "tf-test"
"name": "tf-test",
"protocol": "tcp"
}
]
}
Expand Down Expand Up @@ -4364,6 +4365,10 @@ resource "aws_ecs_service" "test" {
kms_key = aws_kms_key.test.arn
role_arn = aws_iam_role.test.arn
}
timeout {
idle_timeout_seconds = 120
per_request_timeout_seconds = 60
}
}
}
}
Expand Down

0 comments on commit f8ba1b6

Please sign in to comment.