-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
51 lines (43 loc) · 1.18 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
resource "aws_vpc" "vpc" {
cidr_block = var.vpc-cidr
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "${var.prefix}-vpc"
}
}
data "aws_availability_zones" "available" {
state = "available"
}
resource "aws_subnet" "public" {
count = min(3, length(data.aws_availability_zones.available.names))
vpc_id = aws_vpc.vpc.id
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = cidrsubnet(aws_vpc.vpc.cidr_block, 8, count.index)
map_public_ip_on_launch = true
tags = {
Name = "${var.prefix}-subnet-public-${data.aws_availability_zones.available.names[count.index]}"
Tier = "public"
}
}
resource "aws_security_group" "web" {
name = "web_sg"
description = "Allow HTTP inbound traffic"
vpc_id = aws_vpc.vpc.id
ingress {
description = "Web security group."
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = [aws_vpc.vpc.cidr_block]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "${var.prefix}-web-sg"
}
}