Skip to content

Commit 51cfc4a

Browse files
authored
Merge pull request #57 from meltwater/54_ttl
54_ttl - allow users to set TTL on DNS Records
2 parents 108636a + d7f9cdd commit 51cfc4a

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## Unreleased
88

9+
## [v2.1.8](https://github.com/meltwater/terraform-aws-asg-dns-handler/compare/v2.1.7...v2.1.8) - 2023-11-07
10+
911
### Added
1012

13+
- Allow users to specify custom Route53 DNS Record TTL
14+
1115
## [v2.1.7](https://github.com/meltwater/terraform-aws-asg-dns-handler/compare/v2.1.6...v2.1.7) - 2022-03-22
1216

1317
### Changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ module "clever_name_autoscale_dns" {
3939
source = meltwater/asg-dns-handler/aws"
4040
version = "~> 2.0"
4141
42-
# use_public_ip = true
42+
# use_public_ip = true
43+
# route53_record_ttl = 300
4344
autoscale_handler_unique_identifier = "clever_name"
4445
autoscale_route53zone_arn = "ABCDEFGHIJ123"
4546
vpc_name = "my_vpc"

lambda/autoscale/autoscale.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def fetch_ip_from_ec2(instance_id):
2121
logger.info("Fetching IP for instance-id: %s", instance_id)
2222
ec2_response = ec2.describe_instances(InstanceIds=[instance_id])
23-
if 'use_public_ip' in os.environ and os.environ['use_public_ip'] == "true":
23+
if 'USE_PUBLIC_IP' in os.environ and os.environ['USE_PUBLIC_IP'] == "true":
2424
ip_address = ec2_response['Reservations'][0]['Instances'][0]['PublicIpAddress']
2525
logger.info("Found public IP for instance-id %s: %s", instance_id, ip_address)
2626
else:
@@ -93,7 +93,7 @@ def update_record(zone_id, ip, hostname, operation):
9393
'ResourceRecordSet': {
9494
'Name': hostname,
9595
'Type': 'A',
96-
'TTL': 300,
96+
'TTL': os.environ['ROUTE53_TTL'],
9797
'ResourceRecords': [{'Value': ip}]
9898
}
9999
}

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ resource "aws_lambda_function" "autoscale_handling" {
115115
description = "Handles DNS for autoscaling groups by receiving autoscaling notifications and setting/deleting records from route53"
116116
environment {
117117
variables = {
118-
"use_public_ip" = var.use_public_ip
118+
"USE_PUBLIC_IP" = var.use_public_ip
119+
"ROUTE53_TTL" = var.route53_record_ttl
119120
}
120121
}
121122
}

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
variable "autoscale_handler_unique_identifier" {
22
description = "asg_dns_handler"
3+
type = string
34
}
45

56
variable "vpc_name" {
67
description = "The name of the VPC"
8+
type = string
79
}
810

911
variable "use_public_ip" {
1012
description = "Use public IP instead of private"
1113
default = false
14+
type = bool
1215
}
1316

1417
variable "autoscale_route53zone_arn" {
1518
description = "The ARN of route53 zone associated with autoscaling group"
19+
type = string
1620
}
1721

22+
variable "route53_record_ttl" {
23+
description = "TTL to use for the Route 53 Records created"
24+
default = 300
25+
type = number
26+
}

0 commit comments

Comments
 (0)