# Set up data source for CloudFormation exports data "aws_cloudformation_export" "vpc_id" { name = "${var.environment_name}:VpcId" } data "aws_cloudformation_export" "cluster_name" { name = "${var.environment_name}:ClusterName" } data "aws_cloudformation_export" "container_security_group" { name = "${var.environment_name}:ContainerSecurityGroup" } data "aws_cloudformation_export" "private_subnet_one" { name = "${var.environment_name}:PrivateSubnetOne" } data "aws_cloudformation_export" "private_subnet_two" { name = "${var.environment_name}:PrivateSubnetTwo" } data "aws_cloudformation_export" "public_listener" { name = "${var.environment_name}:PublicListener" } # Resources # Log group resource "aws_cloudwatch_log_group" "log_group" { name = var.log_group_name retention_in_days = 7 } # Service Registry resource "aws_service_discovery_service" "service" { name = var.service_name namespace_id = var.namespace_id dns_config { namespace_id = var.namespace_id dns_records { ttl = 10 type = "A" } routing_policy = "WEIGHTED" } health_check_custom_config { failure_threshold = 1 } } # ALB Listener and target group resource "aws_lb_target_group" "target_group" { port = 80 protocol = "HTTP" target_type = "ip" vpc_id = data.aws_cloudformation_export.vpc_id.value health_check { interval = 10 path = "/ping" protocol = "HTTP" timeout = 5 healthy_threshold = 2 matcher = "200-299" } } resource "aws_lb_listener_rule" "listener_rule" { listener_arn = data.aws_cloudformation_export.public_listener.value priority = var.priority condition { path_pattern { values = [ var.path ] } } action { type = "forward" target_group_arn = aws_lb_target_group.target_group.arn } } # Task definition resource "aws_iam_role" "execution_role" { assume_role_policy = <