Skip to content

Instantly share code, notes, and snippets.

View pmatsinopoulos's full-sized avatar
💻
Programming

Panos Matsinopoulos pmatsinopoulos

💻
Programming
View GitHub Profile
@pmatsinopoulos
pmatsinopoulos / route_table_to_nat_gateway.tf
Created August 28, 2023 14:26
AWS Public and Private Subnets - route_table_to_nat_gateway.tf
resource "aws_route_table" "to_nat_gateway" {
vpc_id = aws_vpc.private_and_public_subnets.id
tags = {
"Name" = "access-to-nat-gateway"
}
}
resource "aws_route" "to_nat_gateway" {
route_table_id = aws_route_table.to_nat_gateway.id
@pmatsinopoulos
pmatsinopoulos / nat_gateway.tf
Created August 28, 2023 14:19
AWS Private and Public Subnets - nat_gateway.tf
resource "aws_eip" "nat_gateway" {
depends_on = [aws_internet_gateway.private_and_public_subnets]
}
resource "aws_nat_gateway" "private_and_public_subnets" {
connectivity_type = "public"
allocation_id = aws_eip.nat_gateway.id
subnet_id = aws_subnet.subnet_2.id # public subnet
tags = {
@pmatsinopoulos
pmatsinopoulos / ec2_key_pair_internal.tf
Created August 28, 2023 12:15
AWS Private and Public Subnets - ec2_keypair_internal.tf
resource "aws_key_pair" "internal_to_vpc" {
key_name = "${local.project}-internal"
public_key = file("${path.module}/id_rsa_internal.pub")
tags = {
"Name" = "${local.project}-internal"
}
}
@pmatsinopoulos
pmatsinopoulos / route_table_to_internet_gateway.tf
Created August 28, 2023 07:47
AWS Private and Public Subnets - route_table_to_internet_gateway.tf
resource "aws_route_table" "to_internet_gateway" {
vpc_id = aws_vpc.private_and_public_subnets.id
tags = {
"Name" = "access-to-internet"
}
}
resource "aws_route" "to_internet_gateway" {
route_table_id = aws_route_table.to_internet_gateway.id
@pmatsinopoulos
pmatsinopoulos / internet_gateway.tf
Created August 28, 2023 07:37
AWS Private and Public Subnets - internet_gateway.tf
resource "aws_internet_gateway" "private_and_public_subnets" {
vpc_id = aws_vpc.private_and_public_subnets.id
tags = {
"Name" = "igw"
}
}
@pmatsinopoulos
pmatsinopoulos / ssh_access.tf
Created August 28, 2023 06:45
AWS Private and Public Subnets - ssh_access.tf
resource "aws_security_group" "ssh_access" {
name = "${local.project}-ssh-access"
description = "Allow SSH traffic from anywhere"
vpc_id = aws_vpc.private_and_public_subnets.id
ingress {
description = "allow SSH from anywhere"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
@pmatsinopoulos
pmatsinopoulos / ec2.tf
Created August 27, 2023 13:45
AWS Private and Public Subnets - ec2.tf
data "aws_ami" "client" {
most_recent = true
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "block-device-mapping.delete-on-termination"
@pmatsinopoulos
pmatsinopoulos / ec2_key_pair.tf
Created August 27, 2023 13:14
AWS Private and Public Subnets - ec2_key_pair.tf
resource "aws_key_pair" "private_public_subnets" {
key_name = local.project
public_key = file("${path.module}/id_rsa.pub")
tags = {
"Name" = local.project
}
}
@pmatsinopoulos
pmatsinopoulos / vpc_subnets.tf
Created August 27, 2023 12:02
AWS Private and Public Subnets - vpc_subnets.tf
resource "aws_subnet" "subnet_1" {
availability_zone = "eu-west-1a"
cidr_block = "172.18.0.0/28"
tags = {
"Name" = "private-subnet-1"
}
vpc_id = aws_vpc.private_and_public_subnets.id
}
@pmatsinopoulos
pmatsinopoulos / vpc.tf
Last active August 27, 2023 11:40
AWS Private and Public Subnets - vpc.tf
resource "aws_vpc" "private_and_public_subnets" {
cidr_block = "172.18.0.0/27" # 32 IPs
enable_dns_hostnames = true
enable_dns_support = true
instance_tenancy = "default"
tags = {
"Name" = "${local.project}-vpc"
}
}