@@ -174,6 +174,58 @@ resource "aws_security_group" "sg_1" {
174174 }
175175}
176176
177+ # Coturn 서버 전용 보안 그룹 (Security Group)
178+ resource "aws_security_group" "coturn_sg" {
179+ name = " team5-coturn-server-sg"
180+ description = " Allow WebRTC TURN server traffic"
181+ vpc_id = aws_vpc. vpc_1 . id
182+
183+ ingress {
184+ description = " SSH for maintenance"
185+ from_port = 22
186+ to_port = 22
187+ protocol = " tcp"
188+ cidr_blocks = [" 0.0.0.0/0" ]
189+ }
190+
191+ ingress {
192+ description = " TURN Listening Port (TCP)"
193+ from_port = 3478
194+ to_port = 3478
195+ protocol = " tcp"
196+ cidr_blocks = [" 0.0.0.0/0" ]
197+ }
198+
199+ ingress {
200+ description = " TURN Listening Port (UDP)"
201+ from_port = 3478
202+ to_port = 3478
203+ protocol = " udp"
204+ cidr_blocks = [" 0.0.0.0/0" ]
205+ }
206+
207+ ingress {
208+ description = " TURN Media Relay Ports (UDP)"
209+ from_port = 49152
210+ to_port = 65535
211+ protocol = " udp"
212+ cidr_blocks = [" 0.0.0.0/0" ]
213+ }
214+
215+ egress {
216+ from_port = 0
217+ to_port = 0
218+ protocol = " -1"
219+ cidr_blocks = [" 0.0.0.0/0" ]
220+ }
221+
222+ tags = {
223+ Key = " TEAM"
224+ Value = " devcos-team05"
225+ Name = " team5-coturn-sg"
226+ }
227+ }
228+
177229# EC2 역할 생성
178230resource "aws_iam_role" "ec2_role_1" {
179231 tags = {
@@ -307,6 +359,55 @@ ${local.ec2_user_data_base}
307359EOF
308360}
309361
362+ resource "aws_instance" "coturn_server" {
363+ ami = " ami-02835aed2a5cb1d2a" # 서울 리전 Ubuntu 22.04 LTS
364+ instance_type = " t3.micro"
365+ subnet_id = aws_subnet. subnet_1 . id
366+ vpc_security_group_ids = [aws_security_group . coturn_sg . id ]
367+ associate_public_ip_address = true
368+
369+ tags = {
370+ Key = " TEAM"
371+ Value = " devcos-team05"
372+ Name = " team5-coturn-server"
373+ }
374+
375+ # EC2 부팅 시 Coturn 자동 설치 및 설정 스크립트
376+ user_data = <<- EOF
377+ #!/bin/bash
378+ apt-get update
379+ apt-get install -y coturn
380+
381+ PUBLIC_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)
382+ PRIVATE_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
383+
384+ cat <<EOT > /etc/turnserver.conf
385+ listening-port=3478
386+ external-ip=$PUBLIC_IP/$PRIVATE_IP
387+
388+ # 동적 인증을 위한 비밀키 설정
389+ use-auth-secret
390+ static-auth-secret=${ var . turn_shared_secret }
391+
392+ lt-cred-mech
393+ realm=${ var . catfe_domain_1 }
394+ log-file=/var/log/turnserver.log
395+ verbose
396+ fingerprint
397+ no-multicast-peers
398+ EOT
399+
400+ systemctl restart coturn
401+ systemctl enable coturn
402+ EOF
403+ }
404+
405+ # 3. 결과 출력 (Output - Turn 서버 IP 주소 출력)
406+ output "coturn_server_public_ip" {
407+ description = " The public IP address of the Coturn server."
408+ value = aws_instance. coturn_server . public_ip
409+ }
410+
310411# RDS용 Security Group
311412resource "aws_security_group" "rds_sg_1" {
312413 name = " team5-rds-sg-1"
@@ -361,6 +462,8 @@ resource "aws_db_instance" "mysql" {
361462 db_subnet_group_name = aws_db_subnet_group. db_subnet_group . name
362463 vpc_security_group_ids = [aws_security_group . rds_sg_1 . id ]
363464
465+ # RDS 퍼블릭 액세스 허용
466+ publicly_accessible = true
364467
365468 multi_az = false
366469
0 commit comments