|
| 1 | +# tui.dev |
| 2 | + |
| 3 | +module "tui" { |
| 4 | + source = "terraform-aws-modules/ecs/aws//modules/service" |
| 5 | + |
| 6 | + name = "tui" |
| 7 | + cluster_arn = aws_ecs_cluster.internal.arn |
| 8 | + assign_public_ip = false |
| 9 | + launch_type = "FARGATE" |
| 10 | + |
| 11 | + volume = { |
| 12 | + tui_shared = { |
| 13 | + efs_volume_configuration = { |
| 14 | + file_system_id = data.terraform_remote_state.base.outputs.shared_efs |
| 15 | + root_directory = "/tui" |
| 16 | + } |
| 17 | + |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + cpu = 256 # 0.25 vCPU |
| 22 | + memory = 512 |
| 23 | + desired_count = 1 |
| 24 | + container_definitions = { |
| 25 | + tui = { |
| 26 | + cpu = 256 |
| 27 | + memory = 512 |
| 28 | + image = var.gromit_image |
| 29 | + command = ["--textlogs=false", "policy", "serve", "--save=/shared", "--port=:80"] |
| 30 | + |
| 31 | + environment = [] |
| 32 | + secrets = [ |
| 33 | + { name = "CREDENTIALS", valueFrom = aws_ssm_parameter.tui_credentials.arn } |
| 34 | + ] |
| 35 | + port_mappings = [ |
| 36 | + { |
| 37 | + name = "tui" |
| 38 | + containerPort = 80 |
| 39 | + hostPort = 80 |
| 40 | + protocol = "tcp" |
| 41 | + } |
| 42 | + ] |
| 43 | + mount_points = [ |
| 44 | + { |
| 45 | + sourceVolume = "tui_shared" |
| 46 | + containerPath = "/shared" |
| 47 | + } |
| 48 | + ] |
| 49 | + health_check = { |
| 50 | + command = ["CMD-SHELL", "curl -f http://localhost/ping || exit 1"] |
| 51 | + interval = 300 |
| 52 | + timeout = 5 |
| 53 | + retries = 3 |
| 54 | + startPeriod = 30 |
| 55 | + } |
| 56 | + log_configuration = { |
| 57 | + logDriver = "awslogs" |
| 58 | + options = { |
| 59 | + awslogs-group = "internal" |
| 60 | + awslogs-region = "eu-central-1" |
| 61 | + awslogs-stream-prefix = "tui" |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + subnet_ids = data.terraform_remote_state.base.outputs.vpc.public_subnets |
| 67 | + load_balancer = { |
| 68 | + service = { |
| 69 | + target_group_arn = aws_lb_target_group.tui.arn |
| 70 | + container_name = "tui" |
| 71 | + container_port = 80 |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + create_task_exec_iam_role = false |
| 76 | + create_task_exec_policy = false |
| 77 | + task_exec_iam_role_arn = aws_iam_role.ter.arn |
| 78 | + create_security_group = false |
| 79 | + security_group_ids = [aws_security_group.tui.id] |
| 80 | +} |
| 81 | + |
| 82 | +resource "aws_security_group" "tui" { |
| 83 | + name = "tui" |
| 84 | + description = "EFS, http" |
| 85 | + vpc_id = data.terraform_remote_state.base.outputs.vpc.id |
| 86 | + |
| 87 | + egress { |
| 88 | + from_port = 0 |
| 89 | + to_port = 0 |
| 90 | + protocol = "-1" |
| 91 | + cidr_blocks = ["0.0.0.0/0"] |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +resource "aws_vpc_security_group_ingress_rule" "http" { |
| 96 | + security_group_id = aws_security_group.tui.id |
| 97 | + cidr_ipv4 = "0.0.0.0/0" |
| 98 | + from_port = 80 |
| 99 | + to_port = 80 |
| 100 | + ip_protocol = "tcp" |
| 101 | +} |
| 102 | + |
| 103 | +resource "aws_vpc_security_group_ingress_rule" "efs_tui" { |
| 104 | + security_group_id = aws_security_group.tui.id |
| 105 | + cidr_ipv4 = data.terraform_remote_state.base.outputs.vpc.cidr |
| 106 | + from_port = 2049 |
| 107 | + to_port = 2049 |
| 108 | + ip_protocol = "tcp" |
| 109 | +} |
| 110 | + |
| 111 | +resource "aws_lb_target_group" "tui" { |
| 112 | + name = "tui" |
| 113 | + port = 80 |
| 114 | + protocol = "HTTP" |
| 115 | + target_type = "ip" |
| 116 | + vpc_id = data.terraform_remote_state.base.outputs.vpc.id |
| 117 | +} |
| 118 | + |
| 119 | +resource "aws_lb" "tui" { |
| 120 | + name = "tui" |
| 121 | + internal = false |
| 122 | + load_balancer_type = "application" |
| 123 | + security_groups = [aws_security_group.tui.id] |
| 124 | + subnets = data.terraform_remote_state.base.outputs.vpc.public_subnets |
| 125 | + |
| 126 | + # FIXME: enable before making public |
| 127 | + enable_deletion_protection = false |
| 128 | + |
| 129 | + access_logs { |
| 130 | + bucket = data.terraform_remote_state.base.outputs.assets |
| 131 | + prefix = "tui-lb" |
| 132 | + enabled = true |
| 133 | + } |
| 134 | + |
| 135 | + connection_logs { |
| 136 | + bucket = data.terraform_remote_state.base.outputs.assets |
| 137 | + prefix = "tui-lb" |
| 138 | + enabled = true |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +resource "aws_lb_listener" "tui" { |
| 143 | + load_balancer_arn = aws_lb.tui.arn |
| 144 | + port = "80" |
| 145 | + protocol = "HTTP" |
| 146 | + default_action { |
| 147 | + type = "forward" |
| 148 | + target_group_arn = aws_lb_target_group.tui.arn |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +resource "aws_route53_record" "tui" { |
| 153 | + zone_id = data.terraform_remote_state.base.outputs.dns.zone_id |
| 154 | + |
| 155 | + name = "tui.internal" |
| 156 | + type = "CNAME" |
| 157 | + ttl = "300" |
| 158 | + |
| 159 | + records = [aws_lb.tui.dns_name] |
| 160 | +} |
0 commit comments