Skip to content

Commit

Permalink
update code to use fqdn for ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 27, 2022
1 parent 79ddc36 commit 8787012
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
36 changes: 24 additions & 12 deletions code/ddns-lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
LOGGER = logging.getLogger()
ACCOUNT = None
REGION = None
VERSION = '0.0.2'
VERSION = '0.0.3'

# Adjust the logging level [logging.INFO, logging.DEBUG, logging.WARNING, etc]
LOGGER.setLevel(logging.DEBUG)
Expand All @@ -51,6 +51,8 @@
TAGKEY_CNAME = os.environ['TagKeyCname']
TAGKEY_ZONE = os.environ['TagKeyZone']
TAGKEY_HOSTNAME = os.environ['TagKeyHostName']
DNS_RR_TTL = int(os.environ['DNS_RR_TimeToLive'])
DNS_RR_TTL = 60 if DNS_RR_TTL==0 else DNS_RR_TTL

print('Loading function v%s: %s'.format(VERSION,datetime.datetime.now().time().isoformat()))

Expand Down Expand Up @@ -153,7 +155,7 @@ def lambda_handler(

# Only doing something if the state is running
if state == 'running':
LOGGER.debug("sleeping for 60 seconds %s", lineno())
LOGGER.debug("sleeping for {} seconds {}".format(SLEEPTIME,lineno()))

if "pytest" in sys.modules:
# called from within a test run
Expand Down Expand Up @@ -381,6 +383,7 @@ def lambda_handler(
private_hosted_zone_properties = get_hosted_zone_properties(route53, private_hosted_zone_id)
LOGGER.debug("private_hosted_zone_properties:"
" %s", str(private_hosted_zone_properties) + lineno())
fqdn = private_host_name + '.' + private_hosted_zone_name
if state == 'running':
found_vpc_id = False
if 'VPCs' in private_hosted_zone_properties:
Expand Down Expand Up @@ -425,15 +428,17 @@ def lambda_handler(
reversed_ip_address,
'in-addr.arpa',
'PTR',
private_dns_name
fqdn
# private_dns_name
)

caller_response.append('Created PTR record in zone id: ' +
str(reverse_lookup_zone_id) +
' for hosted zone ' +
str(reversed_ip_address) +
'in-addr.arpa with value: ' +
str(private_dns_name))
str(fqdn))
# str(private_dns_name))

except BaseException as err:
LOGGER.debug("%s", str(err)+lineno())
Expand Down Expand Up @@ -462,7 +467,8 @@ def lambda_handler(
reversed_ip_address,
'in-addr.arpa',
'PTR',
private_dns_name
fqdn
# private_dns_name
)

caller_response.append('Deleted PTR record in zone id: ' +
Expand All @@ -471,7 +477,8 @@ def lambda_handler(
str(reversed_ip_address) + '.' +
str(private_dns_name) +
' with value: ' +
str(private_dns_name))
str(fqdn))
# str(private_dns_name))

except BaseException as err:
LOGGER.debug("%s", str(err)+lineno())
Expand Down Expand Up @@ -725,6 +732,7 @@ def lambda_handler(
" %s", str(private_hosted_zone_properties) + lineno())

# create A records and PTR records
fqdn = private_host_name + '.' + private_hosted_zone_name
if state == 'running':
if vpc_id in map(lambda x: x['VPCId'], private_hosted_zone_properties['VPCs']):
vpc_associated = True
Expand Down Expand Up @@ -770,15 +778,17 @@ def lambda_handler(
reversed_ip_address,
'in-addr.arpa',
'PTR',
private_dns_name
fqdn
# private_dns_name
)

caller_response.append('Created PTR record in zone id: ' +
str(reverse_lookup_zone_id) +
' for hosted zone ' +
str(reversed_ip_address) +
'in-addr.arpa with value: ' +
str(private_dns_name))
str(fqdn))
# str(private_dns_name))
else:
LOGGER.debug("No reverse zone associated with VPC - skipping creating resource records %s", lineno())

Expand Down Expand Up @@ -847,14 +857,16 @@ def lambda_handler(
reversed_ip_address,
'in-addr.arpa',
'PTR',
private_dns_name
fqdn
# private_dns_name
)
caller_response.append('Deleted PTR record in zone id: ' +
str(reverse_lookup_zone_id) +
' for hosted zone ' +
str(reversed_ip_address) +
'in-addr.arpa with value: ' +
str(private_dns_name))
str(fqdn))
# str(private_dns_name))
else:
delete_resource_record(
route53,
Expand Down Expand Up @@ -1239,7 +1251,7 @@ def change_resource_recordset(client, zone_id, host_name, hosted_zone_name, reco
"ResourceRecordSet": {
"Name": host_name + hosted_zone_name,
"Type": record_type,
"TTL": 60,
"TTL": DNS_RR_TTL,
"ResourceRecords": [
{
"Value": value
Expand Down Expand Up @@ -1336,7 +1348,7 @@ def delete_resource_record(client, zone_id, host_name, hosted_zone_name, record_
"ResourceRecordSet": {
"Name": host_name + hosted_zone_name,
"Type": record_type,
"TTL": 60,
"TTL": DNS_RR_TTL,
"ResourceRecords": [
{
"Value": value
Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
locals {
_module_version = "0.0.13"
_module_version = "0.0.14"
}

0 comments on commit 8787012

Please sign in to comment.