@@ -12,11 +12,119 @@ provider "aws" {
1212 region = " ap-northeast-2"
1313}
1414
15- resource "aws_vpc" "example" {
15+ # VPC_1
16+ resource "aws_vpc" "vpc_1" {
1617 cidr_block = " 10.0.0.0/16"
18+ enable_dns_support = true
19+ enable_dns_hostnames = true
1720
1821 tags = {
19- Name = " example "
22+ Name = " team5-vpc-1 "
2023 }
2124}
2225
26+ # 퍼블릭 서브넷 (Subnet_1)
27+ resource "aws_subnet" "subnet_1" {
28+ vpc_id = aws_vpc. vpc_1 . id
29+ cidr_block = " 10.0.1.0/24"
30+ availability_zone = " ap-northeast-2a"
31+ map_public_ip_on_launch = true # 퍼블릭 IP 자동 할당
32+
33+ tags = {
34+ Name = " team5-subnet-1-public"
35+ }
36+ }
37+
38+ # 프라이빗 서브넷 (Subnet_2)
39+ resource "aws_subnet" "subnet_2" {
40+ vpc_id = aws_vpc. vpc_1 . id
41+ cidr_block = " 10.0.2.0/24"
42+ availability_zone = " ap-northeast-2b"
43+
44+ tags = {
45+ Name = " team5-subnet-2-private"
46+ }
47+ }
48+
49+ # 인터넷 게이트 웨이
50+ resource "aws_internet_gateway" "igw_1" {
51+ vpc_id = aws_vpc. vpc_1 . id
52+
53+ tags = {
54+ Name = " team5-igw-1"
55+ }
56+ }
57+
58+ # 라우팅 테이블
59+ resource "aws_route_table" "rt_1" {
60+ vpc_id = aws_vpc. vpc_1 . id
61+
62+ # 모든 트래픽에 대해 인터넷 게이트웨이로 보냄
63+ route {
64+ cidr_block = " 0.0.0.0/0"
65+ gateway_id = aws_internet_gateway. igw_1 . id
66+ }
67+
68+ tags = {
69+ Name = " team5-rt-1"
70+ }
71+ }
72+
73+ resource "aws_route_table_association" "association_1" {
74+ # 연결할 서브넷
75+ subnet_id = aws_subnet. subnet_1 . id
76+
77+ # 연결할 라우트 테이블 지정
78+ route_table_id = aws_route_table. rt_1 . id
79+ }
80+
81+ resource "aws_route_table_association" "association_2" {
82+ # 연결할 서브넷
83+ subnet_id = aws_subnet. subnet_2 . id
84+
85+ # 연결할 라우트 테이블 지정
86+ route_table_id = aws_route_table. rt_1 . id
87+ }
88+
89+ resource "aws_security_group" "sg_1" {
90+ name = " team5-sg-1"
91+ description = " Allow SSH and HTTP"
92+ vpc_id = aws_vpc. vpc_1 . id
93+
94+ ingress {
95+ description = " SSH"
96+ from_port = 22
97+ to_port = 22
98+ protocol = " tcp"
99+ cidr_blocks = [" 0.0.0.0/0" ] # 모든 IP 허용
100+ }
101+
102+ ingress {
103+ description = " HTTP"
104+ from_port = 80
105+ to_port = 80
106+ protocol = " tcp"
107+ cidr_blocks = [" 0.0.0.0/0" ] # 모든 IP 허용
108+ }
109+
110+ egress {
111+ from_port = 0
112+ to_port = 0
113+ protocol = " -1" # 모든 프로토콜
114+ cidr_blocks = [" 0.0.0.0/0" ] # 모든 IP 허용
115+ }
116+ }
117+
118+ resource "aws_instance" "ec2_1" {
119+ ami = " ami-077ad873396d76f6a"
120+ instance_type = " t2.micro"
121+
122+ subnet_id = aws_subnet. subnet_1 . id
123+ vpc_security_group_ids = [aws_security_group . sg_1 . id ]
124+
125+ associate_public_ip_address = true
126+
127+ tags = {
128+ Name = " team5-ec2-1"
129+ }
130+ }
0 commit comments