-
Notifications
You must be signed in to change notification settings - Fork 0
/
instances.tf
54 lines (43 loc) · 1.5 KB
/
instances.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Security groups
resource "aws_security_group" "ecs-security-group" {
name = "${aws_ecs_cluster.ecs_cluster.name}_ecs_secgroup"
description = "[${var.environment}] security group for ECS instances"
vpc_id = "${data.aws_vpc.vpc.id}"
egress {
from_port = 0
to_port = 0
protocol = "-1"
#provisional: Change it to be parametrizable
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
#provisional: Change it to be parametrizable
cidr_blocks = ["${concat(data.aws_vpc.vpc.*.cidr_block,var.allowed_subnets)}"]
}
tags = {
Name = "${aws_ecs_cluster.ecs_cluster.name}_ecs_secgroup"
Env = "${var.environment}"
}
}
# Instance definitions
resource "aws_instance" "ecs-instance" {
ami = "${data.aws_ami.ecs_ami.image_id}"
subnet_id = "${element(var.vpc_subnet_ids, count.index % length(var.vpc_subnet_ids))}"
count = "${length(var.instances)}"
instance_type = "${element(var.instances, count.index)}"
key_name = "${var.instance_keypair_name}"
vpc_security_group_ids = ["${aws_security_group.ecs-security-group.id}"]
tags = {
Name = "[${aws_ecs_cluster.ecs_cluster.name}] instance-${count.index}"
}
user_data = <<EOF
#!/bin/bash
sudo yum update -y
echo ECS_CLUSTER=${aws_ecs_cluster.ecs_cluster.name} >> /etc/ecs/ecs.config
sudo reboot
EOF
iam_instance_profile = "${aws_iam_instance_profile.ecs_instance_iam_profile.name}"
}