/terraform-aws-route53

Terraform module which creates Route53 resources on AWS

Primary LanguageHCLApache License 2.0Apache-2.0

Route53 Terraform module

This module is derived from the one with same name maintained by Anton Babenko.

In this version, the 'zone' and 'record' modules allow to create a single zone and a single record. The 'zones' and 'records' modules are just calling the se modules with for_each loops. This provides a much simpler code as it avoids having loops and resource indexes everywhere.

Of course, using loops (for_each/count) on modules is possible since terraform 0.13 only. So, this module cannot work with a terraform version lower than 0.13.

----------------- Original documentation -----------------------

Terraform module which creates Route53 resources.

There are independent submodules:

  • zones - to manage Route53 zones
  • records - to manage Route53 records

Usage

Create Route53 zones and records

module "zones" {
  source  = "terraform-aws-modules/route53/aws//modules/zones"
  version = "~> 2.0"

  zones = {
    "terraform-aws-modules-example.com" = {
      comment = "terraform-aws-modules-examples.com (production)"
      tags = {
        env = "production"
      }
    }

    "myapp.com" = {
      comment = "myapp.com"
    }
  }

  tags = {
    ManagedBy = "Terraform"
  }
}

module "records" {
  source  = "terraform-aws-modules/route53/aws//modules/records"
  version = "~> 2.0"

  zone_name = keys(module.zones.route53_zone_zone_id)[0]

  records = [
    {
      name    = "apigateway1"
      type    = "A"
      alias   = {
        name    = "d-10qxlbvagl.execute-api.eu-west-1.amazonaws.com"
        zone_id = "ZLY8HYME6SFAD"
      }
    },
    {
      name    = ""
      type    = "A"
      ttl     = 3600
      records = [
        "10.10.10.10",
      ]
    },
  ]

  depends_on = [module.zones]
}

Note that depends_on in modules is available since Terraform 0.13.

Examples

Conditional creation

Sometimes you need to have a way to create resources conditionally but Terraform does not allow to use count inside module block, so the solution is to specify argument create.

Authors

Module is maintained by Anton Babenko with help from these awesome contributors.

License

Apache 2 Licensed. See LICENSE for full details.