-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathmain.tf
64 lines (57 loc) · 1.59 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
resource "aws_launch_configuration" "ecs" {
#name = "ecs-${var.name}"
name_prefix = "ecs-${var.name}-"
image_id = "${lookup(var.ami, var.region)}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
iam_instance_profile = "${aws_iam_instance_profile.ecs_profile.name}"
security_groups = ["${aws_security_group.ecs.id}"]
user_data = <<EOF
#!/bin/bash
echo ECS_CLUSTER=${aws_ecs_cluster.cluster.name} >> /etc/ecs/ecs.config
EOF
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "ecs" {
#name = "ecs-asg-${var.name}"
name = "asg-${aws_launch_configuration.ecs.name}"
vpc_zone_identifier = ["${var.subnet_id}"]
launch_configuration = "${aws_launch_configuration.ecs.name}"
min_size = 1
max_size = 10
desired_capacity = "${var.servers}"
tag {
key = "Name"
value = "${var.name} ${var.tagName}"
propagate_at_launch = true
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group" "ecs" {
name = "ecs-sg-${var.name}"
description = "Container Instance Allowed Ports"
vpc_id = "${var.vpc_id}"
ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "ecs-sg-${var.name}"
}
}
# Make this a var that an get passed in?
resource "aws_ecs_cluster" "cluster" {
name = "${var.name}"
}