-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mateuscacabuenaPUCRS/T3
T3 - Finished
- Loading branch information
Showing
26 changed files
with
789 additions
and
60 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,53 @@ | ||
module "alb" { | ||
source = "terraform-aws-modules/alb/aws" | ||
|
||
name = "${local.name}-alb" | ||
|
||
load_balancer_type = "application" | ||
|
||
vpc_id = module.vpc.vpc_id | ||
subnets = module.vpc.public_subnets | ||
|
||
security_groups = [aws_security_group.security_group.id] | ||
|
||
enable_deletion_protection = false | ||
|
||
listeners = { | ||
http = { | ||
port = local.container_port | ||
protocol = "HTTP" | ||
|
||
forward = { | ||
target_group_key = "ecs" | ||
} | ||
} | ||
} | ||
|
||
target_groups = { | ||
ecs = { | ||
backend_protocol = "HTTP" | ||
backend_port = local.container_port | ||
target_type = "ip" | ||
deregistration_delay = 5 | ||
load_balancing_cross_zone_enabled = true | ||
|
||
health_check = { | ||
enabled = true | ||
healthy_threshold = 5 | ||
interval = 30 | ||
matcher = "200" | ||
path = "/" | ||
port = "traffic-port" | ||
protocol = "HTTP" | ||
timeout = 5 | ||
unhealthy_threshold = 2 | ||
} | ||
|
||
# Theres nothing to attach here in this definition. Instead, | ||
# ECS will attach the IPs of the tasks to this target group | ||
create_attachment = false | ||
} | ||
} | ||
|
||
tags = local.tags | ||
} |
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,3 @@ | ||
data "aws_availability_zones" "available" {} | ||
|
||
data "aws_caller_identity" "current" {} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resource "aws_ecr_repository" "ecr" { | ||
name = "${local.name}-ecr" | ||
} |
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,53 @@ | ||
resource "aws_ecs_cluster" "ecs_cluster" { | ||
name = "${local.name}-ecs-cluster" | ||
} | ||
|
||
resource "aws_ecs_task_definition" "task" { | ||
family = "${local.name}-ecs-task" | ||
network_mode = "awsvpc" | ||
requires_compatibilities = ["FARGATE"] | ||
|
||
cpu = "1024" | ||
memory = "2048" | ||
|
||
container_definitions = jsonencode([{ | ||
name = local.container_name | ||
cpu = 512 | ||
memory = 1024 | ||
essential = true | ||
image = "${local.user_id}.dkr.ecr.${local.region}.amazonaws.com/${local.container_name}:latest" | ||
|
||
portMappings = [{ | ||
containerPort = local.container_port | ||
hostPort = local.container_port | ||
protocol = "tcp" | ||
}] | ||
}]) | ||
|
||
execution_role_arn = "arn:aws:iam::${local.user_id}:role/LabRole" | ||
task_role_arn = "arn:aws:iam::${local.user_id}:role/LabRole" | ||
|
||
tags = local.tags | ||
} | ||
|
||
resource "aws_ecs_service" "ecs_service" { | ||
name = "${local.name}-ecs-service" | ||
cluster = aws_ecs_cluster.ecs_cluster.id | ||
task_definition = aws_ecs_task_definition.task.arn | ||
desired_count = 1 | ||
launch_type = "FARGATE" | ||
|
||
network_configuration { | ||
subnets = module.vpc.public_subnets | ||
security_groups = [aws_security_group.security_group.id] | ||
assign_public_ip = true | ||
} | ||
|
||
load_balancer { | ||
target_group_arn = module.alb.target_groups["ecs"].arn | ||
container_name = local.container_name | ||
container_port = local.container_port | ||
} | ||
|
||
tags = local.tags | ||
} |
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,47 @@ | ||
module "ecs" { | ||
source = "terraform-aws-modules/ecs/aws" | ||
|
||
cluster_name = "${local.name}-ecs-cluster" | ||
|
||
services = { | ||
"${local.container_name}" = { | ||
cpu = 1024 | ||
memory = 4096 | ||
|
||
# Container definition(s) | ||
container_definitions = { | ||
"${local.container_name}" = { | ||
cpu = 512 | ||
memory = 1024 | ||
essential = true | ||
image = "${local.user_id}.dkr.ecr.${local.region}.amazonaws.com/${local.container_name}:latest" | ||
|
||
port_mappings = [ | ||
{ | ||
containerPort = local.container_port | ||
hostPort = local.container_port | ||
protocol = "tcp" | ||
} | ||
] | ||
} | ||
} | ||
|
||
subnet_ids = module.vpc.public_subnets | ||
# subnet_ids = module.vpc.private_subnets | ||
|
||
load_balancer = { | ||
service = { | ||
target_group_arn = module.alb.target_groups["ecs"].arn | ||
container_name = local.container_name | ||
container_port = local.container_port | ||
} | ||
} | ||
|
||
# Roles attempted: LabRole, ecs.amazonaws.com/AWSServiceRoleForECS, vocareum, AdministratorAccess | ||
task_execution_role_arn = "arn:aws:iam::${local.user_id}:role/LabRole" | ||
task_role_arn = "arn:aws:iam::${local.user_id}:role/LabRole" | ||
} | ||
} | ||
|
||
tags = local.tags | ||
} |
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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
locals { | ||
region = var.region | ||
environment = var.environment | ||
name = "${local.environment}-${var.project_name}" | ||
|
||
container_name = "${local.name}-ecr" | ||
container_port = 8000 | ||
|
||
user_id = data.aws_caller_identity.current.account_id | ||
|
||
tags = { | ||
Name = local.name | ||
Example = local.name | ||
Repository = "https://github.com/terraform-aws-modules/terraform-aws-ecs" | ||
} | ||
} |
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
Oops, something went wrong.