Skip to content

Commit

Permalink
chore: update Let's Encrypt staging environment
Browse files Browse the repository at this point in the history
In order to avoid running into Let's Encrypt rate limits, the Caddyfile
configuration now uses the Let's Encrypt staging environment as a
reverse proxy server.
  • Loading branch information
sydrawat01 committed Oct 26, 2023
1 parent 26ad717 commit dd4e266
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion modules/ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ resource "aws_instance" "jenkins_server" {
}

user_data = base64encode("${templatefile("../modules/ec2/userdata.sh", {
DOMAIN_NAME = "jenkins.${var.domain_name}"
DOMAIN_NAME = "jenkins.${var.domain_name}",
ENVIRONMENT = "${var.environment}"
})}")

tags = {
Expand Down
19 changes: 12 additions & 7 deletions modules/ec2/userdata.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#!/bin/bash

cd /etc/caddy/ || exit
sudo mv Caddyfile Caddyfile.backup
sudo mv Caddyfile Caddyfile.bkp
touch Caddyfile
echo "${DOMAIN_NAME}" >domain.txt

tee -a ./Caddyfile <<END
{
acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
if [ "$ENVIRONMENT" = "prod" ]; then
echo "${DOMAIN_NAME} {
root * /usr/share/caddy
reverse_proxy localhost:8080
}" | tee ./Caddyfile
else
echo "{
acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
${DOMAIN_NAME} {
root * /usr/share/caddy
reverse_proxy localhost:8080
}
END
}" | tee ./Caddyfile

fi

sudo systemctl restart caddy.service
1 change: 1 addition & 0 deletions modules/ec2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ variable "domain_name" {}
variable "igw_id" {}
variable "vpc_id" {}
variable "ssh_key_name" {}
variable "environment" {}
1 change: 1 addition & 0 deletions root/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ module "ec2" {
igw_id = module.vpc.igw_id
vpc_id = module.vpc.vpc_id
ssh_key_name = module.ssh.ssh_key_name
environment = var.env
}

0 comments on commit dd4e266

Please sign in to comment.