Skip to content

Commit f05ffa4

Browse files
committed
Merge branch 'master' into ecs-agent
2 parents 88fa348 + d474052 commit f05ffa4

File tree

10 files changed

+298
-131
lines changed

10 files changed

+298
-131
lines changed

Readme.md

Lines changed: 4 additions & 0 deletions
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

docs.md

Lines changed: 4 additions & 0 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 |

ecs-cluster/main.tf

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
}

main.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ variable "ecs_security_groups" {
127127
default = ""
128128
}
129129

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+
130135
variable "ecs_ami" {
131136
description = "The AMI that will be used to launch EC2 instances in the ECS cluster"
132137
default = ""
@@ -233,7 +238,6 @@ module "s3_logs" {
233238
source = "./s3-logs"
234239
name = "${var.name}"
235240
environment = "${var.environment}"
236-
account_id = "${module.defaults.s3_logs_account_id}"
237241
logs_expiration_enabled = "${var.logs_expiration_enabled}"
238242
logs_expiration_days = "${var.logs_expiration_days}"
239243
}
@@ -332,3 +336,13 @@ output "internal_route_tables" {
332336
output "external_route_tables" {
333337
value = "${module.vpc.external_rtb_id}"
334338
}
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+
}

rds/main.tf

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ variable "maintenance_window" {
5151
default = "Mon:01:00-Mon:02:00"
5252
}
5353

54+
variable "monitoring_interval" {
55+
description = "Seconds between enhanced monitoring metric collection. 0 disables enhanced monitoring."
56+
default = "0"
57+
}
58+
59+
variable "monitoring_role_arn" {
60+
description = "The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. Required if monitoring_interval > 0."
61+
default = ""
62+
}
63+
5464
variable "apply_immediately" {
5565
description = "If false, apply changes during maintenance window"
5666
default = true
@@ -97,32 +107,40 @@ variable "subnet_ids" {
97107
type = "list"
98108
}
99109

100-
resource "aws_security_group" "main" {
101-
name = "${var.name}-rds"
102-
description = "Allows traffic to RDS from other security groups"
103-
vpc_id = "${var.vpc_id}"
110+
resource "aws_security_group_rule" "main-ingress-cidrs" {
111+
security_group_id = "${aws_security_group.main.id}"
112+
type = "ingress"
113+
cidr_blocks = ["${var.ingress_allow_cidr_blocks}"]
114+
from_port = "${var.port}"
115+
to_port = "${var.port}"
116+
protocol = "TCP"
117+
}
104118

105-
ingress {
106-
from_port = "${var.port}"
107-
to_port = "${var.port}"
108-
protocol = "TCP"
109-
security_groups = ["${var.ingress_allow_security_groups}"]
110-
}
119+
resource "aws_security_group_rule" "main-ingress-sgs" {
120+
security_group_id = "${aws_security_group.main.id}"
121+
type = "ingress"
122+
count = "${length(var.ingress_allow_security_groups)}"
123+
source_security_group_id = "${element(var.ingress_allow_security_groups, count.index)}"
111124

112-
ingress {
113-
from_port = "${var.port}"
114-
to_port = "${var.port}"
115-
protocol = "TCP"
116-
cidr_blocks = ["${var.ingress_allow_cidr_blocks}"]
117-
}
125+
from_port = "${var.port}"
126+
to_port = "${var.port}"
127+
protocol = "TCP"
128+
}
118129

119-
egress {
120-
from_port = 0
121-
to_port = 0
122-
protocol = -1
123-
cidr_blocks = ["0.0.0.0/0"]
124-
}
130+
resource "aws_security_group_rule" "main-egress-all" {
131+
security_group_id = "${aws_security_group.main.id}"
132+
type = "egress"
133+
from_port = 0
134+
to_port = 0
135+
protocol = -1
136+
cidr_blocks = ["0.0.0.0/0"]
137+
}
125138

139+
140+
resource "aws_security_group" "main" {
141+
name = "${var.name}-rds"
142+
description = "Allows traffic to RDS from other security groups"
143+
vpc_id = "${var.vpc_id}"
126144
tags {
127145
Name = "RDS (${var.name})"
128146
}
@@ -149,6 +167,8 @@ resource "aws_db_instance" "main" {
149167
backup_retention_period = "${var.backup_retention_period}"
150168
backup_window = "${var.backup_window}"
151169
maintenance_window = "${var.maintenance_window}"
170+
monitoring_interval = "${var.monitoring_interval}"
171+
monitoring_role_arn = "${var.monitoring_role_arn}"
152172
apply_immediately = "${var.apply_immediately}"
153173
final_snapshot_identifier = "${var.name}-finalsnapshot"
154174

s3-logs/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ variable "logs_expiration_days" {
1212
default = 30
1313
}
1414

15+
data "aws_elb_service_account" "main" {}
16+
1517
data "template_file" "policy" {
1618
template = "${file("${path.module}/policy.json")}"
1719

1820
vars = {
1921
bucket = "${var.name}-${var.environment}-logs"
20-
account_id = "${var.account_id}"
22+
elb_account_id = "${data.aws_elb_service_account.main.arn}"
2123
}
2224
}
2325

s3-logs/policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"Action": "s3:PutObject",
66
"Effect": "Allow",
77
"Principal": {
8-
"AWS": "arn:aws:iam::${account_id}:root"
8+
"AWS": "${elb_account_id}"
99
},
1010
"Resource": "arn:aws:s3:::${bucket}/*",
1111
"Sid": "log-bucket-policy"

0 commit comments

Comments
 (0)