diff --git a/README.md b/README.md index 443aa1c..196694a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

- Terraform AWS Route table + Terraform AWS Route53 Record

@@ -24,13 +24,13 @@

- + - + - + @@ -65,59 +65,34 @@ This module has a few dependencies: ## Examples -**IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-route-table/releases). +**IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-route53-record/releases). Here are some examples of how you can use this module in your inventory structure: ### Simple set ```hcl - module "route-table" { - record_enabled = true - zone_id = "Z2FDRFHATA1ER4" - names = [ - "www.", - "admin." - ] - types = [ - "A", - "CNAME" - ] - ttls = [ - "3600", - "3600", - ] - values = [ - "10.0.0.27", - "mydomain.com", - ] + module "route53-record" { + source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" + zone_id = "Z1XJD7SSBKXLC1" + name = "www" + type = "A" + ttl = "3600" + values = "10.0.0.27" } ``` ### Set with alias ```hcl - module "route-table" { - source = "git::https://github.com/clouddrove/terraform-aws-route-table.git?ref=tags/0.12.0" - record_enabled = true - zone_id = "Z2FDRFHATA1ER4" - names = [ - "www.", - "admin." - ] - types = [ - "A", - "CNAME" - ] - alias = { - names = [ - "d130easdflja734js.cloudfront.net" - ] - zone_ids = [ - "Z2FDRFHATA1ER4" - ] - evaluate_target_healths = [ - false - ] - } + module "route53-record" { + source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" + zone_id = "Z1XJD7SSBKXLC1" + name = "www." + type = "A" + alias = { + name = "d130easdflja734js.cloudfront.net" + zone_id = "Z2FDRFHATA1ER4" + evaluate_target_health = false + } } ``` @@ -131,21 +106,22 @@ Here are some examples of how you can use this module in your inventory structur | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| | alias | An alias block. Conflicts with ttl & records. Alias record documented below. | map | `` | no | -| allow_overwrites | Allow creation of this record in Terraform to overwrite an existing record, if any. This does not affect the ability to update the record in Terraform and does not prevent other resources within Terraform or manual Route 53 changes outside Terraform from overwriting this record. false by default. This configuration is not recommended for most environments. | list | `` | no | -| health_check_ids | The health check the record should be associated with. | list | `` | no | -| multivalue_answer_routing_policies | Set to true to indicate a multivalue answer routing policy. Conflicts with any other routing policy. | list | `` | no | -| names | The name of the record. | list | `` | no | -| record_enabled | Whether to create Route53 record set. | bool | `false` | no | -| set_identifiers | Unique identifier to differentiate records with routing policies from one another. Required if using failover, geolocation, latency, or weighted routing policies documented below. | list | `` | no | -| ttls | (Required for non-alias records) The TTL of the record. | list | `` | no | -| types | The record type. Valid values are A, AAAA, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV and TXT. | list | `` | no | -| values | (Required for non-alias records) A string list of records. To specify a single record value longer than 255 characters such as a TXT record for DKIM, add "" inside the Terraform configuration string (e.g. "first255characters""morecharacters"). | list | `` | no | +| allow_overwrite | Allow creation of this record in Terraform to overwrite an existing record, if any. This does not affect the ability to update the record in Terraform and does not prevent other resources within Terraform or manual Route 53 changes outside Terraform from overwriting this record. false by default. This configuration is not recommended for most environments. | bool | `false` | no | +| health_check_id | The health check the record should be associated with. | string | `` | no | +| multivalue_answer_routing_policy | Set to true to indicate a multivalue answer routing policy. Conflicts with any other routing policy. | string | `` | no | +| name | The name of the record. | string | `` | no | +| record_enabled | Whether to create Route53 record set. | bool | `true` | no | +| set_identifier | Unique identifier to differentiate records with routing policies from one another. Required if using failover, geolocation, latency, or weighted routing policies documented below. | string | `` | no | +| ttl | (Required for non-alias records) The TTL of the record. | string | `` | no | +| type | The record type. Valid values are A, AAAA, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV and TXT. | string | `` | no | +| values | (Required for non-alias records) A string list of records. To specify a single record value longer than 255 characters such as a TXT record for DKIM, add "" inside the Terraform configuration string (e.g. "first255characters""morecharacters"). | string | `` | no | | zone_id | Zone ID. | string | `` | no | + ## Feedback -If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-aws-route-table/issues), or feel free to drop us an email at [hello@clouddrove.com](mailto:hello@clouddrove.com). +If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-aws-route53-record/issues), or feel free to drop us an email at [hello@clouddrove.com](mailto:hello@clouddrove.com). -If you have found it worth your time, go ahead and give us a ★ on [our GitHub](https://github.com/clouddrove/terraform-aws-route-table)! +If you have found it worth your time, go ahead and give us a ★ on [our GitHub](https://github.com/clouddrove/terraform-aws-route53-record)! ## About us diff --git a/README.yaml b/README.yaml index ba16020..ace56fe 100644 --- a/README.yaml +++ b/README.yaml @@ -5,13 +5,13 @@ # # Name of this project -name : Terraform AWS Route table +name : Terraform AWS Route53 Record # License of this project license: "MIT" # Canonical GitHub repo -github_repo: clouddrove/terraform-aws-route-table +github_repo: clouddrove/terraform-aws-route53-record # Badges to display badges: @@ -36,52 +36,27 @@ usage : |- Here are some examples of how you can use this module in your inventory structure: ### Simple set ```hcl - module "route-table" { - record_enabled = true - zone_id = "Z2FDRFHATA1ER4" - names = [ - "www.", - "admin." - ] - types = [ - "A", - "CNAME" - ] - ttls = [ - "3600", - "3600", - ] - values = [ - "10.0.0.27", - "mydomain.com", - ] + module "route53-record" { + source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" + zone_id = "Z1XJD7SSBKXLC1" + name = "www" + type = "A" + ttl = "3600" + values = "10.0.0.27" } ``` ### Set with alias ```hcl - module "route-table" { - source = "git::https://github.com/clouddrove/terraform-aws-route-table.git?ref=tags/0.12.0" - record_enabled = true - zone_id = "Z2FDRFHATA1ER4" - names = [ - "www.", - "admin." - ] - types = [ - "A", - "CNAME" - ] - alias = { - names = [ - "d130easdflja734js.cloudfront.net" - ] - zone_ids = [ - "Z2FDRFHATA1ER4" - ] - evaluate_target_healths = [ - false - ] - } + module "route53-record" { + source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" + zone_id = "Z1XJD7SSBKXLC1" + name = "www." + type = "A" + alias = { + name = "d130easdflja734js.cloudfront.net" + zone_id = "Z2FDRFHATA1ER4" + evaluate_target_health = false + } } ``` diff --git a/_example/set-with-alias/example.tf b/_example/set-with-alias/example.tf index d3cfd1f..57d32ba 100644 --- a/_example/set-with-alias/example.tf +++ b/_example/set-with-alias/example.tf @@ -2,28 +2,15 @@ provider "aws" { region = "eu-west-1" } -module "route-table" { - source = "git::https://github.com/clouddrove/terraform-aws-route-table.git?ref=tags/0.12.0" +module "route53-record" { + source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" - zone_id = "Z2FDRFHATA1ER4" - - names = [ - "www.", - "admin." - ] - types = [ - "A", - "CNAME" - ] + zone_id = "Z1XJD7SSBKXLC1" + name = "www" + type = "A" alias = { - names = [ - "d130easdflja734js.cloudfront.net" - ] - zone_ids = [ - "Z2FDRFHATA1ER4" - ] - evaluate_target_healths = [ - false - ] + name = "d130easdflja734js.cloudfront.net" + zone_id = "Z2FDRFHATA1ER4" + evaluate_target_health = false } } diff --git a/_example/set-with-alias/outputs.tf b/_example/set-with-alias/outputs.tf deleted file mode 100644 index 52fd0aa..0000000 --- a/_example/set-with-alias/outputs.tf +++ /dev/null @@ -1,9 +0,0 @@ -output "id" { - value = module.route53.*.zone_id - description = "The ID of the Hostzone." -} - -output "tags" { - value = module.route53.tags - description = "A mapping of tags to assign to the resource." -} \ No newline at end of file diff --git a/_example/simple-set/example.tf b/_example/simple-set/example.tf index f2ce8d5..2d403eb 100644 --- a/_example/simple-set/example.tf +++ b/_example/simple-set/example.tf @@ -2,24 +2,12 @@ provider "aws" { region = "eu-west-1" } -module "route-table" { - source = "git::https://github.com/clouddrove/terraform-aws-route-table.git?ref=tags/0.12.0" +module "route53-record" { + source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" - zone_id = "Z3XYSELRQ8JFS" - names = [ - "www.", - "admin." - ] - types = [ - "A", - "CNAME" - ] - ttls = [ - "3600", - "3600", - ] - values = [ - "10.0.0.27", - "mydomain.com", - ] + zone_id = "Z1XJD7SSBKXLC1" + name = "www" + type = "A" + ttl = "3600" + values = "10.0.0.27" } diff --git a/_example/simple-set/outputs.tf b/_example/simple-set/outputs.tf deleted file mode 100644 index e69de29..0000000 diff --git a/main.tf b/main.tf index f68ee6a..8778a85 100644 --- a/main.tf +++ b/main.tf @@ -4,32 +4,32 @@ # Module : Route53 Record Set # Description : Terraform module to create Route53 record sets resource on AWS. resource "aws_route53_record" "default" { - count = var.record_enabled && length(var.ttls) > 0 ? length(var.ttls) : 0 + count = var.record_enabled && length(var.alias) == 0 ? 1 : 0 zone_id = var.zone_id - name = element(var.names, count.index) - type = element(var.types, count.index) - ttl = element(var.ttls, count.index) - records = split(",", element(var.values, count.index)) - set_identifier = length(var.set_identifiers) > 0 ? element(var.set_identifiers, count.index) : "" - health_check_id = length(var.health_check_ids) > 0 ? element(var.health_check_ids, count.index) : "" - multivalue_answer_routing_policy = length(var.multivalue_answer_routing_policies) > 0 ? element(var.multivalue_answer_routing_policies, count.index) : null - allow_overwrite = length(var.allow_overwrites) > 0 ? element(var.allow_overwrites, count.index) : false + name = var.name + type = var.type + ttl = var.ttl + records = split(",", var.values) + set_identifier = var.set_identifier + health_check_id = var.health_check_id + multivalue_answer_routing_policy = var.multivalue_answer_routing_policy + allow_overwrite = var.allow_overwrite } # Module : Route53 Record Set # Description : Terraform module to create Route53 record sets resource on AWS. resource "aws_route53_record" "alias" { - count = var.record_enabled && length(var.alias) > 0 && length(var.alias["names"]) > 0 ? length(var.alias["names"]) : 0 + count = var.record_enabled && length(var.alias) > 0 ? 1 : 0 zone_id = var.zone_id - name = element(var.names, count.index) - type = element(var.types, count.index) - set_identifier = length(var.set_identifiers) > 0 ? element(var.set_identifiers, count.index) : "" - health_check_id = length(var.health_check_ids) > 0 ? element(var.health_check_ids, count.index) : "" - multivalue_answer_routing_policy = length(var.multivalue_answer_routing_policies) > 0 ? element(var.multivalue_answer_routing_policies, count.index) : null - allow_overwrite = length(var.allow_overwrites) > 0 ? element(var.allow_overwrites, count.index) : false + name = var.name + type = var.type + set_identifier = var.set_identifier + health_check_id = var.health_check_id + multivalue_answer_routing_policy = var.multivalue_answer_routing_policy + allow_overwrite = var.allow_overwrite alias { - name = length(var.alias) > 0 ? element(var.alias["names"], count.index) : "" - zone_id = length(var.alias) > 0 ? element(var.alias["zone_ids"], count.index) : "" - evaluate_target_health = length(var.alias) > 0 ? element(var.alias["evaluate_target_healths"], count.index) : false + name = var.alias["name"] + zone_id = var.alias["zone_id"] + evaluate_target_health = var.alias["evaluate_target_health"] } } diff --git a/variables.tf b/variables.tf index 1d8cbc5..97c5ad0 100644 --- a/variables.tf +++ b/variables.tf @@ -6,57 +6,56 @@ variable "record_enabled" { description = "Whether to create Route53 record set." } -variable "types" { - type = list - default = [] +variable "type" { + type = string + default = "" description = "The record type. Valid values are A, AAAA, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV and TXT. " } -variable "ttls" { - type = list - default = [] +variable "ttl" { + type = string + default = "" description = "(Required for non-alias records) The TTL of the record." } -variable "names" { - type = list - default = [] +variable "name" { + type = string + default = "" description = "The name of the record." } variable "values" { - type = list - default = [] + type = string + default = "" description = "(Required for non-alias records) A string list of records. To specify a single record value longer than 255 characters such as a TXT record for DKIM, add \"\" inside the Terraform configuration string (e.g. \"first255characters\"\"morecharacters\")." } -variable "set_identifiers" { - type = list - default = [] +variable "set_identifier" { + type = string + default = "" description = "Unique identifier to differentiate records with routing policies from one another. Required if using failover, geolocation, latency, or weighted routing policies documented below." } -variable "health_check_ids" { - type = list - default = [] +variable "health_check_id" { + type = string + default = "" description = "The health check the record should be associated with." } variable "alias" { type = map - default = {"names"=[],"zone_ids"=[],"evaluate_target_healths"=[]} + default = {} description = "An alias block. Conflicts with ttl & records. Alias record documented below." } -variable "multivalue_answer_routing_policies" { - type = list - default = [] +variable "multivalue_answer_routing_policy" { + default = null description = "Set to true to indicate a multivalue answer routing policy. Conflicts with any other routing policy." } -variable "allow_overwrites" { - type = list - default = [] +variable "allow_overwrite" { + type = bool + default = false description = "Allow creation of this record in Terraform to overwrite an existing record, if any. This does not affect the ability to update the record in Terraform and does not prevent other resources within Terraform or manual Route 53 changes outside Terraform from overwriting this record. false by default. This configuration is not recommended for most environments." }