1- # AWS ECS Cluster Terraform Module [ ![ Build Status] ( https://travis-ci.org/blinkist/terraform-aws-airship-ecs-cluster.svg?branch=master )] ( https://travis-ci.org/blinkist/terraform-aws-airship-ecs-cluster )
1+ # AWS ECS Cluster Terraform Module [ ![ Build Status] ( https://travis-ci.org/blinkist/terraform-aws-airship-ecs-cluster.svg?branch=master )] ( https://travis-ci.org/blinkist/terraform-aws-airship-ecs-cluster ) [ ![ Slack Community ] ( https://slack.cloudposse.com/badge.svg )] ( https://slack.cloudposse.com )
22
33## Introduction
44
5- This is a partner project to the [ AWS ECS Service Terraform Module] ( https://github.com/blinkist/terraform-aws-airship-ecs-service/ ) . This Terraform module provides a way to easily create and manage Amazon ECS clusters.
5+ This is a partner project to the [ AWS ECS Service Terraform Module] ( https://github.com/blinkist/terraform-aws-airship-ecs-service/ ) . This Terraform module provides a way to easily create and manage Amazon ECS clusters. It does not provide a Lambda function for draining, but it will need an ARN of a lambda in case scaling is enabled. The module will then create the lifecycle hook and permissions needed for automatic draining.
66
7- ## Usage without ECS Scaling
7+ ## Usage Full example, Scaling and EFS mounting enabled
88
99``` hcl
10- module "ecs_web" {
11- source = "blinkist/airship-ecs-cluster/aws"
12- version = "0.4.2"
13-
14- name = "${terraform.workspace}-web"
15- environment = "${terraform.workspace}"
16-
17- vpc_id = "${module.vpc.vpc_id}"
18- subnet_ids = ["${module.vpc.private_subnets}"]
19-
20- cluster_properties {
21- create = true
22- ec2_key_name = "${aws_key_pair.main.key_name}"
23- ec2_instance_type = "t2.small"
24- ec2_asg_min = "1"
25- ec2_asg_max = "1"
26- ec2_disk_size = "40"
27- ec2_disk_type = "gp2"
28- # ec2_disk_encryption = "false"
29-
30- # block_metadata_service blocks the aws metadata service from the ECS Tasks true / false
31- block_metadata_service = true
32- }
33-
34- ecs_instance_scaling_create = false
35-
36- vpc_security_group_ids = ["${module.ecs_instance_sg.this_security_group_id}","${module.admin_sg.this_security_group_id}"]
37-
38- tags= {
39- Environment = "${terraform.workspace}"
40- }
41- }
42- ```
43-
44- ## Usage without ECS Scaling and with EFS mounting
45-
46- ``` hcl
47- module "ecs_web" {
48- source = "blinkist/airship-ecs-cluster/aws"
49- version = "0.4.2"
50-
51- name = "${terraform.workspace}-web"
52- environment = "${terraform.workspace}"
53-
54- vpc_id = "${module.vpc.vpc_id}"
55- subnet_ids = ["${module.vpc.private_subnets}"]
56-
57- cluster_properties {
58- create = true
59- ec2_key_name = "${aws_key_pair.main.key_name}"
60- ec2_instance_type = "t2.small"
61- ec2_asg_min = "1"
62- ec2_asg_max = "1"
63- ec2_disk_size = "40"
64- ec2_disk_type = "gp2"
65- # ec2_disk_encryption = "false"
66- efs_enabled = true
67- efs_id = "${module.efs.aws_efs_file_system_sharedfs_id}"
68- }
69-
70- ecs_instance_scaling_create = false
71-
72- vpc_security_group_ids = ["${module.ecs_instance_sg.this_security_group_id}","${module.admin_sg.this_security_group_id}"]
73-
74- tags= {
75- Environment = "${terraform.workspace}"
76- }
77- }
78-
79-
80- ```
81-
82- ## Usage with ECS Instance Scaling
83-
84- ``` hcl
85- # The ECS Draining module, which takes care of the Terminate lifecycle
86-
10+ # ECS Draining module will create a lambda function which takes care of instance draining.
8711module "ecs_draining {
8812 source = "blinkist/airship-ecs-instance-draining/aws"
8913 version = "0.1.0"
@@ -101,55 +25,54 @@ data "template_file" "extra_userdata" {
10125
10226module "ecs_web" {
10327 source = "blinkist/airship-ecs-cluster/aws"
104- version = "0.1.0"
105-
28+ version = "0.5.0"
29+
30+ # name is re-used as a unique identifier for the creation of different resources
10631 name = "${terraform.workspace}-web"
107- environment = "${terraform.workspace}"
10832
10933 vpc_id = "${module.vpc.vpc_id}"
11034 subnet_ids = ["${module.vpc.private_subnets}"]
111-
35+
11236 cluster_properties {
113- create = true
37+ # ec2_key_name defines the keypair
11438 ec2_key_name = "${aws_key_pair.main.key_name}"
115- ec2_custom_userdata = "${data.template_file.extra_userdata.rendered}"
39+ # ec2_instance_type defines the instance type
11640 ec2_instance_type = "t2.small"
41+ # ec2_custom_userdata sets the launch configuration userdata for the EC2 instances
42+ ec2_custom_userdata = "${data.template_file.extra_userdata.rendered}"
43+ # ec2_asg_min defines the minimum size of the autoscaling group
11744 ec2_asg_min = "1"
45+ # ec2_asg_max defines the maximum size of the autoscaling group
11846 ec2_asg_max = "1"
119- ec2_disk_size = "40"
47+ # ec2_disk_size defines the size in GB of the non-root volume of the EC2 Instance
48+ ec2_disk_size = "100"
49+ # ec2_disk_type defines the disktype of that EBS Volume
12050 ec2_disk_type = "gp2"
121- # ec2_disk_encryption = "false"
51+ # ec2_disk_encryption = "true"
52+
53+ # block_metadata_service blocks the aws metadata service from the ECS Tasks true / false, this is preferred security wise
54+ block_metadata_service = true
55+
56+ # efs_enabled sets if EFS should be mounted
57+ efs_enabled = true
58+ # the id of the EFS volume to mount
59+ efs_id = "${module.efs.aws_efs_file_system_sharedfs_id}"
60+ # efs_mount_folder defines the folder to which the EFS volume will be mounted
61+ # efs_mount_folder = "/mnt/efs"
12262 }
63+
64+ # vpc_security_group_ids defines the security groups for the ec2 instances.
65+ vpc_security_group_ids = ["${module.ecs_instance_sg.this_security_group_id}","${module.admin_sg.this_security_group_id}"]
12366
67+ # ecs_instance_scaling_create defines if we set autscaling for the autoscaling group
68+ # NB! NB! A draining lambda ARN needs to be defined !!
12469 ecs_instance_scaling_create = true
125- ecs_instance_draining_lambda_arn = "${module.ecs_draining.lambda_function_arn}"
12670
127- datadog_api_key = "Datadog API KEY"
128- datadog_enabled = true
71+ # The lambda function which takes care of draining the ecs instance
72+ ecs_instance_draining_lambda_arn = "${module.ecs_draining.lambda_function_arn}"
12973
74+ # ecs_instance_scaling_properties defines how the ECS Cluster scales up / down
13075 ecs_instance_scaling_properties = [
131- {
132- type = "CPUReservation"
133- direction = "up"
134- evaluation_periods = 2
135- observation_period = "300"
136- statistic = "Average"
137- threshold = "89"
138- cooldown = "900"
139- adjustment_type = "ChangeInCapacity"
140- scaling_adjustment = "1"
141- },
142- {
143- type = "CPUReservation"
144- direction = "down"
145- evaluation_periods = 4
146- observation_period = "300"
147- statistic = "Average"
148- threshold = "10"
149- cooldown = "300"
150- adjustment_type = "ChangeInCapacity"
151- scaling_adjustment = "-1"
152- },
15376 {
15477 type = "MemoryReservation"
15578 direction = "up"
@@ -174,6 +97,32 @@ module "ecs_web" {
17497 },
17598 ]
17699
100+ tags = {
101+ Environment = "${terraform.workspace}"
102+ }
103+ }
104+ ```
105+
106+ ## Usage without ECS Scaling and without EFS mounting
107+ ``` hcl
108+ module "ecs_web" {
109+ source = "blinkist/airship-ecs-cluster/aws"
110+ version = "0.5.0"
111+
112+ name = "${terraform.workspace}-web"
113+
114+ vpc_id = "${module.vpc.vpc_id}"
115+ subnet_ids = ["${module.vpc.private_subnets}"]
116+
117+ cluster_properties {
118+ ec2_key_name = "${aws_key_pair.main.key_name}"
119+ ec2_instance_type = "t2.small"
120+ ec2_asg_min = "1"
121+ ec2_asg_max = "1"
122+ ec2_disk_size = "100"
123+ ec2_disk_type = "gp2"
124+ }
125+
177126 vpc_security_group_ids = ["${module.ecs_instance_sg.this_security_group_id}","${module.admin_sg.this_security_group_id}"]
178127
179128 tags= {
@@ -182,7 +131,19 @@ module "ecs_web" {
182131}
183132```
184133
185- ## Outputs
134+ ## Usage for Fargate
135+ ``` hcl
136+ module "ecs_fargate" {
137+ source = "blinkist/airship-ecs-cluster/aws"
138+ version = "0.5.0"
186139
187- TODO
140+ name = "${terraform.workspace}-web"
188141
142+ # create_roles defines if we create IAM Roles for EC2 instances
143+ create_roles = false
144+ # create_autoscalinggroup defines if we create an ASG for ECS
145+ create_autoscalinggroup = false
146+ # ecs_instance_scaling_create = false
147+
148+ }
149+ ```
0 commit comments