forked from EconomistDigitalSolutions/terraform-aws-ec2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_main.tf
105 lines (86 loc) · 2.27 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
provider "aws" {
region = "${var.aws-region}"
profile = "${var.aws-profile}"
}
resource "aws_instance" "instance" {
ami = "${var.instance-ami}"
instance_type = "${var.instance-type}"
iam_instance_profile = "${var.iam-role-name != "" ? var.iam-role-name : ""}"
key_name = "${var.instance-key-name != "" ? var.instance-key-name : ""}"
associate_public_ip_address = "${var.instance-associate-public-ip}"
# user_data = "${file("${var.user-data-script}")}"
user_data = "${var.user-data-script != "" ? file("${var.user-data-script}") : ""}"
vpc_security_group_ids = ["${aws_security_group.sg.id}"]
subnet_id = "${aws_subnet.subnet.id}"
tags = {
Name = "${var.instance-tag-name}"
}
}
resource "aws_vpc" "vpc" {
cidr_block = "${var.vpc-cidr-block}"
enable_dns_hostnames = true
tags = {
Name = "${var.vpc-tag-name}"
}
}
resource "aws_internet_gateway" "ig" {
vpc_id = "${aws_vpc.vpc.id}"
tags = {
Name = "${var.ig-tag-name}"
}
}
resource "aws_subnet" "subnet" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${var.subnet-cidr-block}"
tags = {
Name = "${var.subnet-tag-name}"
}
}
resource "aws_route_table" "rt" {
vpc_id = "${aws_vpc.vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.ig.id}"
}
}
resource "aws_route_table_association" "rta" {
subnet_id = "${aws_subnet.subnet.id}"
route_table_id = "${aws_route_table.rt.id}"
}
resource "aws_security_group" "sg" {
name = "${var.sg-tag-name}"
vpc_id = "${aws_vpc.vpc.id}"
ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = "22"
to_port = "22"
}
ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = "80"
to_port = "80"
}
ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = "443"
to_port = "443"
}
ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = "8080"
to_port = "8080"
}
egress {
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
from_port = "0"
to_port = "0"
}
tags = {
Name = "${var.sg-tag-name}"
}
}