|
| 1 | +resource "aws_vpc" "vpc_demo" { |
| 2 | + cidr_block = var.cidr |
| 3 | + instance_tenancy = var.instance_tenancy |
| 4 | + enable_dns_hostnames = var.enable_dns_hostnames |
| 5 | + enable_dns_support = var.enable_dns_support |
| 6 | + enable_classiclink = var.enable_classiclink |
| 7 | + |
| 8 | + tags = { |
| 9 | + Name = var.tags |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +resource "aws_internet_gateway" "gw" { |
| 14 | + vpc_id = aws_vpc.vpc_demo.id |
| 15 | + |
| 16 | + tags = { |
| 17 | + Name = "internet-gateway-demo" |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +resource "aws_subnet" "public_1" { |
| 22 | + availability_zone = "us-east-1a" |
| 23 | + vpc_id = aws_vpc.vpc_demo.id |
| 24 | + map_public_ip_on_launch = true |
| 25 | + cidr_block = "10.0.1.0/24" |
| 26 | + |
| 27 | + tags = { |
| 28 | + Name = "public_1-demo" |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +resource "aws_route_table" "route-public" { |
| 33 | + vpc_id = aws_vpc.vpc_demo.id |
| 34 | + |
| 35 | + route { |
| 36 | + cidr_block = "10.0.0.0/0" |
| 37 | + gateway_id = aws_internet_gateway.gw.id |
| 38 | + } |
| 39 | + |
| 40 | + tags = { |
| 41 | + Name = "public-route-table-demo" |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +resource "aws_route_table_association" "public_1" { |
| 46 | + subnet_id = aws_subnet.public_1.id |
| 47 | + route_table_id = aws_route_table.route-public.id |
| 48 | +} |
| 49 | + |
| 50 | +resource "aws_security_group" "allow_ssh" { |
| 51 | + name = "allow_SSH" |
| 52 | + description = "Allow SSH inbound traffic" |
| 53 | + vpc_id = aws_vpc.vpc_demo.id |
| 54 | + |
| 55 | + ingress { |
| 56 | + # SSH Port 22 allowed from any IP |
| 57 | + from_port = 22 |
| 58 | + to_port = 22 |
| 59 | + protocol = "tcp" |
| 60 | + cidr_blocks = ["0.0.0.0/0"] |
| 61 | + } |
| 62 | + |
| 63 | + ingress { |
| 64 | + # SSH Port 80 allowed from any IP |
| 65 | + from_port = 80 |
| 66 | + to_port = 80 |
| 67 | + protocol = "tcp" |
| 68 | + cidr_blocks = ["0.0.0.0/0"] |
| 69 | + } |
| 70 | + |
| 71 | + egress { |
| 72 | + from_port = 0 |
| 73 | + to_port = 0 |
| 74 | + protocol = "-1" |
| 75 | + cidr_blocks = ["0.0.0.0/0"] |
| 76 | + } |
| 77 | +} |
0 commit comments