GitHub - 5a6io/OliveSafety: Cloud Wave 3๊ธฐ ํ๋ก์ ํธ olivesafety
Cloud Wave 3๊ธฐ ํ๋ก์ ํธ olivesafety. Contribute to 5a6io/OliveSafety development by creating an account on GitHub.
github.com
Cloud Wave์์ ํ๋ก์ ํธ๋ฅผ ์ํํ์ ๋ ์ฝ์๋ก ์์ ํด Terraform ์ฝ๋๋ก ์์ฑํด๋ณด๋ ค๊ณ ํ๋ค. ๋จผ์ Network์ ๊ด๋ จ๋ ๋ชจ๋์ ์์ฑํด๋ณด๊ฒ ๋ค.
๐๋ชจ๋ ๊ตฌ์ฑ์ ํ์ํ ๋ฆฌ์์ค
IAM: aws_iam_role, aws_iam_role_policy_attachmentSecurity Group: aws_security_gruop
โ๏ธIAM ๋ชจ๋
main.tf
# EKS Cluster
resource "aws_iam_role" "cluster" {
name = "${var.project_name}-cluster-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"sts:AssumeRole",
"sts:TagSession"
]
Effect = "Allow"
Principal = {
Service = "eks.amazonaws.com"
}
},
]
})
tags = merge(var.common_tags, {
Name = "${var.project_name}-cluster-role"
})
}
# EKS Node Group
resource "aws_iam_role_policy_attachment" "AmazonEKSClusterPolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.cluster.name
}
resource "aws_iam_role" "node" {
name = "${var.project_name}-node-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
}]
})
tags = merge(var.common_tags, {
Name = "${var.project_name}-node-role"
})
}
resource "aws_iam_role_policy_attachment" "AmazonEKSWorkerNodePolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "AmazonEKS_CNI_Policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "AmazonEC2ContainerRegistryReadOnly" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.example.name
}
variables.tf
variable "project_name" {
type = string
}
variable "common_tags" {
type = map(string)
default = {}
}
์์์๋ role๋ง ๋ง๋ค์์ง๋ง ์ด์ธ์๋ user๋ group๋ ๊ฐ๋ฅํ๋ค. ๊ทธ๋ ์ง๋ง ๋๋ ๋ฆฌ์์ค์ ๋ํ role๋ง ํ์ํ๊ธฐ ๋๋ฌธ์ role์ ์์ฑํ๋ค.์ฐ์ EKS ํด๋ฌ์คํฐ์ ๋ ธ๋ ๊ด๋ จ Role๋ง ์ ๋ฆฌํด๋์๋ค. ์ถํ์ ๋ ํ์ํ role์ด ์๋ค๋ฉด ์ถ๊ฐํ ์์ ์ด๋ค. ๊ทธ๋ฆฌ๊ณ outputs.tf๋ ํ์ํ๋ค๋ฉด ์ถ๊ฐํ ์์ ์ด๋ค.
โ๏ธSecurity Group ๋ชจ๋
main.tf
# EKS
resource "aws_security_group" "sg_eks" {
name = "${var.project_name}-sg-eks"
vpc_id = var.vpc_id
tags = merge(var.common_tags, {
name = "${var.project_name}-sg-eks"
})
}
resource "aws_vpc_security_group_ingress_rule" "eks_ingress" {
security_group_id = aws_security_group.sg_eks.id
from_port = "ํฌํธ ๋ฒํธ"
ip_protocol = "tcp"
to_port = "ํฌํธ ๋ฒํธ"
tags = merge(var.common_tags, {
Name = "${var.project_name}-eks-ingress"
})
}
# RDS
resource "aws_security_group" "sg_rds" {
name = "${var.project_name}-sg-rds"
vpc_id = var.vpc_id
tags = merge(var.common_tags, {
Name = "${var.project_name}-sg-rds"
})
}
resource "aws_vpc_security_group_ingress_rule" "rds_ingress" {
security_group_id = aws_security_group.sg_rds.id
from_port = "ํฌํธ ๋ฒํธ"
ip_protocol = "tcp"
to_port = "ํฌํธ ๋ฒํธ"
tags = merge(var.common_tags, {
Name = "${var.project_name}-rds-ingress"
})
}
outputs.tf
output "sg_eks" {
value = aws_security_group.sg_eks.id
}
output "sg_rds" {
value = aws_security_group.sg_rds.id
}
variables.tf
variable "project_name" {
type = string
}
variable "common_tags" {
type = map(string)
default = {}
}
variable "vpc_id" {
type = string
}
๐๋ชจ๋ ์์ฑ
02-security.tf
module "iam" {
source = "../modules/security/iam"
project_name = var.project_name
common_tags = var.common_tags
}
module "sg" {
source = "../modules/security/security-group"
project_name = var.project_name
common_tags = var.common_tags
vpc_id = module.vpc.vpc_id
}
์ด๋ ๊ฒ ์ฌ์ฉํ๊ณ ์ ํ๋ ๋ชจ๋์ ํธ์ถํ๋ฉด ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ค๋ฅธ ๋ชจ๋์์ ์ฌ์ฉํ ๋ modules.iam์ด๋ modules.sg๋ก ํธ์ถํ๋ฉด ๋๋ค.
๋ค์์๋ EKS์ ECS์ ๋ํด์ ์์ฑํ๊ณ ์ ํ๋ค. EKS๋ Cloud Wave ํ๋ก์ ํธ์์ ํ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ์์ฑํ๊ฒ ๋ค. ๊ทธ๋ฆฌ๊ณ ECS๋ ์ต๊ทผ Softbank Hackathon์์ ์ํํ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ํ๊ฒ ๋ค.
์์ฑํ ์ฝ๋๋ ์๋ ๊นํ๋ธ์์ ๋ณผ ์ ์์ต๋๋ค.
GitHub - 5a6io/Cloud-Wave-Project-Terraform: Cloud Wave 3๊ธฐ ํ๋ก์ ํธ Terraform ์ฝ๋
Cloud Wave 3๊ธฐ ํ๋ก์ ํธ Terraform ์ฝ๋. Contribute to 5a6io/Cloud-Wave-Project-Terraform development by creating an account on GitHub.
github.com
'Cloud > IaC' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [IaC] Terraform Module๋ก AWS Network ์์ฑ (0) | 2025.11.11 |
|---|---|
| [IaC] Terraform module ์์ฑ (1) | 2025.07.18 |
| [IaC] Terraform์ผ๋ก AWS ์ธํ๋ผ ๊ด๋ฆฌ ๋ฐ ์๋ํ (0) | 2025.06.30 |
| [IaC] ํ ๋ผํผ(Terraform)์ด๋? (0) | 2025.06.28 |