Skip to content

Commit 153206c

Browse files
Adds support for additional containers (sidecars) (#107)
Co-authored-by: Jared Darling <[email protected]>
1 parent 7698d0b commit 153206c

File tree

3 files changed

+127
-59
lines changed

3 files changed

+127
-59
lines changed

examples/test/main.tf

+46-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
1+
locals {
2+
public_subnet_ids = [for s in module.base-network.public_subnets : s.id]
3+
private_subnet_ids = [for s in module.base-network.private_subnets : s.id]
4+
}
5+
16
module "base-network" {
2-
source = "cn-terraform/networking/aws"
3-
name_prefix = "test-networking"
4-
vpc_cidr_block = "192.168.0.0/16"
5-
availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d"]
6-
public_subnets_cidrs_per_availability_zone = ["192.168.0.0/19", "192.168.32.0/19", "192.168.64.0/19", "192.168.96.0/19"]
7-
private_subnets_cidrs_per_availability_zone = ["192.168.128.0/19", "192.168.160.0/19", "192.168.192.0/19", "192.168.224.0/19"]
7+
source = "cn-terraform/networking/aws"
8+
cidr_block = "192.168.0.0/16"
9+
10+
vpc_additional_tags = {
11+
vpc_tag1 = "tag1",
12+
vpc_tag2 = "tag2",
13+
}
14+
15+
public_subnets = {
16+
first_public_subnet = {
17+
availability_zone = "us-east-1a"
18+
cidr_block = "192.168.0.0/19"
19+
}
20+
second_public_subnet = {
21+
availability_zone = "us-east-1b"
22+
cidr_block = "192.168.32.0/19"
23+
}
24+
}
25+
26+
public_subnets_additional_tags = {
27+
public_subnet_tag1 = "tag1",
28+
public_subnet_tag2 = "tag2",
29+
}
30+
31+
private_subnets = {
32+
first_private_subnet = {
33+
availability_zone = "us-east-1a"
34+
cidr_block = "192.168.128.0/19"
35+
}
36+
second_private_subnet = {
37+
availability_zone = "us-east-1b"
38+
cidr_block = "192.168.160.0/19"
39+
}
40+
}
41+
42+
private_subnets_additional_tags = {
43+
private_subnet_tag1 = "tag1",
44+
private_subnet_tag2 = "tag2",
45+
}
846
}
947

1048
module "test" {
@@ -13,6 +51,6 @@ module "test" {
1351
vpc_id = module.base-network.vpc_id
1452
container_image = "ubuntu"
1553
container_name = "test"
16-
public_subnets_ids = module.base-network.public_subnets_ids
17-
private_subnets_ids = module.base-network.private_subnets_ids
54+
public_subnets_ids = local.public_subnet_ids
55+
private_subnets_ids = local.private_subnet_ids
1856
}

main.tf

+50-47
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,57 @@ module "ecs-cluster" {
1515
#------------------------------------------------------------------------------
1616
module "td" {
1717
source = "cn-terraform/ecs-fargate-task-definition/aws"
18-
version = "1.0.35"
18+
version = "1.0.36"
1919
# source = "../terraform-aws-ecs-fargate-task-definition"
2020

21-
name_prefix = var.name_prefix
22-
container_name = var.container_name
23-
container_image = var.container_image
24-
container_memory = var.container_memory
25-
container_memory_reservation = var.container_memory_reservation
26-
container_definition = var.container_definition
27-
port_mappings = var.port_mappings
28-
healthcheck = var.healthcheck
29-
container_cpu = var.container_cpu
30-
essential = var.essential
31-
entrypoint = var.entrypoint
32-
command = var.command
33-
working_directory = var.working_directory
34-
environment = var.environment
35-
extra_hosts = var.extra_hosts
36-
map_environment = var.map_environment
37-
environment_files = var.environment_files
38-
secrets = var.secrets
39-
readonly_root_filesystem = var.readonly_root_filesystem
40-
linux_parameters = var.linux_parameters
41-
log_configuration = var.log_configuration
42-
firelens_configuration = var.firelens_configuration
43-
mount_points = var.mount_points
44-
dns_servers = var.dns_servers
45-
dns_search_domains = var.dns_search_domains
46-
ulimits = var.ulimits
47-
repository_credentials = var.repository_credentials
48-
volumes_from = var.volumes_from
49-
links = var.links
50-
user = var.user
51-
container_depends_on = var.container_depends_on
52-
docker_labels = var.docker_labels
53-
start_timeout = var.start_timeout
54-
stop_timeout = var.stop_timeout
55-
privileged = var.privileged
56-
system_controls = var.system_controls
57-
hostname = var.hostname
58-
disable_networking = var.disable_networking
59-
interactive = var.interactive
60-
pseudo_terminal = var.pseudo_terminal
61-
docker_security_options = var.docker_security_options
21+
additional_containers = var.additional_containers
22+
command = var.command
23+
container_cpu = var.container_cpu
24+
container_definition_overrides = var.container_definition_overrides
25+
container_depends_on = var.container_depends_on
26+
container_image = var.container_image
27+
container_memory = var.container_memory
28+
container_memory_reservation = var.container_memory_reservation
29+
container_name = var.container_name
30+
disable_networking = var.disable_networking
31+
dns_search_domains = var.dns_search_domains
32+
dns_servers = var.dns_servers
33+
docker_labels = var.docker_labels
34+
docker_security_options = var.docker_security_options
35+
entrypoint = var.entrypoint
36+
environment = var.environment
37+
environment_files = var.environment_files
38+
essential = var.essential
39+
extra_hosts = var.extra_hosts
40+
firelens_configuration = var.firelens_configuration
41+
healthcheck = var.healthcheck
42+
hostname = var.hostname
43+
interactive = var.interactive
44+
links = var.links
45+
linux_parameters = var.linux_parameters
46+
log_configuration = var.log_configuration
47+
map_environment = var.map_environment
48+
mount_points = var.mount_points
49+
name_prefix = var.name_prefix
50+
port_mappings = var.port_mappings
51+
privileged = var.privileged
52+
pseudo_terminal = var.pseudo_terminal
53+
readonly_root_filesystem = var.readonly_root_filesystem
54+
repository_credentials = var.repository_credentials
55+
secrets = var.secrets
56+
start_timeout = var.start_timeout
57+
stop_timeout = var.stop_timeout
58+
system_controls = var.system_controls
59+
ulimits = var.ulimits
60+
user = var.user
61+
volumes_from = var.volumes_from
62+
working_directory = var.working_directory
6263

64+
ecs_task_execution_role_custom_policies = var.ecs_task_execution_role_custom_policies
65+
ephemeral_storage_size = var.ephemeral_storage_size
6366
permissions_boundary = var.permissions_boundary
6467
placement_constraints = var.placement_constraints_task_definition
6568
proxy_configuration = var.proxy_configuration
66-
ephemeral_storage_size = var.ephemeral_storage_size
67-
ecs_task_execution_role_custom_policies = var.ecs_task_execution_role_custom_policies
6869
volumes = var.volumes
6970

7071
tags = var.tags
@@ -75,19 +76,20 @@ module "td" {
7576
#------------------------------------------------------------------------------
7677
module "ecs-fargate-service" {
7778
source = "cn-terraform/ecs-fargate-service/aws"
78-
version = "2.0.41"
79+
version = "2.0.42"
7980
# source = "../terraform-aws-ecs-fargate-service"
8081

8182
name_prefix = var.name_prefix
8283
vpc_id = var.vpc_id
8384

84-
ecs_cluster_arn = module.ecs-cluster.aws_ecs_cluster_cluster_arn
85+
deployment_controller = var.deployment_controller
8586
deployment_maximum_percent = var.deployment_maximum_percent
8687
deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent
87-
deployment_controller = var.deployment_controller
8888
desired_count = var.desired_count
89+
ecs_cluster_arn = module.ecs-cluster.aws_ecs_cluster_cluster_arn
8990
enable_ecs_managed_tags = var.enable_ecs_managed_tags
9091
enable_execute_command = var.enable_execute_command
92+
force_new_deployment = var.force_new_deployment
9193
health_check_grace_period_seconds = var.health_check_grace_period_seconds
9294
ordered_placement_strategy = var.ordered_placement_strategy
9395
placement_constraints = var.ecs_service_placement_constraints
@@ -115,6 +117,7 @@ module "ecs-fargate-service" {
115117

116118
# Application Load Balancer
117119
custom_lb_arn = var.custom_lb_arn
120+
additional_lbs = var.additional_lbs
118121
lb_internal = var.lb_internal
119122
lb_security_groups = var.lb_security_groups
120123
lb_drop_invalid_header_fields = var.lb_drop_invalid_header_fields

variables.tf

+31-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ variable "vpc_id" {
2727
#------------------------------------------------------------------------------
2828
# AWS ECS Container Definition Variables
2929
#------------------------------------------------------------------------------
30+
variable "additional_containers" {
31+
description = "Additional container definitions (sidecars) to use for the task."
32+
default = []
33+
type = any #cloudposse/ecs-container-definition/aws
34+
}
35+
3036
variable "container_name" {
3137
type = string
3238
description = "The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, _ allowed)"
@@ -49,7 +55,7 @@ variable "container_memory_reservation" {
4955
default = 2048 # 2 GB
5056
}
5157

52-
variable "container_definition" {
58+
variable "container_definition_overrides" {
5359
type = map(any)
5460
description = "Container definition overrides which allows for extra keys or overriding existing keys."
5561
default = {}
@@ -414,7 +420,9 @@ variable "deployment_minimum_healthy_percent" {
414420
variable "deployment_controller" {
415421
description = "(Optional) Deployment controller"
416422
type = list(any)
417-
default = []
423+
default = [{
424+
type = "ECS"
425+
}]
418426
}
419427

420428
variable "desired_count" {
@@ -429,6 +437,12 @@ variable "enable_ecs_managed_tags" {
429437
default = false
430438
}
431439

440+
variable "force_new_deployment" {
441+
description = "(Optional) Enable to force a new task deployment of the service. This can be used to update tasks to use a newer Docker image with same image/tag combination (e.g. myimage:latest), roll Fargate tasks onto a newer platform version, or immediately deploy ordered_placement_strategy and placement_constraints updates."
442+
default = false
443+
type = bool
444+
}
445+
432446
variable "enable_execute_command" {
433447
description = "(Optional) Specifies whether to enable Amazon ECS Exec for the tasks within the service."
434448
type = bool
@@ -521,6 +535,19 @@ variable "custom_lb_arn" {
521535
default = null
522536
}
523537

538+
variable "additional_lbs" {
539+
default = {}
540+
description = "Additional load balancers to add to ECS service"
541+
type = map(object
542+
(
543+
{
544+
target_group_arn = string
545+
container_port = number
546+
}
547+
)
548+
)
549+
}
550+
524551
variable "lb_internal" {
525552
description = "(Optional) If true, the LB will be internal."
526553
type = bool
@@ -615,7 +642,7 @@ variable "lb_http_ports" {
615642
description = "Map containing objects with two fields, listener_port and the target_group_port to redirect HTTP requests"
616643
type = map(any)
617644
default = {
618-
default_http = {
645+
default-http = {
619646
listener_port = 80
620647
target_group_port = 80
621648
}
@@ -638,7 +665,7 @@ variable "lb_https_ports" {
638665
description = "Map containing objects with two fields, listener_port and the target_group_port to redirect HTTPS requests"
639666
type = map(any)
640667
default = {
641-
default_http = {
668+
default-https = {
642669
listener_port = 443
643670
target_group_port = 443
644671
}

0 commit comments

Comments
 (0)