From ae2cca8d03b96ae717db6179eacf096480912e17 Mon Sep 17 00:00:00 2001 From: namgigun Date: Mon, 22 Sep 2025 15:44:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Infra:=20=ED=85=8C=EB=9D=BC=ED=8F=BC=20?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - main.tf 파일 생성 - .gitignore에 terraform에 대한 민감한 정보를 등록 --- .gitignore | 8 +++++++- infra/terraform/main.tf | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 infra/terraform/main.tf diff --git a/.gitignore b/.gitignore index 5ca2add7..1d0b1312 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,10 @@ out/ ### Custom ### db_dev.mv.db db_dev.trace.db -.env \ No newline at end of file +.env + +### Terraform ### +/infra/terraform/.terraform +/infra/terraform/.terraform.lock.hcl +/infra/terraform/terraform.tfstate +/infra/terraform/terraform.tfstate.backup \ No newline at end of file diff --git a/infra/terraform/main.tf b/infra/terraform/main.tf new file mode 100644 index 00000000..6e1e7eef --- /dev/null +++ b/infra/terraform/main.tf @@ -0,0 +1,22 @@ +terraform { + // aws 라이브러리 불러옴 + required_providers { + aws = { + source = "hashicorp/aws" + } + } +} + +# 디폴드 리전 설정 +provider "aws" { + region = "ap-northeast-2" +} + +resource "aws_vpc" "example" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = "example" + } +} + From 6a7f8a5cf0dc5f7ad5bf80ed681da0668ce3568f Mon Sep 17 00:00:00 2001 From: namgigun Date: Mon, 22 Sep 2025 17:48:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Infra:=20AWS=20=EC=B4=88=EA=B8=B0=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 간단한 구조 1. VPC (1) 2. Subnet (2) -> Private, Public 3. EC2 (1) --- infra/terraform/main.tf | 112 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/infra/terraform/main.tf b/infra/terraform/main.tf index 6e1e7eef..17cf7397 100644 --- a/infra/terraform/main.tf +++ b/infra/terraform/main.tf @@ -12,11 +12,119 @@ provider "aws" { region = "ap-northeast-2" } -resource "aws_vpc" "example" { +# VPC_1 +resource "aws_vpc" "vpc_1" { cidr_block = "10.0.0.0/16" + enable_dns_support = true + enable_dns_hostnames = true tags = { - Name = "example" + Name = "team5-vpc-1" } } +# 퍼블릭 서브넷 (Subnet_1) +resource "aws_subnet" "subnet_1" { + vpc_id = aws_vpc.vpc_1.id + cidr_block = "10.0.1.0/24" + availability_zone = "ap-northeast-2a" + map_public_ip_on_launch = true # 퍼블릭 IP 자동 할당 + + tags = { + Name = "team5-subnet-1-public" + } +} + +# 프라이빗 서브넷 (Subnet_2) +resource "aws_subnet" "subnet_2" { + vpc_id = aws_vpc.vpc_1.id + cidr_block = "10.0.2.0/24" + availability_zone = "ap-northeast-2b" + + tags = { + Name = "team5-subnet-2-private" + } +} + +# 인터넷 게이트 웨이 +resource "aws_internet_gateway" "igw_1" { + vpc_id = aws_vpc.vpc_1.id + + tags = { + Name = "team5-igw-1" + } +} + +# 라우팅 테이블 +resource "aws_route_table" "rt_1" { + vpc_id = aws_vpc.vpc_1.id + + # 모든 트래픽에 대해 인터넷 게이트웨이로 보냄 + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.igw_1.id + } + + tags = { + Name = "team5-rt-1" + } +} + +resource "aws_route_table_association" "association_1" { + # 연결할 서브넷 + subnet_id = aws_subnet.subnet_1.id + + # 연결할 라우트 테이블 지정 + route_table_id = aws_route_table.rt_1.id +} + +resource "aws_route_table_association" "association_2" { + # 연결할 서브넷 + subnet_id = aws_subnet.subnet_2.id + + # 연결할 라우트 테이블 지정 + route_table_id = aws_route_table.rt_1.id +} + +resource "aws_security_group" "sg_1" { + name = "team5-sg-1" + description = "Allow SSH and HTTP" + vpc_id = aws_vpc.vpc_1.id + + ingress { + description = "SSH" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] # 모든 IP 허용 + } + + ingress { + description = "HTTP" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] # 모든 IP 허용 + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" # 모든 프로토콜 + cidr_blocks = ["0.0.0.0/0"] # 모든 IP 허용 + } +} + +resource "aws_instance" "ec2_1" { + ami = "ami-077ad873396d76f6a" + instance_type = "t2.micro" + + subnet_id = aws_subnet.subnet_1.id + vpc_security_group_ids = [aws_security_group.sg_1.id] + + associate_public_ip_address = true + + tags = { + Name = "team5-ec2-1" + } +} \ No newline at end of file