Skip to content

Module creates a lambda that manages DNS A records for instances in an autoscaling group.

Notifications You must be signed in to change notification settings

infrahouse/terraform-aws-update-dns

Repository files navigation

terraform-aws-update-dns

The module updates Route53 to create an A record in a zone for instances in an autoscaling group. When the instance is terminated, the respective record is removed.

Usage

Prerequisites:

Autoscaling group name must be known before using this module. "Known" means that either we already created the ASG:

resource "aws_autoscaling_group" "update-dns" {
  max_size = 1
  min_size = 3
}

and then we can pass the ASG name as asg_name = aws_autoscaling_group.update-dns.name or we know the ASG name beforehand

resource "random_string" "asg_name" {
  length  = 6
  special = false
}
locals {
  asg_name = "${aws_launch_template.jumphost.name}-${random_string.asg_name.result}"
}

and then we can pass asg_name = local.asg_name:

module "update_dns" {
  source            = "infrahouse/update-dns/aws"
  version           = "~> 0.1"
  asg_name          = local.asg_name
  route53_zone_id   = var.route53_zone_id
  route53_hostname  = var.route53_hostname
  route53_public_ip = true
}

Requirements

Name Version
terraform ~> 1.5
aws ~> 5.11
random ~> 3.6

Providers

Name Version
archive n/a
aws ~> 5.11
null n/a
random ~> 3.6

Modules

No modules.

Resources

Name Type
aws_cloudwatch_event_rule.instance_start resource
aws_cloudwatch_event_rule.scale resource
aws_cloudwatch_event_target.instance-running resource
aws_cloudwatch_event_target.scale-out resource
aws_cloudwatch_log_group.update_dns resource
aws_iam_policy.lambda_logging resource
aws_iam_policy.lambda_permissions resource
aws_iam_role.iam_for_lambda resource
aws_iam_role_policy_attachment.AWSLambdaBasicExecutionRole resource
aws_iam_role_policy_attachment.lambda_logs resource
aws_iam_role_policy_attachment.lambda_permissions resource
aws_lambda_function.update_dns resource
aws_lambda_function_event_invoke_config.update_dns resource
aws_lambda_permission.allow_cloudwatch_asg_lifecycle_hook resource
aws_lambda_permission.allow_cloudwatch_instance_running resource
aws_s3_bucket.lambda_tmp resource
aws_s3_bucket_public_access_block.public_access resource
aws_s3_object.lambda_package resource
null_resource.install_python_dependencies resource
random_uuid.lamda_src_hash resource
archive_file.lambda data source
aws_caller_identity.current data source
aws_iam_policy.AWSLambdaBasicExecutionRole data source
aws_iam_policy_document.assume_role data source
aws_iam_policy_document.lambda-permissions data source
aws_iam_policy_document.lambda_logging data source
aws_region.current data source
aws_route53_zone.asg_zone data source

Inputs

Name Description Type Default Required
asg_name Autoscaling group name to assign this lambda to. string n/a yes
route53_hostname An A record with this name will be created in the rout53 zone. Can be either a string or one of special values: _PrivateDnsName_, tbc. string "_PrivateDnsName_" no
route53_public_ip If true, create the A record with the public IP address. Otherwise, private instance IP address. bool true no
route53_ttl TTL in seconds on the route53 A record. number 300 no
route53_zone_id Route53 zone id of a zone where A record will be created. any n/a yes

Outputs

No outputs.

About

Module creates a lambda that manages DNS A records for instances in an autoscaling group.

Resources

Stars

Watchers

Forks

Packages

No packages published