Skip to content

Instantly share code, notes, and snippets.

@sanchezl
Last active January 30, 2020 20:56
Show Gist options
  • Save sanchezl/3650dba7c0e9b4ece302c27bf1acd6d1 to your computer and use it in GitHub Desktop.
Save sanchezl/3650dba7c0e9b4ece302c27bf1acd6d1 to your computer and use it in GitHub Desktop.
Cleanup Route 53 resource record sets when deleting an OpenShift Cluster. Requires `jq` and `aws`.
#!/usr/bin/env bash
cluster_name=$1
hosted_zone_dns_name=$2
hosted_zone_id=$(
aws route53 list-hosted-zones-by-name \
--dns-name ${hosted_zone_dns_name} \
--query HostedZones[0].Id \
--output text
)
resource_record_sets=$( \
aws route53 list-resource-record-sets \
--hosted-zone-id "${hosted_zone_id}" \
--query "ResourceRecordSets[?contains(Name,'${cluster_name}')]" \
--output json
)
if [ "${resource_record_sets}" = "[]" ] ; then
printf "No resource record sets found for cluster %s\n" "${cluster_name}"
exit
fi
batch=$( \
jq '{ "Changes":[ .[] | {"Action":"DELETE", "ResourceRecordSet": . }]}' <<< "${resource_record_sets}"
)
printf "Requesting deletion of resource record sets..."
change_info_id=$(
aws route53 change-resource-record-sets \
--hosted-zone-id "${hosted_zone_id}" \
--query ChangeInfo.Id \
--output text \
--change-batch "${batch}"
)
printf "\n"
printf "Waiting for resource record sets to be deleted..."
aws route53 wait resource-record-sets-changed --id "${change_info_id}"
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment