|
1 | 1 | data "aws_caller_identity" "this" {}
|
2 |
| -data "aws_region" "this" {} |
| 2 | + |
| 3 | +locals { |
| 4 | + name = format("%s-%s-%s", var.prefix, var.environment, var.name) |
| 5 | +} |
3 | 6 |
|
4 | 7 | /* -------------------------------------------------------------------------- */
|
5 | 8 | /* VPC */
|
@@ -69,72 +72,182 @@ module "fargate_cluster" {
|
69 | 72 | /* -------------------------------------------------------------------------- */
|
70 | 73 | /* Service */
|
71 | 74 | /* -------------------------------------------------------------------------- */
|
72 |
| -module "service_api" { |
| 75 | +module "api_service" { |
73 | 76 | source = "../.."
|
74 | 77 |
|
75 |
| - # Generics |
76 | 78 | prefix = var.prefix
|
77 | 79 | environment = var.environment
|
78 |
| - name = format("%s-service-api", var.name) |
| 80 | + name = format("%s-api-service", var.name) |
79 | 81 |
|
80 |
| - # IAM Role |
81 |
| - is_create_iam_role = true |
| 82 | + # ECS service |
| 83 | + task_cpu = 1024 |
| 84 | + task_memory = 2048 |
| 85 | + ecs_cluster_name = module.fargate_cluster.ecs_cluster_name |
| 86 | + service_discovery_namespace = module.fargate_cluster.service_discovery_namespace |
| 87 | + is_enable_execute_command = true |
| 88 | + application_subnet_ids = module.vpc.private_subnet_ids |
| 89 | + security_groups = [ |
| 90 | + module.fargate_cluster.ecs_task_security_group_id |
| 91 | + ] |
82 | 92 | additional_ecs_task_role_policy_arns = [
|
83 | 93 | "arn:aws:iam::aws:policy/AmazonSSMFullAccess"
|
84 | 94 | ]
|
85 | 95 |
|
86 | 96 | # ALB
|
87 |
| - is_attach_service_with_lb = true |
88 |
| - alb_listener_arn = module.fargate_cluster.alb_listener_http_arn |
89 |
| - alb_host_header = null |
90 |
| - alb_paths = ["/*"] |
91 |
| - alb_priority = "100" |
92 |
| - vpc_id = module.vpc.vpc_id |
| 97 | + alb_listener_arn = module.fargate_cluster.alb_listener_http_arn |
| 98 | + alb_host_header = null |
| 99 | + alb_paths = ["/*"] |
| 100 | + alb_priority = "100" |
| 101 | + vpc_id = module.vpc.vpc_id |
93 | 102 | health_check = {
|
94 | 103 | interval = 20,
|
95 |
| - path = "/", |
| 104 | + path = "", |
96 | 105 | timeout = 10,
|
97 | 106 | healthy_threshold = 3,
|
98 | 107 | unhealthy_threshold = 3,
|
99 | 108 | matcher = "200,201,204"
|
100 | 109 | }
|
101 | 110 |
|
102 |
| - # Logging |
103 | 111 | is_create_cloudwatch_log_group = true
|
104 | 112 |
|
105 |
| - # Task definition |
106 |
| - service_info = { |
107 |
| - cpu_allocation = 256, |
108 |
| - mem_allocation = 512, |
109 |
| - port = 80, |
110 |
| - image = "nginx" |
111 |
| - mount_points = [] |
| 113 | + container = { |
| 114 | + main_container = { |
| 115 | + name = format("%s-api-service", local.name) |
| 116 | + image = "nginx" |
| 117 | + cpu = 128 |
| 118 | + memory = 256 |
| 119 | + is_attach_to_lb = true |
| 120 | + port_mappings = [ |
| 121 | + { |
| 122 | + # If a container has multiple ports, index 0 will be used for target group |
| 123 | + host_port = 80 |
| 124 | + container_port = 80 |
| 125 | + protocol = "tcp" |
| 126 | + } |
| 127 | + ] |
| 128 | + entry_point = [] |
| 129 | + command = [] |
| 130 | + } |
| 131 | + side_container = { |
| 132 | + name = format("%s-nginx", local.name) |
| 133 | + image = "tutum/dnsutils" |
| 134 | + cpu = 128 |
| 135 | + memory = 256 |
| 136 | + port_mappings = [ |
| 137 | + { |
| 138 | + host_port = 443 |
| 139 | + container_port = 443 |
| 140 | + protocol = "tcp" |
| 141 | + }, |
| 142 | + ] |
| 143 | + } |
112 | 144 | }
|
113 |
| - is_application_scratch_volume_enabled = true |
114 |
| - |
115 |
| - # Secret and Env |
116 | 145 | environment_variables = {
|
117 |
| - THIS_IS_ENV = "ENV1", |
118 |
| - THIS_IS_ENVV = "ENVV", |
| 146 | + main_container = { |
| 147 | + THIS_IS_ENV = "ENV1", |
| 148 | + THIS_IS_ENVV = "ENVV", |
| 149 | + } |
| 150 | + side_container = { |
| 151 | + XXXX = "XXXX", |
| 152 | + XXXXX = "XXXXX", |
| 153 | + } |
119 | 154 | }
|
120 |
| - # WARNING Secret should not be in plain text |
121 | 155 | secret_variables = {
|
122 |
| - THIS_IS_SECRET = "1xxxxx", |
123 |
| - THIS_IS_SECRETT = "2xxxxx", |
124 |
| - THIS_IS_SECRETTT = "3xxxxx", |
125 |
| - THIS_IS_SECRETTTTT = "4xxxxx", |
126 |
| - THIS_IS_SECRETTTTTT = "5xxxxx", |
127 |
| - THIS_IS_SECRETTTTTTT = "6xxxxx", |
| 156 | + main_container = { |
| 157 | + THIS_IS_SECRET = "1xxxxx", |
| 158 | + THIS_IS_SECRETT = "2xxxxx", |
| 159 | + } |
128 | 160 | }
|
129 | 161 |
|
| 162 | + tags = var.custom_tags |
| 163 | +} |
| 164 | + |
| 165 | +module "payment_service" { |
| 166 | + source = "../.." |
| 167 | + |
| 168 | + prefix = var.prefix |
| 169 | + environment = var.environment |
| 170 | + name = format("%s-api-service", var.name) |
| 171 | + |
130 | 172 | # ECS service
|
| 173 | + task_cpu = 1024 |
| 174 | + task_memory = 2048 |
131 | 175 | ecs_cluster_name = module.fargate_cluster.ecs_cluster_name
|
132 | 176 | service_discovery_namespace = module.fargate_cluster.service_discovery_namespace
|
133 | 177 | is_enable_execute_command = true
|
134 | 178 | application_subnet_ids = module.vpc.private_subnet_ids
|
135 | 179 | security_groups = [
|
136 | 180 | module.fargate_cluster.ecs_task_security_group_id
|
137 | 181 | ]
|
| 182 | + additional_ecs_task_role_policy_arns = [ |
| 183 | + "arn:aws:iam::aws:policy/AmazonSSMFullAccess" |
| 184 | + ] |
| 185 | + |
| 186 | + # ALB |
| 187 | + alb_listener_arn = module.fargate_cluster.alb_listener_http_arn |
| 188 | + alb_host_header = null |
| 189 | + alb_paths = ["/*"] |
| 190 | + alb_priority = "100" |
| 191 | + vpc_id = module.vpc.vpc_id |
| 192 | + health_check = { |
| 193 | + interval = 20, |
| 194 | + path = "", |
| 195 | + timeout = 10, |
| 196 | + healthy_threshold = 3, |
| 197 | + unhealthy_threshold = 3, |
| 198 | + matcher = "200,201,204" |
| 199 | + } |
| 200 | + |
| 201 | + is_create_cloudwatch_log_group = true |
| 202 | + |
| 203 | + container = { |
| 204 | + main_container = { |
| 205 | + name = format("%s-api-service", local.name) |
| 206 | + image = "nginx" |
| 207 | + cpu = 128 |
| 208 | + memory = 256 |
| 209 | + is_attach_to_lb = true |
| 210 | + port_mappings = [ |
| 211 | + { |
| 212 | + # If a container has multiple ports, index 0 will be used for target group |
| 213 | + host_port = 80 |
| 214 | + container_port = 80 |
| 215 | + protocol = "tcp" |
| 216 | + } |
| 217 | + ] |
| 218 | + entry_point = [] |
| 219 | + command = [] |
| 220 | + } |
| 221 | + side_container = { |
| 222 | + name = format("%s-nginx", local.name) |
| 223 | + image = "tutum/dnsutils" |
| 224 | + cpu = 128 |
| 225 | + memory = 256 |
| 226 | + port_mappings = [ |
| 227 | + { |
| 228 | + host_port = 443 |
| 229 | + container_port = 443 |
| 230 | + protocol = "tcp" |
| 231 | + }, |
| 232 | + ] |
| 233 | + } |
| 234 | + } |
| 235 | + environment_variables = { |
| 236 | + main_container = { |
| 237 | + THIS_IS_ENV = "ENV1", |
| 238 | + THIS_IS_ENVV = "ENVV", |
| 239 | + } |
| 240 | + side_container = { |
| 241 | + XXXX = "XXXX", |
| 242 | + XXXXX = "XXXXX", |
| 243 | + } |
| 244 | + } |
| 245 | + secret_variables = { |
| 246 | + main_container = { |
| 247 | + THIS_IS_SECRET = "1xxxxx", |
| 248 | + THIS_IS_SECRETT = "2xxxxx", |
| 249 | + } |
| 250 | + } |
138 | 251 |
|
139 | 252 | tags = var.custom_tags
|
140 | 253 | }
|
0 commit comments