Skip to content

Commit 6cf50e6

Browse files
Merge pull request #6 from blinkist/small_fixes_and_doc_cleanup
Small fixes and doc cleanup
2 parents f80da45 + 546d289 commit 6cf50e6

File tree

9 files changed

+91
-267
lines changed

9 files changed

+91
-267
lines changed

README.md

Lines changed: 76 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,13 @@
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.
8711
module "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
10226
module "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+
```

main.tf

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ module "autoscalinggroup" {
3838
iam_instance_profile = "${module.iam.ecs_instance_profile}"
3939
tags = "${var.tags}"
4040
subnet_ids = ["${var.subnet_ids}"]
41-
environment = "${var.environment}"
4241
}
4342

4443
#
@@ -52,16 +51,3 @@ module "ecs_instance_scaling" {
5251
ecs_instance_draining_lambda_arn = "${var.ecs_instance_draining_lambda_arn}"
5352
ecs_instance_scaling_properties = ["${var.ecs_instance_scaling_properties}"]
5453
}
55-
56-
#
57-
# Datadog ECS Service
58-
#
59-
module "datadog" {
60-
source = "./modules/datadog/"
61-
create = "${var.datadog_enabled && var.create}"
62-
name = "${var.name}"
63-
cluster_id = "${aws_ecs_cluster.this.id}"
64-
datadog_enabled = "${var.datadog_enabled}"
65-
datadog_api_key = "${var.datadog_api_key}"
66-
environment = "${var.environment}"
67-
}

modules/autoscalinggroup/amazon_ecs_ami.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fi
1010

1111
# EFS MOUNTING
1212
if [ "${efs_enabled}" == "1" ]; then
13-
mkdir /mnt/efs
13+
mkdir -p ${efs_mount_folder}
1414
if ! rpm -qa | grep -qw nfs-utils; then
1515
yum -y install nfs-utils
1616
fi
@@ -19,7 +19,7 @@ if [ "${efs_enabled}" == "1" ]; then
1919
fi
2020
AZ_ZONE=$(curl -L http://169.254.169.254/latest/meta-data/placement/availability-zone);
2121
DIR_SRC=$AZ_ZONE.${efs_id}.efs.${region}.amazonaws.com
22-
DIR_TGT=/mnt/efs
22+
DIR_TGT=${efs_mount_folder}
2323

2424
mount -t nfs4 $DIR_SRC:/ $DIR_TGT
2525
cp -p /etc/fstab /etc/fstab.back-$(date +%F)

modules/autoscalinggroup/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ data "template_file" "cloud_config_amazon" {
2424
block_metadata_service = "${lookup(var.cluster_properties, "block_metadata_service", "0")}"
2525
efs_enabled = "${lookup(var.cluster_properties, "efs_enabled", "0")}"
2626
efs_id = "${lookup(var.cluster_properties, "efs_id","")}"
27+
efs_mount_folder = "${lookup(var.cluster_properties, "efs_mount_folder","/mnt/efs")}"
2728
custom_userdata = "${lookup(var.cluster_properties, "ec2_custom_userdata","")}"
2829
}
2930
}
@@ -53,7 +54,7 @@ resource "aws_launch_configuration" "launch_config" {
5354
volume_size = "${lookup(var.cluster_properties, "ec2_disk_size")}"
5455
volume_type = "${lookup(var.cluster_properties, "ec2_disk_type")}"
5556
delete_on_termination = true
56-
encrypted = "${lookup(var.cluster_properties, "ec2_disk_encryption","false")}"
57+
encrypted = "${lookup(var.cluster_properties, "ec2_disk_encryption","true")}"
5758
}
5859

5960
lifecycle {

modules/autoscalinggroup/variables.tf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,3 @@ variable "ami" {
3333
description = "The ami to use with the autoscaling group instances"
3434
default = ""
3535
}
36-
37-
variable "datadog_enabled" {
38-
description = "Is datadog enabled ? "
39-
default = false
40-
}
41-
42-
variable "datadog_api_key" {
43-
description = "Datadog API Key"
44-
default = false
45-
}
46-
47-
variable "environment" {
48-
description = "Which environment are we in ? For datadog"
49-
type = "string"
50-
}

modules/datadog/main.tf

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)