File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -337,4 +337,68 @@ resource "aws_eip" "unihub_eip_1" {
337337 }
338338}
339339
340+ # EC2 모니터링 EC2 구축
340341
342+ locals {
343+ ec2_monitoring_base = <<- END_OF_FILE
344+ #!/bin/bash
345+ # 가상 메모리 4GB 설정
346+ sudo dd if=/dev/zero of=/swapfile bs=128M count=32
347+ sudo chmod 600 /swapfile
348+ sudo mkswap /swapfile
349+ sudo swapon /swapfile
350+ sudo sh -c 'echo "/swapfile swap swap defaults 0 0" >> /etc/fstab'
351+
352+ # 도커 설치 및 실행/활성화
353+ yum install docker -y
354+ systemctl enable docker
355+ systemctl start docker
356+
357+ # 도커 네트워크 생성
358+ docker network create common
359+
360+ echo "${ var . github_access_token_1 } " | docker login ghcr.io -u ${ var . github_access_token_1_owner } --password-stdin
361+
362+ END_OF_FILE
363+ }
364+
365+ # EC2 인스턴스 생성
366+ resource "aws_instance" "unihub_ec2_2" {
367+ # 사용할 AMI ID
368+ ami = data. aws_ami . latest_amazon_linux . id
369+ # EC2 인스턴스 유형
370+ instance_type = " t3.small"
371+ # 사용할 서브넷 ID
372+ subnet_id = aws_subnet. unihub_subnet_1 . id
373+ # 적용할 보안 그룹 ID
374+ vpc_security_group_ids = [aws_security_group . unihub_sg_1 . id ]
375+ # 퍼블릭 IP 연결 설정
376+ associate_public_ip_address = true
377+
378+ # 인스턴스에 IAM 역할 연결
379+ iam_instance_profile = aws_iam_instance_profile. unihub_instance_profile_1 . name
380+
381+ # 인스턴스에 태그 설정
382+ tags = {
383+ Name = " ${ var . prefix } -ec2-monitor"
384+ }
385+
386+ # 루트 볼륨 설정
387+ root_block_device {
388+ volume_type = " gp3"
389+ volume_size = 25
390+ }
391+
392+ user_data = <<- EOF
393+ ${ local . ec2_monitoring_base }
394+ EOF
395+ }
396+
397+ # 2) 탄력적 IP 할당
398+ resource "aws_eip" "unihub_eip_2" {
399+ domain = " vpc"
400+ instance = aws_instance. unihub_ec2_2 . id
401+ tags = {
402+ Name = " ${ var . prefix } -eip-monitor"
403+ }
404+ }
You can’t perform that action at this time.
0 commit comments