-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathr53_migrator.sh
80 lines (67 loc) · 2.66 KB
/
r53_migrator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# This script is used to migrate a Route 53 Hosted Zone from one AWS account to another.
# It requires the AWS CLI and jq to be installed on the system.
# Please read the README.md file for more information.
. ./config
. ./functions.sh
if [ "$#" -gt 0 ]; then
case "$1" in
--dry-run)
export DRYRUN="true"
;;
--help)
echo ""
echo "Usage: $0 [--dry-run]"
echo ""
exit 1
;;
*)
echo ""
echo "[ERROR] Unknown argument '$1'"
echo ""
echo "Usage: $0 [--dry-run]"
echo ""
exit 1
;;
esac
fi
# Check pre-requisites
check_cmd "aws"
check_cmd "jq"
# Prompt the user for AWS CLI profile names and hosted zone ID
echo ""
echo "********************************************************"
echo " Amazon Route 53 Hosted Zone Migrator "
echo "********************************************************"
echo ""
read -p "- Enter AWS CLI profile name for the source AWS account: " SOURCE_PROFILE
read -p "- Enter AWS CLI profile name for the destination AWS account: " DEST_PROFILE
read -p "- Enter the Route 53 Hosted Zone ID to migrate: " HOSTED_ZONE_ID
echo ""
# Checking log directory
if [ ! -e "$WORK_DIR/$HOSTED_ZONE_ID/$LOG_FILE" ]; then
mkdir -p "$WORK_DIR/$HOSTED_ZONE_ID"
touch "$WORK_DIR/$HOSTED_ZONE_ID/$LOG_FILE"
fi
# Starting logging after the definition of the HOSTED_ZONE_ID
echo "" >> "$WORK_DIR/$HOSTED_ZONE_ID/$LOG_FILE"
echo "********************************************************" >> "$WORK_DIR/$HOSTED_ZONE_ID/$LOG_FILE"
echo " Amazon Route 53 Hosted Zone Migrator " >> "$WORK_DIR/$HOSTED_ZONE_ID/$LOG_FILE"
echo "********************************************************" >> "$WORK_DIR/$HOSTED_ZONE_ID/$LOG_FILE"
echo "" >> "$WORK_DIR/$HOSTED_ZONE_ID/$LOG_FILE"
# Log dry-run execution
if [ "$DRYRUN" == "true" ]; then log "[INFO] Dry-run execution enabled"; fi
# Checking if specified AWS CLI profile are correct
log "[INFO] Checking AWS CLI profiles..."
aws_cli_profile_check "$SOURCE_PROFILE"
aws_cli_profile_check "$DEST_PROFILE"
# Checking if specified Hosted Zone is ok for both accounts
log "[INFO] Checking Hosted Zone..."
check_hosted_zone_id "$HOSTED_ZONE_ID"
# Checking if HOSTED ZONE is public or private
log "[INFO] Checking if Hosted Zone is public or private..."
check_private_hosted_zone "$HOSTED_ZONE_ID"
# Call the main function to perform the migration
extract_and_convert_zone "$SOURCE_PROFILE" "$DEST_PROFILE" "$HOSTED_ZONE_ID" "$HOSTED_ZONE_PRIVATE"
# Check DNSSEC configuration
check_dnssec "$SOURCE_PROFILE" "$HOSTED_ZONE_ID"