Skip to content

Commit

Permalink
Merge pull request #57 from meltwater/54_ttl
Browse files Browse the repository at this point in the history
54_ttl - allow users to set TTL on DNS Records
  • Loading branch information
bdebyl authored Nov 7, 2023
2 parents 108636a + d7f9cdd commit 51cfc4a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

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

### Added

- Allow users to specify custom Route53 DNS Record TTL

## [v2.1.7](https://github.com/meltwater/terraform-aws-asg-dns-handler/compare/v2.1.6...v2.1.7) - 2022-03-22

### Changed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module "clever_name_autoscale_dns" {
source = meltwater/asg-dns-handler/aws"
version = "~> 2.0"
# use_public_ip = true
# use_public_ip = true
# route53_record_ttl = 300
autoscale_handler_unique_identifier = "clever_name"
autoscale_route53zone_arn = "ABCDEFGHIJ123"
vpc_name = "my_vpc"
Expand Down
4 changes: 2 additions & 2 deletions lambda/autoscale/autoscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def fetch_ip_from_ec2(instance_id):
logger.info("Fetching IP for instance-id: %s", instance_id)
ec2_response = ec2.describe_instances(InstanceIds=[instance_id])
if 'use_public_ip' in os.environ and os.environ['use_public_ip'] == "true":
if 'USE_PUBLIC_IP' in os.environ and os.environ['USE_PUBLIC_IP'] == "true":
ip_address = ec2_response['Reservations'][0]['Instances'][0]['PublicIpAddress']
logger.info("Found public IP for instance-id %s: %s", instance_id, ip_address)
else:
Expand Down Expand Up @@ -93,7 +93,7 @@ def update_record(zone_id, ip, hostname, operation):
'ResourceRecordSet': {
'Name': hostname,
'Type': 'A',
'TTL': 300,
'TTL': os.environ['ROUTE53_TTL'],
'ResourceRecords': [{'Value': ip}]
}
}
Expand Down
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ resource "aws_lambda_function" "autoscale_handling" {
description = "Handles DNS for autoscaling groups by receiving autoscaling notifications and setting/deleting records from route53"
environment {
variables = {
"use_public_ip" = var.use_public_ip
"USE_PUBLIC_IP" = var.use_public_ip
"ROUTE53_TTL" = var.route53_record_ttl
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
variable "autoscale_handler_unique_identifier" {
description = "asg_dns_handler"
type = string
}

variable "vpc_name" {
description = "The name of the VPC"
type = string
}

variable "use_public_ip" {
description = "Use public IP instead of private"
default = false
type = bool
}

variable "autoscale_route53zone_arn" {
description = "The ARN of route53 zone associated with autoscaling group"
type = string
}

variable "route53_record_ttl" {
description = "TTL to use for the Route 53 Records created"
default = 300
type = number
}

0 comments on commit 51cfc4a

Please sign in to comment.