Skip to content

Commit 0a4329e

Browse files
committed
Merge branch 'master' into log-driver-variable
2 parents 3dc87e7 + 9d186a0 commit 0a4329e

File tree

26 files changed

+414
-203
lines changed

26 files changed

+414
-203
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ RUN apt-get update \
1111
&& apt-get clean
1212

1313
COPY tools /usr/local/bin
14-
RUN curl -sL "https://releases.hashicorp.com/terraform/0.7.2/terraform_0.7.2_linux_amd64.zip"> terraform.zip \
14+
RUN curl -sL "https://releases.hashicorp.com/terraform/0.9.11/terraform_0.9.11_linux_amd64.zip"> terraform.zip \
1515
&& unzip terraform.zip \
1616
&& mv terraform /usr/local/bin
1717

18-
RUN curl -sL "https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip" > packer.zip \
18+
RUN curl -sL "https://releases.hashicorp.com/packer/1.0.3/packer_1.0.3_linux_amd64.zip" > packer.zip \
1919
&& unzip packer.zip \
2020
&& mv packer /usr/local/bin
2121

22-
RUN curl -sL -o /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.1.3/dumb-init_1.1.3_amd64 && chmod +x /usr/local/bin/dumb-init
22+
RUN curl -sL -o /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 && chmod +x /usr/local/bin/dumb-init
2323

2424
ENTRYPOINT ["/usr/local/bin/dumb-init"]
2525

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ endif
3333

3434
install-tools: $(tools)
3535

36+
ifeq (${platform},Darwin)
3637
/usr/local/bin/%: ./tools/%
3738
install -S -m 0755 $< /usr/local/bin
39+
else
40+
/usr/local/bin/%: ./tools/%
41+
install -m 0755 $< /usr/local/bin
42+
endif
3843

3944
amis:
4045
pack-ami build -p ./packer -t base -r

Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,16 @@ traffic in and out of the different subnets. The Stack terraform will automatica
155155

156156
Traffic from each internal subnet to the outside world will run through the associated NAT gateway.
157157

158+
Alternatively, setting the `use_nat_instances` VPC module variable to true, will use [EC2 NAT instances][nat-instances] instead of the NAT gateway. NAT instances cost less than the NAT gateway, can be shutdown when not in use, and may be preferred in development environments. By default, NAT instances will not use [Elastic IPs][elastic-ip] to avoid a small hourly charge if the NAT instances are not running full time. To use Elastic IPs for the NAT instances, set the `use_eip_with_nat_instances` VPC module variable to true.
159+
158160
For further reading, check out these sources:
159161

160162
- [Recommended Address Space](http://serverfault.com/questions/630022/what-is-the-recommended-cidr-when-creating-vpc-on-aws)
161163
- [Practical VPC Design](https://medium.com/aws-activate-startup-blog/practical-vpc-design-8412e1a18dcc)
162164

163165
[nat-gateway]: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html
166+
[nat-instances]: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_NAT_Instance.html
167+
[elastic-ip]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html
164168

165169
### Instances
166170

@@ -194,7 +198,7 @@ For more complicated service discovery which handles cases like versioning, we'd
194198

195199
### Bastion
196200

197-
The bastion host acts as the "jump point" for the rest of the infrastructure. Since most of our instances aren't exposed to the external internet, the bastion acts as the gatekeeper for any direct SSH access.
201+
The bastion host acts as the "jump point" for the rest of the infrastructure. Since most of our instances are not exposed to the external internet, the bastion acts as the gatekeeper for any direct SSH access.
198202

199203
The bastion is provisioned using the key name that you pass to the stack (and hopefully have stored somewhere). If you ever need to access an instance directly, you can do it by "jumping through" the bastion:
200204

defaults/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ variable "cidr" {
2323
}
2424

2525
variable "default_ecs_ami" {
26+
type = "map"
27+
2628
default = {
2729
us-east-1 = "ami-dde4e6ca"
2830
us-west-1 = "ami-6d21770d"
@@ -39,6 +41,8 @@ variable "default_ecs_ami" {
3941

4042
# http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-access-logs.html#attach-bucket-policy
4143
variable "default_log_account_ids" {
44+
type = "map"
45+
4246
default = {
4347
us-east-1 = "127311923021"
4448
us-west-2 = "797873946194"

docs.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Usage:
4444
| cidr | the CIDR block to provision for the VPC, if set to something other than the default, both internal_subnets and external_subnets have to be defined as well | `10.30.0.0/16` | no |
4545
| internal_subnets | a list of CIDRs for internal subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones | `<list>` | no |
4646
| external_subnets | a list of CIDRs for external subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones | `<list>` | no |
47+
| use_nat_instances | use NAT EC2 instances instead of the NAT gateway service | `false` | no |
48+
| use_eip_with_nat_instances | use Elastic IPs with NAT instances if `use_nat_instances` is true | `false` | no |
49+
| nat_instance_type | the EC2 instance type for NAT instances if `use_nat_instances` is true | `t2.nano` | no |
50+
| nat_instance_ssh_key_name | the name of the ssh key to use with NAT instances if `use_nat_instances` is true | "" | no |
4751
| availability_zones | a comma-separated list of availability zones, defaults to all AZ of the region, if set to something other than the defaults, both internal_subnets and external_subnets have to be defined as well | `<list>` | no |
4852
| bastion_instance_type | Instance type for the bastion | `t2.micro` | no |
4953
| ecs_cluster_name | the name of the cluster, if not specified the variable name will be used | `` | no |
@@ -88,7 +92,7 @@ Usage:
8892
# bastion
8993

9094
The bastion host acts as the "jump point" for the rest of the infrastructure.
91-
Since most of our instances aren't exposed to the external internet, the bastion acts as the gatekeeper for any direct SSH access.
95+
Since most of our instances are not exposed to the external internet, the bastion acts as the gatekeeper for any direct SSH access.
9296
The bastion is provisioned using the key name that you pass to the stack (and hopefully have stored somewhere).
9397
If you ever need to access an instance directly, you can do it by "jumping through" the bastion.
9498

@@ -130,7 +134,7 @@ Usage:
130134
# defaults
131135

132136
This module is used to set configuration defaults for the AWS infrastructure.
133-
It doesn't provide much value when used on its own because terraform makes it
137+
It does not provide much value when used on its own because terraform makes it
134138
hard to do dynamic generations of things like subnets, for now it's used as
135139
a helper module for the stack.
136140

@@ -248,7 +252,7 @@ Usage:
248252
| instance_type | The instance type to use, e.g t2.small | - | yes |
249253
| instance_ebs_optimized | When set to true the instance will be launched with EBS optimized turned on | `true` | no |
250254
| min_size | Minimum instance count | `3` | no |
251-
| max_size | Maxmimum instance count | `100` | no |
255+
| max_size | Maximum instance count | `100` | no |
252256
| desired_capacity | Desired instance count | `3` | no |
253257
| associate_public_ip_address | Should created instances be publicly accessible (if the SG allows) | `false` | no |
254258
| root_volume_size | Root volume size in GB | `25` | no |

ecs-cluster/main.tf

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ variable "desired_capacity" {
9393

9494
variable "associate_public_ip_address" {
9595
description = "Should created instances be publicly accessible (if the SG allows)"
96-
default = false
96+
default = false
9797
}
9898

9999
variable "root_volume_size" {
@@ -126,35 +126,6 @@ variable "extra_cloud_config_content" {
126126
default = ""
127127
}
128128

129-
resource "aws_security_group" "cluster" {
130-
name = "${var.name}-ecs-cluster"
131-
vpc_id = "${var.vpc_id}"
132-
description = "Allows traffic from and to the EC2 instances of the ${var.name} ECS cluster"
133-
134-
ingress {
135-
from_port = 0
136-
to_port = 0
137-
protocol = -1
138-
security_groups = ["${split(",", var.security_groups)}"]
139-
}
140-
141-
egress {
142-
from_port = 0
143-
to_port = 0
144-
protocol = -1
145-
cidr_blocks = ["0.0.0.0/0"]
146-
}
147-
148-
tags {
149-
Name = "ECS cluster (${var.name})"
150-
Environment = "${var.environment}"
151-
}
152-
153-
lifecycle {
154-
create_before_destroy = true
155-
}
156-
}
157-
158129
resource "aws_ecs_cluster" "main" {
159130
name = "${var.name}"
160131

@@ -198,7 +169,7 @@ resource "aws_launch_configuration" "main" {
198169
ebs_optimized = "${var.instance_ebs_optimized}"
199170
iam_instance_profile = "${var.iam_instance_profile}"
200171
key_name = "${var.key_name}"
201-
security_groups = ["${aws_security_group.cluster.id}"]
172+
security_groups = ["${split(",", var.security_groups)}"]
202173
user_data = "${data.template_cloudinit_config.cloud_config.rendered}"
203174
associate_public_ip_address = "${var.associate_public_ip_address}"
204175

@@ -382,8 +353,3 @@ resource "aws_cloudwatch_metric_alarm" "memory_low" {
382353
output "name" {
383354
value = "${var.name}"
384355
}
385-
386-
// The cluster security group ID.
387-
output "security_group_id" {
388-
value = "${aws_security_group.cluster.id}"
389-
}

iam-role/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ EOF
9595
}
9696

9797
resource "aws_iam_instance_profile" "default_ecs" {
98-
name = "ecs-instance-profile-${var.name}-${var.environment}"
99-
path = "/"
100-
roles = ["${aws_iam_role.default_ecs_role.name}"]
98+
name = "ecs-instance-profile-${var.name}-${var.environment}"
99+
path = "/"
100+
role = "${aws_iam_role.default_ecs_role.name}"
101101
}
102102

103103
output "default_ecs_role_id" {

main.tf

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,31 @@ variable "cidr" {
4646
}
4747

4848
variable "internal_subnets" {
49+
type = "list"
4950
description = "a list of CIDRs for internal subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones"
50-
default = ["10.30.0.0/19" ,"10.30.64.0/19", "10.30.128.0/19"]
51+
default = ["10.30.0.0/19", "10.30.64.0/19", "10.30.128.0/19"]
5152
}
5253

5354
variable "external_subnets" {
55+
type = "list"
5456
description = "a list of CIDRs for external subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones"
5557
default = ["10.30.32.0/20", "10.30.96.0/20", "10.30.160.0/20"]
5658
}
5759

5860
variable "availability_zones" {
61+
type = "list"
5962
description = "a comma-separated list of availability zones, defaults to all AZ of the region, if set to something other than the defaults, both internal_subnets and external_subnets have to be defined as well"
6063
default = ["us-west-2a", "us-west-2b", "us-west-2c"]
6164
}
6265

6366
variable "bastion_instance_type" {
6467
description = "Instance type for the bastion"
65-
default = "t2.micro"
68+
default = "t2.micro"
6669
}
6770

6871
variable "ecs_cluster_name" {
6972
description = "the name of the cluster, if not specified the variable name will be used"
70-
default = ""
73+
default = ""
7174
}
7275

7376
variable "ecs_instance_type" {
@@ -124,6 +127,11 @@ variable "ecs_security_groups" {
124127
default = ""
125128
}
126129

130+
variable "ecs_extra_security_groups" {
131+
description = "A comma separated list of security groups added to the default security groups of the stack"
132+
default = ""
133+
}
134+
127135
variable "ecs_ami" {
128136
description = "The AMI that will be used to launch EC2 instances in the ECS cluster"
129137
default = ""
@@ -202,35 +210,34 @@ module "iam_role" {
202210
}
203211

204212
module "ecs_cluster" {
205-
source = "./ecs-cluster"
206-
name = "${coalesce(var.ecs_cluster_name, var.name)}"
207-
environment = "${var.environment}"
208-
vpc_id = "${module.vpc.id}"
209-
image_id = "${coalesce(var.ecs_ami, module.defaults.ecs_ami)}"
210-
subnet_ids = "${module.vpc.internal_subnets}"
211-
key_name = "${var.key_name}"
212-
instance_type = "${var.ecs_instance_type}"
213-
instance_ebs_optimized = "${var.ecs_instance_ebs_optimized}"
214-
iam_instance_profile = "${module.iam_role.profile}"
215-
min_size = "${var.ecs_min_size}"
216-
max_size = "${var.ecs_max_size}"
217-
desired_capacity = "${var.ecs_desired_capacity}"
218-
region = "${var.region}"
219-
availability_zones = "${module.vpc.availability_zones}"
220-
root_volume_size = "${var.ecs_root_volume_size}"
221-
docker_volume_size = "${var.ecs_docker_volume_size}"
222-
docker_auth_type = "${var.ecs_docker_auth_type}"
223-
docker_auth_data = "${var.ecs_docker_auth_data}"
224-
security_groups = "${coalesce(var.ecs_security_groups, format("%s,%s,%s", module.security_groups.internal_ssh, module.security_groups.internal_elb, module.security_groups.external_elb))}"
225-
extra_cloud_config_type = "${var.extra_cloud_config_type}"
226-
extra_cloud_config_content = "${var.extra_cloud_config_content}"
213+
source = "./ecs-cluster"
214+
name = "${coalesce(var.ecs_cluster_name, var.name)}"
215+
environment = "${var.environment}"
216+
vpc_id = "${module.vpc.id}"
217+
image_id = "${coalesce(var.ecs_ami, module.defaults.ecs_ami)}"
218+
subnet_ids = "${module.vpc.internal_subnets}"
219+
key_name = "${var.key_name}"
220+
instance_type = "${var.ecs_instance_type}"
221+
instance_ebs_optimized = "${var.ecs_instance_ebs_optimized}"
222+
iam_instance_profile = "${module.iam_role.profile}"
223+
min_size = "${var.ecs_min_size}"
224+
max_size = "${var.ecs_max_size}"
225+
desired_capacity = "${var.ecs_desired_capacity}"
226+
region = "${var.region}"
227+
availability_zones = "${module.vpc.availability_zones}"
228+
root_volume_size = "${var.ecs_root_volume_size}"
229+
docker_volume_size = "${var.ecs_docker_volume_size}"
230+
docker_auth_type = "${var.ecs_docker_auth_type}"
231+
docker_auth_data = "${var.ecs_docker_auth_data}"
232+
security_groups = "${coalesce(var.ecs_security_groups, format("%s,%s,%s", module.security_groups.internal_ssh, module.security_groups.internal_elb, module.security_groups.external_elb))}"
233+
extra_cloud_config_type = "${var.extra_cloud_config_type}"
234+
extra_cloud_config_content = "${var.extra_cloud_config_content}"
227235
}
228236

229237
module "s3_logs" {
230238
source = "./s3-logs"
231239
name = "${var.name}"
232240
environment = "${var.environment}"
233-
account_id = "${module.defaults.s3_logs_account_id}"
234241
logs_expiration_enabled = "${var.logs_expiration_enabled}"
235242
logs_expiration_days = "${var.logs_expiration_days}"
236243
}
@@ -329,3 +336,13 @@ output "internal_route_tables" {
329336
output "external_route_tables" {
330337
value = "${module.vpc.external_rtb_id}"
331338
}
339+
340+
// The external ssh security group ID.
341+
output "external_ssh" {
342+
value = "${module.security_groups.external_ssh}"
343+
}
344+
345+
// The internal ssh security group ID.
346+
output "internal_ssh" {
347+
value = "${module.security_groups.internal_ssh}"
348+
}

packer/base/packer.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
---
2+
# Latest xenial 16.04 LTS amd64 hvm:ebs-ssd Releases
3+
# us-gov-west-1 20170619.1 ami-939412f2
4+
# us-east-2 20170619.1 ami-8b92b4ee
5+
# sa-east-1 20170619.1 ami-34afc458
6+
# eu-central-1 20170619.1 ami-1c45e273
7+
# us-west-1 20170619.1 ami-73f7da13
8+
# us-west-2 20170619.1 ami-835b4efa
9+
# ap-northeast-2 20170619.1 ami-94d20dfa
10+
# ca-central-1 20170619.1 ami-7ed56a1a
11+
# eu-west-2 20170619.1 ami-cc7066a8
12+
# ap-southeast-1 20170619.1 ami-2378f540
13+
# eu-west-1 20170619.1 ami-6d48500b
14+
# ap-southeast-2 20170619.1 ami-e94e5e8a
15+
# ap-northeast-1 20170619.1 ami-785c491f
16+
# us-east-1 20170619.1 ami-d15a75c7
17+
# ap-south-1 20170619.1 ami-49e59a26
18+
# cn-north-1 20170303 ami-a163b4cc
19+
20+
221
# https://www.packer.io/docs/builders/amazon-ebs.html
322
ami:
4-
source_ami: ami-e6d5d2f1
23+
source_ami: ami-d15a75c7
524
region: us-east-1
625
instance_type: c4.2xlarge
726
ssh_username: ubuntu
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Package: *
2+
Pin: release o=Docker
3+
Pin-Priority: 900

packer/base/scripts/base.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22
set -e
33

4+
export DEBIAN_FRONTEND=noninteractive
45
systemctl disable apt-daily.service
56
systemctl disable apt-daily.timer
67

78
apt-get update -y
8-
apt-get upgrade -y
99

1010
apt-get install -y \
1111
build-essential \
@@ -35,8 +35,12 @@ apt-get install -y \
3535
ntp \
3636
logrotate \
3737
dhcping \
38+
nfs-common \
39+
curl \
40+
unzip \
41+
jq \
3842
dhcpdump
3943

4044
pip install awscli
4145

42-
apt-get dist-upgrade -y
46+
apt-get upgrade -y

packer/base/scripts/docker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
set -e
33

4+
export DEBIAN_FRONTEND=noninteractive
5+
46
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
57
echo 'deb https://apt.dockerproject.org/repo ubuntu-xenial main' > /etc/apt/sources.list.d/docker.list
68

@@ -9,7 +11,6 @@ apt-get purge -y lxc-docker
911
apt-cache policy docker-engine
1012

1113
apt-get install -o Dpkg::Options::="--force-confold" -y \
12-
linux-image-extra-$(uname -r) \
1314
docker-engine
1415

1516
gpasswd -a ubuntu docker

0 commit comments

Comments
 (0)