VPC
Virtual Private Cloud
An isolated virtual network within the cloud. Configures subnets and routing tables.
Virtual Private Cloud
An isolated virtual network within the cloud. Configures subnets and routing tables.
A VPC (Virtual Private Cloud) is a logically isolated private network space within a public cloud. It can replicate an on-premises data center network in the cloud, and gives you full control over IP address ranges, subnets, route tables, and gateways.
A VPC is divided into subnets. Public subnets communicate with the outside through an internet gateway, while private subnets can only make outbound connections through a NAT gateway. Sensitive resources such as databases are placed in private subnets.
A Security Group is an instance-level Firewall that controls inbound/outbound traffic. A Network ACL (NACL) provides an additional layer of security at the subnet level. Combining the two implements Defense in Depth.
VPC Peering connects to other VPCs, and Transit Gateway lets you centrally manage multiple VPCs and on-premises networks. With PrivateLink, you can access AWS services without going through the internet.
# Terraform: AWS VPC 구성
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "main-vpc"
}
}
# 퍼블릭 서브넷 (AZ 2개)
resource "aws_subnet" "public" {
count = 2
vpc_id = aws_vpc.main.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-subnet-${count.index + 1}"
}
}
# 프라이빗 서브넷 (DB용)
resource "aws_subnet" "private" {
count = 2
vpc_id = aws_vpc.main.id
cidr_block = "10.0.${count.index + 10}.0/24"
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = {
Name = "private-subnet-${count.index + 1}"
}
}
# 인터넷 게이트웨이
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id
}
# NAT 게이트웨이 (프라이빗 서브넷 아웃바운드용)
resource "aws_nat_gateway" "main" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public[0].id
}
# 보안 그룹: 웹 서버
resource "aws_security_group" "web" {
name = "web-sg"
description = "Allow HTTP/HTTPS inbound"
vpc_id = aws_vpc.main.id
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# 보안 그룹: DB (웹 서버에서만 접근)
resource "aws_security_group" "db" {
name = "db-sg"
vpc_id = aws_vpc.main.id
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [aws_security_group.web.id] # 웹 SG에서만
}
}
Network: "You shouldn't put the DB in a public subnet. Move it to a private subnet and allow only the web server SG in the security group."
Development: "Then how do I connect to the DB from my local machine?"
Network: "You can use a Bastion host or SSM Session Manager. Direct external exposure is absolutely not allowed."
Interviewer: "Please explain the VPC design of a 3-tier architecture."
Candidate: "I place the ALB in a public subnet, the application servers in a private subnet, and RDS in a separate private subnet. Security group chaining allows communication only in the direction ALB→App→DB, and each tier is distributed across at least 2 AZs to ensure high availability."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Reviewer: "There's 0.0.0.0/0 in the security group inbound rules. Allow the SSH port only from the company IP range."
Author: "You're right. I'll restrict cidr_blocks to the company VPN range."