Skip to content

Commit ec9f644

Browse files
Merge pull request #4819 from nhsuk/service_connect_task_definition_configuration
Add service connect configuration for ECS deployment to task definition
2 parents b5b7151 + 2de8f03 commit ec9f644

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

terraform/app/ecs.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ module "web_service" {
5858
maximum_replica_count = var.maximum_web_replicas
5959
environment = var.environment
6060
server_type = "web"
61+
service_connect_config = {
62+
namespace = "TBD"
63+
services = [
64+
{
65+
port_name = "web-port"
66+
discovery_name = "web"
67+
port = 4000
68+
dns_name = "web"
69+
}
70+
]
71+
}
6172

6273
depends_on = [
6374
aws_iam_role.ecs_deploy,
@@ -97,6 +108,17 @@ module "sidekiq_service" {
97108
cluster_name = aws_ecs_cluster.cluster.name
98109
environment = var.environment
99110
server_type = "sidekiq"
111+
service_connect_config = {
112+
namespace = "TBD"
113+
services = [
114+
{
115+
port_name = "sidekiq-port"
116+
discovery_name = "sidekiq"
117+
port = 4000
118+
dns_name = "sidekiq"
119+
}
120+
]
121+
}
100122

101123
depends_on = [
102124
aws_rds_cluster_instance.core,

terraform/app/modules/ecs_service/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ resource "aws_ecs_task_definition" "this" {
9595
readonlyRootFileSystem = true
9696
portMappings = [
9797
{
98+
name = var.service_connect_config != null && length(var.service_connect_config.services) > 0 ? var.service_connect_config.services[0].port_name : null
9899
containerPort = 4000
99100
hostPort = 4000
101+
protocol = "tcp"
100102
}
101103
]
102104
environment = concat(var.task_config.environment, [{ name = "SERVER_TYPE", value = var.server_type }])

terraform/app/modules/ecs_service/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ variable "network_params" {
8989
nullable = false
9090
}
9191

92+
variable "service_connect_config" {
93+
type = object({
94+
namespace = string
95+
services = list(object({
96+
port_name = string
97+
discovery_name = string
98+
port = number
99+
dns_name = string
100+
}))
101+
})
102+
description = "Service Connect configuration for the ECS service. If this is not set, the service will not use Service Connect."
103+
default = null
104+
nullable = true
105+
}
106+
92107
variable "loadbalancer" {
93108
type = object({
94109
target_group_blue = string

0 commit comments

Comments
 (0)