Skip to content

Commit fe740e9

Browse files
committed
Merge branch 'load-balancer-cleanup' into 'master'
Load balancer cleanup + Certbot See merge request postgres-ai/database-lab-infrastructure!9
2 parents 5b26a10 + aa10f01 commit fe740e9

File tree

10 files changed

+106
-230
lines changed

10 files changed

+106
-230
lines changed

api_dns.tf

Lines changed: 0 additions & 93 deletions
This file was deleted.

api_ssl_endpoint.tf

Lines changed: 0 additions & 70 deletions
This file was deleted.

clones_dns.tf

Lines changed: 0 additions & 13 deletions
This file was deleted.

dle-logical-init.sh.tpl

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,35 @@ set -x
44

55
sleep 20
66
#run certbot and copy files to envoy
7-
# to avoid restrinctions from letsencrypt like "There were too many requests of a given type :: Error creating new order :: too many certificates (5) already issued for this exact set of domains in the last 168 hours: demo-api-engine.aws.postgres.ai: see https://letsencrypt.org/docs/rate-limits/" follwing three lines were commented out and mocked up. In real implementation inline certs have to be removed and letsencrypt generated certs should be used
8-
#sudo certbot certonly --standalone -d demo-api-engine.aws.postgres.ai -m m@m.com --agree-tos -n
9-
#sudo cp /etc/letsencrypt/archive/demo-api-engine.aws.postgres.ai/fullchain1.pem /etc/envoy/certs/
10-
#sudo cp /etc/letsencrypt/archive/demo-api-engine.aws.postgres.ai/privkey1.pem /etc/envoy/certs/
7+
# to avoid restrinctions from letsencrypt like "There were too many requests of a given type ::
8+
# Error creating new order :: too many certificates (5) already issued for this exact set of domains
9+
# in the last 168 hours: demo-api-engine.aws.postgres.ai: see https://letsencrypt.org/docs/rate-limits/"
10+
# follwing three lines were commented out and mocked up. In real implementation inline certs have to be
11+
# removed and letsencrypt generated certs should be used
12+
13+
14+
# <START certbot generated cert>
15+
#
16+
#sudo certbot certonly --standalone -d ${aws_deploy_dns_api_subdomain}.${aws_deploy_dns_zone_name} -m ${aws_deploy_certificate_email} --agree-tos -n
17+
#sudo cp /etc/letsencrypt/live/${aws_deploy_dns_api_subdomain}.${aws_deploy_dns_zone_name}/fullchain.pem /etc/envoy/certs/fullchain1.pem
18+
#sudo cp /etc/letsencrypt/live/${aws_deploy_dns_api_subdomain}.${aws_deploy_dns_zone_name}/privkey.pem /etc/envoy/certs/privkey1.pem
19+
20+
# cat <<EOF > /etc/letsencrypt/renewal-hooks/deploy/envoy.deploy
21+
# #!/bin/bash
22+
# umask 0177
23+
# export DOMAIN=${aws_deploy_dns_api_subdomain}.${aws_deploy_dns_zone_name}
24+
# export DATA_DIR=/etc/envoy/certs/
25+
# cp /etc/letsencrypt/live/$DOMAIN/fullchain.pem $DATA_DIR/fullchain1.pem
26+
# cp /etc/letsencrypt/live/$DOMAIN/privkey.pem $DATA_DIR/privkey1.pem
27+
# EOF
28+
# sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/envoy.deploy
29+
#
30+
# # <END certbot generated cert>
31+
#
32+
# FIXME
33+
# 1. Write script to edit the `/etc/envoy/envoy.yaml` file so that it replaces the wildcard domains with specific domain
34+
35+
1136
cat <<EOF > /etc/envoy/certs/fullchain1.pem
1237
-----BEGIN CERTIFICATE-----
1338
MIICqDCCAZACCQCquzpHNpqBcDANBgkqhkiG9w0BAQsFADAWMRQwEgYDVQQDDAtm
@@ -62,7 +87,7 @@ sudo systemctl enable envoy
6287
sudo systemctl start envoy
6388

6489
#create zfs pools
65-
disks=(${dle_disks})
90+
disks=(${dle_disks})
6691
for i in $${!disks[@]}; do
6792
sudo zpool create -f \
6893
-O compression=on \
@@ -71,11 +96,11 @@ for i in $${!disks[@]}; do
7196
-O logbias=throughput \
7297
-m /var/lib/dblab/dblab_pool_0$i\
7398
dblab_pool_0$i \
74-
$${disks[$i]}
99+
$${disks[$i]}
75100
done
76101

77102
#configure and start DLE
78-
mkdir ~/.dblab
103+
mkdir ~/.dblab
79104
#cp /home/ubuntu/.dblab/config.example.logical_generic.yml ~/.dblab/server.yml
80105
curl https://gitlab.com/postgres-ai/database-lab/-/raw/${dle_version_full}/configs/config.example.logical_generic.yml --output ~/.dblab/server.yml
81106
sed -ri "s/^(\s*)(debug:.*$)/\1debug: ${dle_debug_mode}/" ~/.dblab/server.yml

dns.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* This file sets up all resources necessary to route incoming
3+
* HTTPS requests to the Load Balancer defined in api_ssl_endpoint.
4+
*
5+
* It assumes that the AWS account has a Route 53 hosted zone
6+
* and then provisions a sub-domain that will be used to point
7+
* to the load balancer
8+
*/
9+
10+
11+
data "aws_route53_zone" "dblab_zone" {
12+
name = var.aws_deploy_dns_zone_name
13+
}
14+
15+
###
16+
# FIXME: Understand when this is and is not needed
17+
# This record was created manually within the Postgres.ai hosted zone
18+
# due to issues when attempting to validate the AWS issue certificate.
19+
# If this is necessary in all circumstances, then this Terraform
20+
# resource should be close to correct.
21+
#
22+
#resource "aws_route53_record" "dblab_subdomain_caa" {
23+
# name = var.aws_deploy_dns_zone_name
24+
# type = "CAA"
25+
#
26+
# records = [
27+
# "0 issue \"amazon.com\"",
28+
# "0 issue \"amazontrust.com\"",
29+
# "0 issue \"awstrust.com\"",
30+
# "0 issue \"amazonaws.com\"",
31+
# "0 issue \"letsencrypt.org\""
32+
# ]
33+
#
34+
# zone_id = data.aws_route53_zone.dblab_zone.zone_id
35+
# ttl = "60"
36+
#}
37+
38+
resource "aws_route53_record" "dblab_subdomain" {
39+
name = var.aws_deploy_dns_api_subdomain
40+
type = "CNAME"
41+
42+
# TODO -- Allocate an Elastic IP address for the instance rather than using the
43+
# default assigned public DNS which can rotate
44+
records = [
45+
aws_instance.aws_ec2.public_dns
46+
]
47+
48+
zone_id = data.aws_route53_zone.dblab_zone.zone_id
49+
ttl = "60"
50+
}

instance.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ data "template_file" "init" {
3030
dle_retrieval_refresh_timetable = "${var.dle_retrieval_refresh_timetable}"
3131
dle_disks = "${join(" ",var.aws_deploy_ec2_volumes_names)}"
3232
dle_version_full = "${var.dle_version_full}"
33+
aws_deploy_dns_zone_name = "${var.aws_deploy_dns_zone_name}"
3334
aws_deploy_dns_api_subdomain = "${var.aws_deploy_dns_api_subdomain}"
35+
aws_deploy_certificate_email = "{var.aws_deploy_certificate_email}"
3436
source_postgres_dbname = "${var.source_postgres_dbname}"
3537
source_postgres_host = "${var.source_postgres_host}"
3638
source_postgres_port = "${var.source_postgres_port}"
@@ -40,7 +42,7 @@ data "template_file" "init" {
4042
postgres_config_shared_preload_libraries = "${var.postgres_config_shared_preload_libraries}"
4143
platform_access_token = "${var.platform_access_token}"
4244
platform_project_name = "${var.platform_project_name}"
43-
platform_joe_signing_secret = "${random_string.platform_joe_signing_secret.result}"
45+
platform_joe_signing_secret = "${random_string.platform_joe_signing_secret.result}"
4446
vcs_db_migration_checker_verification_token = "${random_string.vcs_db_migration_checker_verification_token.result}"
4547
vcs_github_secret_token = "${var.vcs_github_secret_token}"
4648
}

outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ output "aws_ec2_instance_dns" {
88
value = "${aws_instance.aws_ec2.public_dns}"
99
}
1010
output "platform_dle_registration_url" {
11-
value = "${format("%s://%s", "https",join("", aws_route53_record.dblab_clones_subdomain.*.fqdn))}"
11+
value = "${format("%s://%s", "https",join("", aws_route53_record.dblab_subdomain.*.fqdn))}"
1212
}
1313
output "platform_joe_registration_url" {
14-
value = "${format("%s://%s:%s", "https",join("", aws_route53_record.dblab_clones_subdomain.*.fqdn),"444")}"
14+
value = "${format("%s://%s:%s", "https",join("", aws_route53_record.dblab_subdomain.*.fqdn),"444")}"
1515
}
1616
output "dle_verification_token" {
1717
value = "${random_string.dle_verification_token.result}"
@@ -23,5 +23,5 @@ output "vcs_db_migration_checker_verification_token" {
2323
value = "${random_string.vcs_db_migration_checker_verification_token.result}"
2424
}
2525
output "vcs_db_migration_checker_registration_url" {
26-
value = "${format("%s://%s:%s", "https",join("", aws_route53_record.dblab_clones_subdomain.*.fqdn),"445")}"
26+
value = "${format("%s://%s:%s", "https",join("", aws_route53_record.dblab_subdomain.*.fqdn),"445")}"
2727
}

0 commit comments

Comments
 (0)