diff --git a/infrastructure/cloud/environments/sandbox/webapp.tf b/infrastructure/cloud/environments/sandbox/webapp.tf index 595c915c..2f918717 100644 --- a/infrastructure/cloud/environments/sandbox/webapp.tf +++ b/infrastructure/cloud/environments/sandbox/webapp.tf @@ -1,5 +1,3 @@ - - module "security" { source = "../../modules/security" environment = var.environment @@ -17,15 +15,19 @@ module "storage" { depends_on = [module.security] } -module "container" { - source = "../../modules/container" - environment = var.environment - app_name = var.app_name - depends_on = [module.security, module.networking] -} - module "networking" { source = "../../modules/networking" environment = var.environment app_name = var.app_name } + +module "container" { + source = "../../modules/container" + environment = var.environment + app_name = var.app_name + ecs_task_execution_iam_role_arn = module.security.ecs_task_execution_iam_role_arn + subnet_private_id = module.networking.subnet_private_id + ecs_sg_id = module.networking.ecs_sg_id + lb_listener = module.networking.lb_listener + lb_tg_arn = module.networking.lb_tg_arn +} diff --git a/infrastructure/cloud/modules/container/ecs.tf b/infrastructure/cloud/modules/container/ecs.tf index 07332a2d..341e4613 100644 --- a/infrastructure/cloud/modules/container/ecs.tf +++ b/infrastructure/cloud/modules/container/ecs.tf @@ -27,8 +27,8 @@ resource "aws_ecs_task_definition" "ecs_task_definition" { } ]) - execution_role_arn = module.security.ecs_task_execution_iam_role_arn - task_role_arn = module.security.ecs_task_execution_iam_role_arn + execution_role_arn = var.ecs_task_execution_iam_role_arn + task_role_arn = var.ecs_task_execution_iam_role_arn } resource "aws_ecs_service" "ecs_service" { @@ -39,16 +39,16 @@ resource "aws_ecs_service" "ecs_service" { desired_count = 1 network_configuration { - subnets = module.networking.subnet_private_id - security_groups = [module.networking.ecs_sg_id] + subnets = var.subnet_private_id + security_groups = [var.ecs_sg_id] assign_public_ip = false } load_balancer { - target_group_arn = module.networking.lb_tg_arn + target_group_arn = var.lb_tg_arn container_name = "${var.app_name}-container-${var.environment}" container_port = 80 } - depends_on = [module.networking.lb_listener] + depends_on = [var.lb_listener] } diff --git a/infrastructure/cloud/modules/container/outputs.tf b/infrastructure/cloud/modules/container/outputs.tf index 2c0a2b56..3f7af474 100644 --- a/infrastructure/cloud/modules/container/outputs.tf +++ b/infrastructure/cloud/modules/container/outputs.tf @@ -1,4 +1,3 @@ output "ecr_url" { - description = "The ECR URL." - value = try(aws_ecr_repository.ecr_repository.repository_url, "") + value = try(aws_ecr_repository.ecr_repository.repository_url, "") } diff --git a/infrastructure/cloud/modules/container/variables.tf b/infrastructure/cloud/modules/container/variables.tf index bdcca553..5a06d4a2 100644 --- a/infrastructure/cloud/modules/container/variables.tf +++ b/infrastructure/cloud/modules/container/variables.tf @@ -7,3 +7,23 @@ variable "app_name" { description = "The name of the application" type = string } + +variable "ecs_task_execution_iam_role_arn" { + description = "ECS Task Execution IAM Role ARN" +} + +variable "subnet_private_id" { + description = "Private Subnet ID" +} + +variable "ecs_sg_id" { + description = "ECS Security Group ID" +} + +variable "lb_tg_arn" { + description = "Load Balancer Target Group ARN" +} + +variable "lb_listener" { + description = "Load Balancer Listener" +} diff --git a/infrastructure/cloud/modules/networking/outputs.tf b/infrastructure/cloud/modules/networking/outputs.tf index 5138f36a..ef436df6 100644 --- a/infrastructure/cloud/modules/networking/outputs.tf +++ b/infrastructure/cloud/modules/networking/outputs.tf @@ -1,19 +1,15 @@ output "subnet_private_id" { - description = "Private Subnet ID" - value = aws_subnet.private[*].id + value = aws_subnet.private[*].id } output "ecs_sg_id" { - description = "ECS Security Group ID" - value = aws_security_group.ecs_security_group.id + value = aws_security_group.ecs_security_group.id } output "lb_tg_arn" { - description = "Load Balancer Target Group ARN" - value = aws_lb_target_group.lb_target_group.arn + value = aws_lb_target_group.lb_target_group.arn } output "lb_listener" { - description = "Load Balancer Listener" - value = aws_lb_listener.lb_listener + value = aws_lb_listener.lb_listener }