I'm using a Google Cloud Platform load balancer to redirect my HTTP and HTTPS traffic. For the SSL cert I'm using letsencrypt. I have a cron to refresh the cert and upload it on gcloud.
I'm looking for a way to add / replace the cert on a the load balancer like in the UI.
My current script
#!/bin/bash
# This script must be run as root or sudo
cert_path=/etc/letsencrypt/live/domain.co
project_ids=("domain-xxxxx")
date=`date +%d-%m-%Y`
certname="domain-cert-${date}"
lb_cert() {
# Multiples projects
for project_id in "${project_ids[@]}"; do
gcloud config set project $project_id
gcloud compute ssl-certificates create $certname --certificate "${cert_path}/cert.pem" --private-key "${cert_path}/privkey.pem"
done
}
certbot renew --quiet
if [[ "$?" -ne 0 ]]; then
lb_cert
fi