-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
72 lines (57 loc) · 1.65 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
resource "aws_vpc" "example_vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "VPC-01"
}
}
resource "aws_internet_gateway" "example_igw" {
vpc_id = aws_vpc.example_vpc.id
}
data "aws_availability_zones" "available" {
state = "available"
}
resource "aws_subnet" "public_subnet" {
count = 2
vpc_id = aws_vpc.example_vpc.id
cidr_block = "10.0.${count.index}.0/24"
availability_zone = data.aws_availability_zones.available.names[count.index]
map_public_ip_on_launch = true
tags = {
Name = "public-${data.aws_availability_zones.available.names[count.index]}"
}
}
resource "aws_subnet" "private_subnet" {
count = 2
vpc_id = aws_vpc.example_vpc.id
cidr_block = "10.0.${count.index + 2}.0/24"
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = {
Name = "private-${data.aws_availability_zones.available.names[count.index]}"
}
}
resource "aws_route_table" "public_route_table" {
vpc_id = aws_vpc.example_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.example_igw.id
}
tags = {
Name = "public-route-table"
}
}
resource "aws_route_table_association" "public_subnet_association" {
count = 2
subnet_id = aws_subnet.public_subnet[count.index].id
route_table_id = aws_route_table.public_route_table.id
}
resource "aws_s3_bucket" "logs" {
bucket_prefix = "sandbox-logs-"
}
output "public_subnet_ids" {
value = aws_subnet.public_subnet[*].id
}
output "private_subnet_ids" {
value = aws_subnet.private_subnet[*].id
}