-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimports.py
executable file
·28 lines (22 loc) · 917 Bytes
/
imports.py
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
#!/usr/local/bin/python3
import sys
import route53
if __name__ == "__main__":
if len(sys.argv) == 1:
print("Usage: " + sys.argv[0] + " <aws_hosted_zone_id> ...")
sys.exit(1)
conn = route53.connect(
aws_access_key_id='<SOME_ACCESS_KEY>',
aws_secret_access_key='<THE_SECRET>'
)
match_id = ''.join(sys.argv[1:])
zone = conn.get_hosted_zone_by_id(match_id)
print("# Imports for: " + match_id)
print("")
print("terraform import aws_route53_zone." + zone.name.replace(".", "_")[:-1] + " " + match_id)
num_records = 0
for record_set in zone.record_sets:
num_records += 1
tf_record_name = record_set.name.replace(".", "_")[:-1]
print("terraform import aws_route53_record." + tf_record_name + " " + match_id + "_" + record_set.name[:-1] + "_" + record_set.rrset_type)
print("# Num Records: " + str(num_records))