-
Notifications
You must be signed in to change notification settings - Fork 3
/
project.tf
97 lines (80 loc) · 2 KB
/
project.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
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags = {
Name = "test-vpc"
ManagedBy = "terraform"
}
}
resource "aws_subnet" "subnet_1" {
vpc_id = aws_vpc.vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = format("%sa", var.aws_provider_region)
map_public_ip_on_launch = true
tags = {
Name = "subnet_1"
ManagedBy = "terraform"
}
}
resource "aws_internet_gateway" "internet_gateway" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "test-igw"
ManagedBy = "terraform"
}
}
resource "aws_route_table" "rt" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "route-table"
ManagedBy = "terraform"
}
}
resource "aws_route" "route_to_gateway" {
route_table_id = aws_route_table.rt.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway.id
depends_on = [aws_route_table.rt]
}
resource "aws_route_table_association" "subnet_1" {
subnet_id = aws_subnet.subnet_1.id
route_table_id = aws_route_table.rt.id
}
resource "aws_security_group" "allow_all" {
name = "allow_all"
description = "Allow all inbound traffic"
vpc_id = aws_vpc.vpc.id
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
data "aws_ami" "amazon_linux_2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
}
resource "aws_instance" "web" {
ami = data.aws_ami.amazon_linux_2.id
instance_type = "t3.micro"
user_data = "#!/bin/bash\nyum update -y\nyum install -y httpd\nservice httpd start"
subnet_id = aws_subnet.subnet_1.id
key_name = var.ssh_key
vpc_security_group_ids = [
aws_security_group.allow_all.id,
]
tags = {
Name = "web"
}
}