-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.tf
executable file
·44 lines (39 loc) · 1.11 KB
/
ec2.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
/*
* Security group for EC2 instances
*/
resource "aws_security_group" "docker_aws_ec2" {
name = "docker-nginx-aws-ec2"
description = "allow incoming HTTP traffic only"
vpc_id = "${aws_vpc.aws.id}"
ingress {
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
/*
* EC2 instances, one per availability zone
*/
resource "aws_instance" "docker_aws" {
ami = "${lookup(var.ec2_amis, var.aws_region)}"
associate_public_ip_address = true
count = "${length(var.azs)}"
depends_on = ["aws_subnet.private"]
instance_type = "t2.micro"
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
user_data = "${file("user_data.sh")}"
/*
* References security group created above
*/
vpc_security_group_ids = ["${aws_security_group.docker_aws_ec2.id}"]
tags = {
Name = "docker-nginx-aws-instance-${count.index}"
}
}