Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Terraform/module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ module "gitfolio_alb" {
backend_resume_id = module.gitfolio_back[1].instance_id
backend_notification_id = module.gitfolio_back[2].instance_id
k8s_id = null #module.gitfolio_k8s[0].instance_id
jenkins_id = module.gitfolio_cicd[0].jenkins_instance_id

route53_domain = var.route53_domain
lb_type = var.lb_type
Expand Down
8 changes: 8 additions & 0 deletions Terraform/module/LB/alb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ resource "aws_security_group" "alb" {
cidr_blocks = [var.any_ip]
}

ingress {
description = "Jenkins"
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = [var.any_ip]
}

egress {
from_port = 0
to_port = 0
Expand Down
53 changes: 53 additions & 0 deletions Terraform/module/LB/jenkins.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
resource "aws_lb_listener_rule" "jenkins" {
listener_arn = aws_lb_listener.https.arn
priority = 50000 // 다른 서비스들과 겹치지 않는 우선순위 사용

action {
type = "forward"
target_group_arn = aws_lb_target_group.jenkins.arn
}

condition {
path_pattern {
values = ["/jenkins", "/jenkins/*"] // /jenkins 하위의 모든 경로를 Jenkins로 라우팅
}
}

condition {
host_header {
values = ["dev.gitfolio.site"]
}
}

tags = {
Name = "Gitfolio Jenkins routing"
}
}

resource "aws_lb_target_group" "jenkins" {
name = "gitfolio-jenkins-tg"
port = 8080 // Jenkins의 기본 포트
protocol = var.target_protocol
vpc_id = var.vpc_id

health_check {
enabled = true
healthy_threshold = var.health_threshold
interval = var.health_interval
matcher = "200,302,403" // Jenkins는 로그인 페이지로 리다이렉트할 수 있으므로 302도 허용
path = "/jenkins/login"
port = var.health_port
protocol = var.health_protocol
timeout = var.health_timeout
unhealthy_threshold = var.health_unthreshold
}

tags = {
Name = "Gitfolio lb jenkins target group"
}
}

resource "aws_lb_target_group_attachment" "jenkins" {
target_group_arn = aws_lb_target_group.jenkins.arn
target_id = var.jenkins_id // Jenkins 인스턴스 ID
}
5 changes: 5 additions & 0 deletions Terraform/module/LB/variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ variable "redis_id" {
variable "k8s_id" {
description = "ID of k8s master instance"
type = string
}
# 젠킨스용
variable "jenkins_id" {
description = "ID of k8s jenkins_instance_id instance"
type = string
}
14 changes: 14 additions & 0 deletions Terraform/module/node/cicd/jenkins-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Java 설치 (Jenkins 필요조건)
sudo yum update -y
sudo yum install java-17-amazon-corretto -y

# Jenkins 리포지토리 설정
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

# Jenkins 설치
sudo yum install jenkins -y

# Jenkins 서비스 시작
sudo systemctl start jenkins
sudo systemctl enable jenkins
4 changes: 2 additions & 2 deletions Terraform/module/node/cicd/output.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "instance_id" {
description = "ID of the instance"
output "jenkins_instance_id" {
description = "The ID of the Jenkins EC2 instance"
value = aws_instance.jenkins.id
}
Loading