|
| 1 | +################################################################################ |
| 2 | +# ECS Resources |
| 3 | +################################################################################ |
| 4 | +module "ecs" { |
| 5 | + source = "terraform-module/ecs/aws" |
| 6 | + version = "~> 1" |
| 7 | + |
| 8 | + name = var.name |
| 9 | + |
| 10 | + container_insights = false |
| 11 | + capacity_providers = ["FARGATE_SPOT"] |
| 12 | + |
| 13 | + default_capacity_provider_strategy = [ |
| 14 | + { |
| 15 | + capacity_provider = "FARGATE_SPOT" |
| 16 | + } |
| 17 | + ] |
| 18 | + |
| 19 | + tags = merge({ Module = "terraform-module/ecs/aws" }) |
| 20 | +} |
| 21 | + |
| 22 | +################################################################################ |
| 23 | +# LB Resources |
| 24 | +################################################################################ |
| 25 | +resource "aws_lb" "this" { |
| 26 | + name = "${var.name}-alb" |
| 27 | + internal = false |
| 28 | + |
| 29 | + load_balancer_type = "application" |
| 30 | + security_groups = [aws_security_group.alb.id] |
| 31 | + subnets = local.public_subnets |
| 32 | + enable_http2 = "true" |
| 33 | + |
| 34 | + enable_cross_zone_load_balancing = true |
| 35 | + enable_deletion_protection = false |
| 36 | + tags = { Service = "alb", AlbType = "application" } |
| 37 | +} |
| 38 | + |
| 39 | +resource "aws_security_group" "alb" { |
| 40 | + name = "${var.name}-sg-alb-${var.env}" |
| 41 | + vpc_id = var.vpc_id |
| 42 | + |
| 43 | + ingress { |
| 44 | + protocol = "tcp" |
| 45 | + from_port = 80 |
| 46 | + to_port = 80 |
| 47 | + cidr_blocks = ["0.0.0.0/0"] |
| 48 | + description = "Allow internet to access port 80 for redirect." |
| 49 | + } |
| 50 | + |
| 51 | + ingress { |
| 52 | + protocol = "tcp" |
| 53 | + from_port = 443 |
| 54 | + to_port = 443 |
| 55 | + cidr_blocks = ["0.0.0.0/0"] |
| 56 | + description = "Allow internet to communicate with services over HTTPS." |
| 57 | + } |
| 58 | + |
| 59 | + egress { |
| 60 | + # TEMP for testing, should be locked to just services protocols |
| 61 | + protocol = "-1" |
| 62 | + from_port = 0 |
| 63 | + to_port = 0 |
| 64 | + cidr_blocks = ["0.0.0.0/0"] # TODO: make sure only vpc cidr or private sunets cidrs |
| 65 | + description = "Allow internal communitcations." |
| 66 | + } |
| 67 | +} |
0 commit comments