Skip to content

Commit efd3778

Browse files
authored
feat: temp dir and mount point (#27)
* feat: temp dir and mount point
1 parent 126706b commit efd3778

File tree

12 files changed

+188
-96
lines changed

12 files changed

+188
-96
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## [v1.1.7] - 2022-10-10
4+
5+
### Added
6+
7+
- Add variable `var.is_application_scratch_volume_enabled` to support enabled temporary storage on ecs
8+
9+
### Changed
10+
11+
- On variable `var.service_info` to support additional mount point
12+
313
## [v1.1.6] - 2022-09-22
414

515
### Added

README.md

Lines changed: 91 additions & 90 deletions
Large diffs are not rendered by default.

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Your can also report the vulnerabilities by emailing to Oozou DevOps team at:
2020
devops@oozou.com
2121
```
2222

23-
We will acknowledge your email within 72 hours on workday, and will send a more details response within 5 days. After the initial email start, we will investigate the security issue snd fix it as soon as possible.
23+
We will acknowledge your email within 72 hours on workday, and will send a more details response within 5 days. After the initial email start, we will investigate the security issue snd fix it as soon as possible.

examples/ecs_ec2_capacity_provider/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ variable "custom_tags" {
1717
description = "Custom tags which can be passed on to the AWS resources. They should be key value pairs having distinct keys."
1818
type = map(string)
1919
default = {}
20-
}
20+
}

examples/simple/main.tf

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
# Please see how to use fargate cluster at ooozou/terraform-aws-fargate-cluster
22

3+
module "fargate_cluster" {
4+
5+
source = "git@github.com:oozou/terraform-aws-ecs-fargate-cluster?ref=v1.0.6"
6+
7+
# Generics
8+
prefix = var.prefix
9+
environment = var.environment
10+
name = var.name
11+
12+
# IAM Role
13+
## If is_create_role is false, all of folowing argument is ignored
14+
is_create_role = true
15+
allow_access_from_principals = ["arn:aws:iam::557291035693:root"]
16+
additional_managed_policy_arns = []
17+
18+
# VPC Information
19+
vpc_id = module.vpc.vpc_id
20+
21+
additional_security_group_ingress_rules = {}
22+
23+
# ALB
24+
is_create_alb = true
25+
is_public_alb = true
26+
enable_deletion_protection = false
27+
alb_listener_port = 8080
28+
# alb_certificate_arn = var.alb_certificate_arn
29+
public_subnet_ids = module.vpc.public_subnet_ids # If is_public_alb is true, public_subnet_ids is required
30+
31+
# ALB's DNS Record
32+
is_create_alb_dns_record = false
33+
34+
tags = var.custom_tags
35+
}
36+
337
module "service_api" {
438
source = "../.."
539

@@ -15,12 +49,12 @@ module "service_api" {
1549
]
1650

1751
# ALB
18-
is_attach_service_with_lb = true
52+
is_attach_service_with_lb = false
1953
alb_listener_arn = module.fargate_cluster.alb_listener_http_arn
2054
alb_host_header = null
2155
alb_paths = ["/*"]
2256
alb_priority = "100"
23-
vpc_id = "vpc-xxxxxxx"
57+
vpc_id = module.vpc.vpc_id
2458
health_check = {
2559
interval = 20,
2660
path = "/",
@@ -40,13 +74,15 @@ module "service_api" {
4074
mem_allocation = 512,
4175
port = 80,
4276
image = "nginx"
77+
mount_points = []
4378
}
79+
is_application_scratch_volume_enabled = true
4480

4581
# ECS service
4682
ecs_cluster_name = module.fargate_cluster.ecs_cluster_name
4783
service_discovery_namespace = module.fargate_cluster.service_discovery_namespace
4884
is_enable_execute_command = true
49-
application_subnet_ids = ["subnet-xxxxxxxxx", "subnet-xxxxxx"]
85+
application_subnet_ids = module.vpc.private_subnet_ids
5086
security_groups = [
5187
module.fargate_cluster.ecs_task_security_group_id
5288
]

examples/simple/vpc.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module "vpc" {
2+
source = "git@github.com:oozou/terraform-aws-vpc.git?ref=v1.1.6"
3+
prefix = var.prefix
4+
environment = var.environment
5+
cidr = "10.105.0.0/16"
6+
private_subnets = ["10.105.60.0/22", "10.105.64.0/22", "10.105.68.0/22"]
7+
public_subnets = ["10.105.0.0/24", "10.105.1.0/24", "10.105.2.0/24"]
8+
database_subnets = ["10.105.20.0/23", "10.105.22.0/23", "10.105.24.0/23"]
9+
availability_zone = ["ap-southeast-1a", "ap-southeast-1b", "ap-southeast-1c"]
10+
is_enable_dns_hostnames = true
11+
is_enable_dns_support = true
12+
is_create_nat_gateway = true
13+
is_enable_single_nat_gateway = true
14+
account_mode = "hub"
15+
tags = var.custom_tags
16+
}

locals.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ locals {
6666
/* Task Definition */
6767
/* -------------------------------------------------------------------------- */
6868
locals {
69+
mount_points_application_scratch = var.is_application_scratch_volume_enabled ? [
70+
{
71+
"containerPath" : "/var/scratch",
72+
"sourceVolume" : "application_scratch"
73+
}
74+
] : []
75+
mount_points = concat(local.mount_points_application_scratch, try(var.service_info.mount_points, []))
76+
6977
# TODO make it better later
7078
container_definitions = local.is_apm_enabled ? templatefile("${path.module}/task-definitions/service-with-sidecar-container.json", {
7179
cpu = var.service_info.cpu_allocation
@@ -84,6 +92,7 @@ locals {
8492
apm_service_port = var.apm_config.service_port
8593
entry_point = jsonencode(var.entry_point)
8694
command = jsonencode(var.command)
95+
mount_points = jsonencode(local.mount_points)
8796
}) : templatefile("${path.module}/task-definitions/service-main-container.json", {
8897
cpu = var.service_info.cpu_allocation
8998
service_image = var.service_info.image
@@ -96,6 +105,7 @@ locals {
96105
secrets_task_definition = jsonencode(local.secrets_task_definition)
97106
entry_point = jsonencode(var.entry_point)
98107
command = jsonencode(var.command)
108+
mount_points = jsonencode(local.mount_points)
99109
})
100110
container_definitions_ec2 = templatefile("${path.module}/task-definitions/service-main-container-ec2.json", {
101111
cpu = var.service_info.cpu_allocation
@@ -110,6 +120,7 @@ locals {
110120
entry_point = jsonencode(var.entry_point)
111121
command = jsonencode(var.command)
112122
unix_max_connection = tostring(var.unix_max_connection)
123+
mount_points = jsonencode(local.mount_points)
113124
})
114125
}
115126

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ resource "aws_ecs_task_definition" "this" {
285285
}
286286
}
287287

288+
dynamic "volume" {
289+
for_each = var.is_application_scratch_volume_enabled ? [true] : []
290+
content {
291+
name = "application_scratch"
292+
}
293+
}
294+
288295
tags = merge(local.tags, { "Name" = local.service_name })
289296
}
290297

task-definitions/service-main-container-ec2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"cpu":${cpu},
44
"image":"${service_image}",
5+
"mountPoints": ${mount_points},
56
"memory":${memory},
67
"name":"${service_name}",
78
"networkMode":"awsvpc",

task-definitions/service-main-container.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"cpu":${cpu},
44
"image":"${service_image}",
5+
"mountPoints": ${mount_points},
56
"memory":${memory},
67
"name":"${service_name}",
78
"networkMode":"awsvpc",
@@ -22,7 +23,7 @@
2223
],
2324
"environment" : ${envvars},
2425
"secrets" : ${secrets_task_definition},
25-
"entryPoint": ${entry_point},
26+
"entryPoint": ${entry_point},
2627
"command": ${command}
2728
}
2829
]

0 commit comments

Comments
 (0)