-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
102 lines (87 loc) · 2.45 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
provider "aws" {
region = var.region
}
resource "aws_vpc" "vpc" {
cidr_block = var.vpc-cidr
enable_dns_hostnames = true
}
resource "aws_subnet" "subnet-a" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.subnet-cidr-a
availability_zone = "${var.region}a"
}
resource "aws_subnet" "subnet-b" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.subnet-cidr-b
availability_zone = "${var.region}b"
}
resource "aws_subnet" "subnet-c" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.subnet-cidr-c
availability_zone = "${var.region}c"
}
resource "aws_route_table" "subnet-route-table" {
vpc_id = aws_vpc.vpc.id
}
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.vpc.id
}
resource "aws_route" "subnet-route" {
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
route_table_id = aws_route_table.subnet-route-table.id
}
resource "aws_route_table_association" "subnet-a-route-table-association" {
subnet_id = aws_subnet.subnet-a.id
route_table_id = aws_route_table.subnet-route-table.id
}
resource "aws_route_table_association" "subnet-b-route-table-association" {
subnet_id = aws_subnet.subnet-b.id
route_table_id = aws_route_table.subnet-route-table.id
}
resource "aws_route_table_association" "subnet-c-route-table-association" {
subnet_id = aws_subnet.subnet-c.id
route_table_id = aws_route_table.subnet-route-table.id
}
resource "aws_instance" "instance" {
ami = "ami-0ad32127d6f7eb18a"
instance_type = "t3.micro"
vpc_security_group_ids = [ aws_security_group.security-group.id ]
subnet_id = aws_subnet.subnet-a.id
associate_public_ip_address = true
user_data = <<EOF
#!/bin/sh
yum install -y nginx
service nginx start
EOF
}
resource "aws_security_group" "security-group" {
vpc_id = aws_vpc.vpc.id
ingress {
from_port = "80"
to_port = "80"
protocol = "tcp"
cidr_blocks = [ "0.0.0.0/0" ]
}
ingress {
from_port = "443"
to_port = "443"
protocol = "tcp"
cidr_blocks = [ "0.0.0.0/0" ]
}
ingress {
from_port = "22"
to_port = "22"
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" ]
}
}
output "nginx_domain" {
value = aws_instance.instance.public_dns
}