-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jenkins instance + eip + route53
* patch: update github actions workflow file tfvars * fix: github actions workflow set environment
- Loading branch information
1 parent
79f7d09
commit f1eb39a
Showing
11 changed files
with
189 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
data "aws_ami" "jenkins_ami" { | ||
most_recent = true | ||
owners = var.root_account_ids | ||
|
||
filter { | ||
name = "name" | ||
values = [var.ami_prefix] | ||
} | ||
|
||
filter { | ||
name = "root-device-type" | ||
values = ["ebs"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
} | ||
|
||
resource "aws_security_group" "jenkins_sg" { | ||
name = "JenkinsServerSG" | ||
description = "Allow TLS inbound traffic" | ||
vpc_id = var.vpc_id | ||
|
||
ingress { | ||
description = "HTTP" | ||
from_port = 80 | ||
to_port = 80 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
ingress { | ||
description = "HTTPS" | ||
from_port = 443 | ||
to_port = 443 | ||
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 = "JenkinsServerSG" | ||
} | ||
} | ||
|
||
resource "aws_network_interface" "jenkins_server_nic" { | ||
subnet_id = var.public_subnets[0] | ||
security_groups = [aws_security_group.jenkins_sg.id] | ||
|
||
tags = { | ||
Name = "jenkins_server_network_interface" | ||
} | ||
} | ||
|
||
resource "aws_eip" "jenkins_server_eip" { | ||
domain = "vpc" | ||
|
||
# instance = aws_instance.jenkins_server.id | ||
network_interface = aws_network_interface.jenkins_server_nic.id | ||
depends_on = [var.igw_id] | ||
|
||
# TODO: tags | ||
} | ||
|
||
resource "aws_instance" "jenkins_server" { | ||
ami = data.aws_ami.jenkins_ami.id | ||
instance_type = var.instance_type | ||
|
||
network_interface { | ||
network_interface_id = aws_network_interface.jenkins_server_nic.id | ||
device_index = 0 | ||
} | ||
|
||
user_data = base64encode("${templatefile("../modules/ec2/userdata.sh", { | ||
DOMAIN_NAME = "jenkins.${var.domain_name}" | ||
})}") | ||
|
||
tags = { | ||
Name = "Jenkins Server" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "jenkins_server_eip_public_ip" { | ||
value = aws_eip.jenkins_server_eip.public_ip | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
cd /etc/caddy/ || exit | ||
sudo mv Caddyfile Caddyfile.backup | ||
touch Caddyfile | ||
echo "${DOMAIN_NAME}" > domain.txt | ||
|
||
tee -a ./Caddyfile << END | ||
${DOMAIN_NAME} { | ||
root * /usr/share/caddy | ||
reverse_proxy localhost:8080 | ||
} | ||
END | ||
|
||
sudo systemctl restart caddy.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
variable "root_account_ids" {} | ||
variable "ami_prefix" {} | ||
variable "instance_type" {} | ||
variable "public_subnets" {} | ||
variable "domain_name" {} | ||
variable "igw_id" {} | ||
variable "vpc_id" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
data "aws_route53_zone" "jenkins" { | ||
name = var.domain_name | ||
} | ||
|
||
resource "aws_route53_record" "www" { | ||
zone_id = data.aws_route53_zone.jenkins.zone_id | ||
name = "jenkins.${var.domain_name}" | ||
type = "A" | ||
ttl = 300 | ||
records = [var.jenkins_server_eip_public_ip] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
variable "domain_name" {} | ||
variable "jenkins_server_eip_public_ip" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters