-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored container definitions out of module (#69)
* Refactored container definitions out of module * Turn cloudwatch logging optional Reason: if the creation of cloudwatch logs happens outside of this module, then that can be passed into the container definitions variable * chore: Update documentation * Turn cloudwatch logging optional * Turn cloudwatch logging optional - fix Despite turning cloudwatch group resource as optional, the module will still expect a log group arn * Lint fixes * Remove square brackets as input is a list * Revert container name to original * Comment about 'target_type' for Fargate * Update target group health check parameters * Documentation update
- Loading branch information
Abdul Wahid
authored
Apr 12, 2023
1 parent
98c991c
commit 9909245
Showing
13 changed files
with
379 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ terraform { | |
required_version = ">= 1.0.11" | ||
|
||
required_providers { | ||
aws = ">= 4.0.0" | ||
aws = ">= 4.6.0" | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
terraform { | ||
required_version = ">= 1.0.11" | ||
|
||
required_providers { | ||
aws = ">= 4.8.0" | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
##### | ||
# VPC and subnets | ||
##### | ||
data "aws_vpc" "default" { | ||
default = true | ||
} | ||
|
||
data "aws_subnets" "all" { | ||
filter { | ||
name = "vpc-id" | ||
values = [data.aws_vpc.default.id] | ||
} | ||
} | ||
|
||
##### | ||
# ECS cluster and fargate | ||
##### | ||
resource "aws_ecs_cluster" "cluster" { | ||
name = "ecs-external-container-definitions-test" | ||
|
||
setting { | ||
name = "containerInsights" | ||
value = "disabled" | ||
} | ||
} | ||
|
||
resource "aws_ecs_cluster_capacity_providers" "cluster" { | ||
cluster_name = aws_ecs_cluster.cluster.name | ||
|
||
capacity_providers = ["FARGATE_SPOT", "FARGATE"] | ||
|
||
default_capacity_provider_strategy { | ||
capacity_provider = "FARGATE_SPOT" | ||
} | ||
} | ||
|
||
module "container_1" { | ||
source = "cloudposse/ecs-container-definition/aws" | ||
version = "0.58.2" | ||
|
||
container_name = "example" | ||
container_image = "hello-world:latest" | ||
|
||
port_mappings = [ | ||
{ | ||
containerPort = 80 | ||
hostPort = 80 | ||
protocol = "tcp" | ||
} | ||
] | ||
|
||
} | ||
|
||
module "container_2" { | ||
source = "cloudposse/ecs-container-definition/aws" | ||
version = "0.58.2" | ||
|
||
container_name = "example-2" | ||
container_image = "hello-world:latest" | ||
|
||
port_mappings = [ | ||
{ | ||
containerPort = 81 | ||
hostPort = 81 | ||
protocol = "udp" | ||
} | ||
] | ||
|
||
container_depends_on = [ | ||
{ | ||
containerName = "example" | ||
condition = "START" | ||
} | ||
] | ||
} | ||
|
||
##### | ||
# ALB | ||
##### | ||
module "alb" { | ||
source = "umotif-public/alb/aws" | ||
version = "~> 2.0" | ||
|
||
name_prefix = "alb-example" | ||
load_balancer_type = "application" | ||
internal = false | ||
vpc_id = data.aws_vpc.default.id | ||
subnets = data.aws_subnets.all.ids | ||
} | ||
|
||
resource "aws_lb_listener" "alb_80" { | ||
load_balancer_arn = module.alb.arn | ||
port = "80" | ||
protocol = "HTTP" | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = module.fargate.target_group_arn[0] | ||
} | ||
} | ||
|
||
##### | ||
# Security Group Config | ||
##### | ||
resource "aws_security_group_rule" "alb_ingress_80" { | ||
security_group_id = module.alb.security_group_id | ||
type = "ingress" | ||
protocol = "tcp" | ||
from_port = 80 | ||
to_port = 80 | ||
cidr_blocks = ["0.0.0.0/0"] | ||
ipv6_cidr_blocks = ["::/0"] | ||
} | ||
|
||
resource "aws_security_group_rule" "task_ingress_80" { | ||
security_group_id = module.fargate.service_sg_id | ||
type = "ingress" | ||
protocol = "tcp" | ||
from_port = 80 | ||
to_port = 80 | ||
source_security_group_id = module.alb.security_group_id | ||
} | ||
|
||
module "fargate" { | ||
source = "../../" | ||
|
||
name_prefix = "ecs-fargate-example-2" | ||
vpc_id = data.aws_vpc.default.id | ||
private_subnet_ids = data.aws_subnets.all.ids | ||
|
||
cluster_id = aws_ecs_cluster.cluster.id | ||
|
||
container_definitions = jsonencode([ | ||
module.container_1.json_map_object, | ||
module.container_2.json_map_object | ||
]) | ||
|
||
capacity_provider_strategy = [ | ||
{ | ||
capacity_provider = "FARGATE_SPOT", | ||
weight = 100 | ||
} | ||
] | ||
|
||
enable_deployment_circuit_breaker = true | ||
enable_deployment_circuit_breaker_rollback = true | ||
|
||
health_check = { | ||
port = "traffic-port" | ||
path = "/" | ||
} | ||
|
||
target_groups = [ | ||
{ | ||
container_name = "example" | ||
target_group_name = "tg-example" | ||
container_port = 80 | ||
} | ||
] | ||
|
||
} | ||
|
||
output "first_container_json" { | ||
description = "Container definition in JSON format" | ||
value = module.container_1.json_map_encoded_list | ||
} | ||
|
||
output "second_container_json" { | ||
description = "Container definition in JSON format" | ||
value = module.container_2.json_map_encoded_list | ||
} | ||
|
||
output "task_definition_container_definitions" { | ||
description = "A list of container definitions" | ||
value = module.fargate.task_definition_container_definitions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ terraform { | |
required_version = ">= 1.0.11" | ||
|
||
required_providers { | ||
aws = ">= 4.0.0" | ||
aws = ">= 4.8.0" | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ terraform { | |
required_version = ">= 1.0.11" | ||
|
||
required_providers { | ||
aws = ">= 4.0.0" | ||
aws = ">= 4.6.0" | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ terraform { | |
required_version = ">= 1.0.11" | ||
|
||
required_providers { | ||
aws = ">= 4.0.0" | ||
aws = ">= 4.6.0" | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.