Skip to content

oozou/terraform-aws-route53

Repository files navigation

terraform-aws-route53

Terraform module design

Design diagram

Usage

resource "aws_elb" "this" {
  name    = "foobar-terraform-elb"
  subnets = "vpc-xxxxx"

  listener {
    instance_port     = 80
    instance_protocol = "http"
    lb_port           = 80
    lb_protocol       = "http"
  }
}

module "host_zone_and_record" {
  source = "<source>"

  is_public_zone = false             # Default `true`
  vpc_id         = "vpc-xxxxx"  # If is_public_zone is `true`, no need to specific

  prefix      = "oozou"
  environment = "dev"

  dns_name = "oozou-sample"
  dns_records = {
    sample_dns = {
      name    = "app1" 
      type    = "A"
      ttl     = "5"
      records = ["192.112.112.112", "192.112.112.113"]
    }
    sample_alias = {
      name = "app2"
      type = "A"
      alias = {
        name    = aws_elb.this.dns_name # Target DNS name
        zone_id = aws_elb.this.zone_id
      }
    }
  }

  tags = var.custom_tags
}

module "only_record" {
  source = "<source>"
  depends_on = [module.host_zone_and_record]
  is_create_zone = false
  is_public_zone = false             # Default `true`
  vpc_id         = "vpc-xxxxx"  # If is_public_zone is `true`, no need to specific

  prefix      = "oozou"
  environment = "dev"

  dns_name = "oozou-sample"

  dns_records = {
    sample_dns = {
      name    = "app2" 
      type    = "A"
      ttl     = "5"
      records = ["192.112.112.114", "192.112.112.115"]
    }
  }
}

Requirements

Name Version
terraform >= 1.0.0
aws >= 4.00

Providers

Name Version
aws 4.6.0

Modules

No modules.

Resources

Name Type
aws_route53_record.this resource
aws_route53_zone.this resource
aws_route53_zone.selected_zone data source

Inputs

Name Description Type Default Required
dns_name (Required) This is the name of the hosted zone. string n/a yes
dns_records Map of DNS records any {} no
environment Environment Variable used as a prefix string n/a yes
is_create_zone Wherther to create a zone or not bool true no
is_public_zone Wherther to create a zone or not bool true no
prefix The prefix name of customer to be displayed in AWS console and resource string n/a yes
tags Tags to add more; default tags contian {terraform=true, environment=var.environment} map(string) {} no
vpc_id Required when hostzone is private, to associate with VPC string "" no

Outputs

Name Description
route53_name Name of Route53 zone
route53_name_servers Name servers of Route53 zone
route53_record_fqdn FQDN built using the zone domain and name
route53_record_name The name of the record
route53_zone_id Zone ID of Route53 zone