Skip to content

Instantly share code, notes, and snippets.

@Jlaird
Last active May 23, 2022 16:20
Show Gist options
  • Save Jlaird/58c6c6bff92f14d5043954ba71c1e863 to your computer and use it in GitHub Desktop.
Save Jlaird/58c6c6bff92f14d5043954ba71c1e863 to your computer and use it in GitHub Desktop.
Setup the default DNS for the new sites.
#!/bin/bash
if [ -z "$1" ]
then
read -p 'Please enter a domain: ' domain
else
domain=$1
fi
#########################################################
####### Setup Domains #######
#########################################################
# platform
cli53 rrcreate "$domain" 'platform 300 CNAME apps.baseplatform.io.'
# manage
cli53 rrcreate "$domain" 'manage AWS ALIAS CNAME platform $self false'
# contracts
cli53 rrcreate "$domain" 'contracts AWS ALIAS CNAME platform $self false'
# email
cli53 rrcreate "$domain" 'email AWS ALIAS CNAME platform $self false'
# platform
cli53 rrcreate "$domain" 'base-cms 300 CNAME apps.base-cms.io.'
# next
cli53 rrcreate "$domain" 'next AWS ALIAS CNAME base-cms $self false'
# Radix
cli53 rrcreate "$domain" 'radix 300 CNAME radix.as3.io.'
# Imgix
cli53 rrcreate "$domain" 'img 300 CNAME img.base-cms.io.'
########################################################
###### Create Cert #######
########################################################
echo "Generating Cert..."
arn=$(aws acm request-certificate --domain-name "*.$domain" --validation-method DNS --output text) && sleep 2
output=$(aws acm describe-certificate --certificate-arn "$arn" --output text)
#Clean up spaces and tabs
output=${output//[[:blank:]]/}
regex="RESOURCERECORD(.*)CNAME(.*)OPTIONSENABLED"
if [[ $output =~ $regex ]] ; then
cname=${BASH_REMATCH[1]/.$domain./}
cname_value=${BASH_REMATCH[2]}
#echo "Creating Validation Domain CName: $cname Value: $cname_value"
cli53 rrcreate "$domain" "$cname CNAME $cname_value"
else
echo "Can't find CName for domain validation."
fi
echo "Waiting for Cert..."
aws acm wait certificate-validated --certificate-arn $arn
echo "Cert Created!"
########################################################
###### ALB Setup #######
########################################################
#@todo put cert on ALB
echo "Add cert to ALB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment