1
0
Fork 0
terraform-training/09_aws_vpc/vpc.tf

113 lines
2 KiB
Terraform
Raw Normal View History

2020-05-14 10:33:26 +02:00
resource "aws_vpc" "default" {
cidr_block = var.cidr_block
enable_dns_hostnames = true
tags = {
Name = "cedric-vpc"
}
}
resource "aws_subnet" "public-subnet1" {
vpc_id = aws_vpc.default.id
cidr_block = var.subnet1.cidr
availability_zone = var.subnet1.az
map_public_ip_on_launch = true
tags = {
Name = "cedric-pub-sub1"
}
}
resource "aws_subnet" "public-subnet2" {
vpc_id = aws_vpc.default.id
cidr_block = var.subnet2.cidr
availability_zone = var.subnet2.az
map_public_ip_on_launch = true
tags = {
Name = "cedric-pub-sub2"
}
}
resource "aws_subnet" "private-subnet1" {
vpc_id = aws_vpc.default.id
cidr_block = var.subnet3.cidr
availability_zone = var.subnet3.az
tags = {
Name = "cedric-priv-sub1"
}
}
resource "aws_subnet" "private-subnet2" {
vpc_id = aws_vpc.default.id
cidr_block = var.subnet4.cidr
availability_zone = var.subnet4.az
tags = {
Name = "cedric-priv-sub2"
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.default.id
tags = {
Name = "cedric-gw"
}
}
resource "aws_route_table" "rt" {
vpc_id = aws_vpc.default.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
tags = {
Name = "cedric-rt"
}
}
resource "aws_route_table_association" "rt" {
subnet_id = aws_subnet.public-subnet1.id
route_table_id = aws_route_table.rt.id
}
resource "aws_security_group" "sg" {
vpc_id = aws_vpc.default.id
name = "cedric-sg"
tags = {
Name = "cedric-sg"
}
description = "HTTP-S/SSH/icmp"
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"]
}
ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}