Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

now deletes all zones if multiple found #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions bin/aws-route53-wipe-hosted-zone
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,40 @@ VERBOSE=true
for domain_to_delete in "$@"; do
$VERBOSE && echo "DESTROYING: $domain_to_delete in Route 53"

hosted_zone_id=$(
hosted_zone_ids=$(
aws route53 list-hosted-zones \
--output text \
--query 'HostedZones[?Name==`'$domain_to_delete'.`].Id'
)


$VERBOSE &&
echo hosted_zone_id=${hosted_zone_id:?Unable to find: $domain_to_delete}
echo hosted_zone_ids=${hosted_zone_ids:?Unable to find: $domain_to_delete}

aws route53 list-resource-record-sets \
--hosted-zone-id $hosted_zone_id |
jq -c '.ResourceRecordSets[]' |
while read -r resourcerecordset; do
read -r name type <<<$(jq -r '.Name,.Type' <<<"$resourcerecordset")
if [ $type == "NS" -o $type == "SOA" ]; then
$VERBOSE && echo "SKIPPING: $type $name"
else
change_id=$(aws route53 change-resource-record-sets \
--hosted-zone-id $hosted_zone_id \
--change-batch '{"Changes":[{"Action":"DELETE","ResourceRecordSet":
'"$resourcerecordset"'
}]}' \
--output text \
--query 'ChangeInfo.Id')
$VERBOSE && echo "DELETING: $type $name $change_id"
fi
done
for hosted_zone_id in ${hosted_zone_ids}; do
aws route53 list-resource-record-sets \
--hosted-zone-id $hosted_zone_id |
jq -c '.ResourceRecordSets[]' |
while read -r resourcerecordset; do
read -r name type <<<$(jq -r '.Name,.Type' <<<"$resourcerecordset")
if [ $type == "NS" -o $type == "SOA" ]; then
$VERBOSE && echo "SKIPPING: $type $name"
else
change_id=$(aws route53 change-resource-record-sets \
--hosted-zone-id $hosted_zone_id \
--change-batch '{"Changes":[{"Action":"DELETE","ResourceRecordSet":
'"$resourcerecordset"'
}]}' \
--output text \
--query 'ChangeInfo.Id')
$VERBOSE && echo "DELETING: $type $name $change_id"
fi
done

change_id=$(aws route53 delete-hosted-zone \
--id $hosted_zone_id \
--output text \
--query 'ChangeInfo.Id')
$VERBOSE && echo "DELETING: hosted zone for $domain_to_delete $change_id"
change_id=$(aws route53 delete-hosted-zone \
--id $hosted_zone_id \
--output text \
--query 'ChangeInfo.Id')
$VERBOSE && echo "DELETING: hosted zone for $domain_to_delete $change_id"
done
done