Notice
Recent Posts
Recent Comments
Link
«   2024/08   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

우당탕탕 개발일지

테라폼 3-Tier 아키텍처 구축(1) - 보안그룹 본문

Cloud

테라폼 3-Tier 아키텍처 구축(1) - 보안그룹

YUDENG 2023. 11. 26. 05:16

3-Tier 아키텍처란?

어떠한 플랫폼이나 애플리케이션을 3계층으로 나누어 별도의 논리적/물리적인 장치에 구축 및 운영하는 형태이다. 통 프레젠테이션 계층, 어플리케이션 계층, 데이터 계층으로 나눈다.

 

  • 프젠테이션 계층
    - 사용자가 애플리케이션과 상호작용하는 인터페이스
    - 일반적으로 HTML, JS, CSS 등이 이 계층에 포함되며, 프론트엔드라고 불린다.
  • 애플리케이션 계층
    - 요청되는 정보를 어떠한 규칙에 따라 처리하고 가공한다.

    - 백엔드로 불린다.
  • 데이터 계층
    - 데이터 베이스와 데이터 베이스에 접근하여 데이터를 CRUD 한다.

 

폴더 구조

- dev/ : Terraform 구성이 정의된 파일

- modules/ : 리소스 집합

 

3-Tier 아키텍처 구현

[ sg ] 보안 그룹

* Source: 출발지, cidr_blocks 또는 Security Group

* Port: Source에서 들어오는 Port Number

 

- vpc-security-group

VPC SG Type Protocol Port Source
INGRESS SSH TCP 22 IP
HTTP TCP 80 IP
ICMP ICMP -1 IP

 

- web-security-group

WEB SG Type Protocol Port Source
INGRESS SSH TCP 22 VPC SG
HTTP TCP 80 0.0.0.0/0

 

- was-security-group

WEB SG Type Protocol Port Source
INGRESS SSH TCP 22 VPC SG
Custom TCP TCP 8080 10.0.11.0/24
10.0.12.0/24

 

- rds-security-group

RDS SG Type Protocol Port Source
INGRESS MYSQL TCP 3306 WAS SG
Custom TCP TCP 8080 LB SG

 

####################################
#   VPC Security Group
####################################
resource "aws_security_group" "vpc_security_group" {
  name        = "vpc_security_group"
  description = "Allow SSH/HTTP/ICMP inbound traffic"
  vpc_id      = var.vpc-id

  ingress {
    description      = "Allow SSH from VPC"
    from_port        = 22
    to_port          = 22
    protocol         = "tcp"
    cidr_blocks      = ["0.0.0.0/0"]
  }

  ingress {
    description      = "Allow HTTP from VPC"
    from_port        = 80
    to_port          = 80
    protocol         = "tcp"
    cidr_blocks      = ["0.0.0.0/0"]
  }

  ingress {
    description      = "Allow ICMP from VPC"
    from_port        = -1
    to_port          = -1
    protocol         = "icmp"
    cidr_blocks      = ["0.0.0.0/0"]
  }
  
  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]
  }

  tags = {
    Name = "vpc_security_group"
  }
}

####################################
#   WEB Security Group
####################################
resource "aws_security_group" "web_security_group" {
  name        = "web_security_group"
  description = "Allow SSH/HTTP inbound traffic"
  vpc_id      = var.vpc-id

  ingress {
    description      = "Allow SSH from VPC"
    from_port        = 22
    to_port          = 22
    protocol         = "tcp"
    security_groups = [var.vpc-sg-id]
  }

  ingress {
    description      = "Allow HTTP from VPC"
    from_port        = 80
    to_port          = 80
    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"]
  }

  tags = {
    Name = "web_security_group"
  }
}


####################################
#   WAS Security Group
####################################
resource "aws_security_group" "was_security_group" {
  name        = "was_security_group"
  description = "Allow SSH inbound traffic"
  vpc_id      = var.vpc-id

  ingress {
    description      = "Allow SSH from VPC"
    from_port        = 22
    to_port          = 22
    protocol         = "tcp"
    security_groups = [var.vpc-sg-id]
  }

  ingress {
    from_port   = 8080
    to_port     = 8080
    protocol    = "tcp"
    cidr_blocks = ["10.0.11.0/24", "10.0.12.0/24"]
  }

  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]
  }

  tags = {
    Name = "was_security_group"
  }
}
####################################
#   RDS Security Group
####################################
resource "aws_security_group" "rds_security_group" {
  name        = "rds_security_group"
  description = "RDS Security Group"
  vpc_id      = var.vpc-id

  ingress {
    from_port   = 3306
    to_port     = 3306
    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"]
  }

  tags = {
    Name = "rds_security_group"
  }
}

- variable.tf

variable "vpc-id" {
  description = "VPC ID"
  type        = string
}

variable "vpc-sg-id" {
  description = "VPC Security Group ID"
  type        = string
}

- outputs.tf

output "vpc_security_group_id" {
  description = "VPC Security Group ID"
  value = aws_security_group.vpc_security_group.id
}

output "web_security_group_id" {
  description = "WEB Security Group ID"
  value = aws_security_group.web_security_group.id
}
output "was_security_group_id" {
  description = "WAS Security Group ID"
  value = aws_security_group.was_security_group.id
}

output "rds_security_group_id" {
  description = "RDS Security Group ID"
  value = aws_security_group.rds_security_group.id
}
728x90

'Cloud' 카테고리의 다른 글

모니터링 구축  (2) 2024.01.05
Linux Git  (0) 2023.12.12
테라폼 3-Tier 아키텍처 구축(2) - VPC, EC2  (1) 2023.11.26
테라폼 개발 환경 준비  (1) 2023.11.26
CI/CD 파이프라인 - GCP를 통한 Jenkins CI 구축  (0) 2023.10.30