From d303a52aef974055761b8d006a15439021b6e1b5 Mon Sep 17 00:00:00 2001 From: Nikita Dugar Date: Tue, 5 Nov 2019 11:05:29 +0530 Subject: [PATCH 1/4] make simplest --- README.md | 108 +++++++++++++---------------- README.yaml | 65 ++++++----------- _example/set-with-alias/example.tf | 29 +++----- _example/set-with-alias/outputs.tf | 9 --- _example/simple-set/example.tf | 26 ++----- _example/simple-set/outputs.tf | 0 main.tf | 38 +++++----- variables.tf | 45 ++++++------ 8 files changed, 126 insertions(+), 194 deletions(-) delete mode 100644 _example/set-with-alias/outputs.tf delete mode 100644 _example/simple-set/outputs.tf diff --git a/README.md b/README.md index 443aa1c..2ebf311 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,36 @@ 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 +108,34 @@ 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 | + + + +## Testing +In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system. + +You need to run the following command in the testing folder: +```hcl + go test -run Test +``` + + + ## 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 @@ -160,4 +150,4 @@ At [CloudDrove][website], we offer expert guidance, implementation support and s [linkedin]: https://cpco.io/linkedin [twitter]: https://twitter.com/clouddrove/ [email]: https://clouddrove.com/contact-us.html - [terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language= + [terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language= \ No newline at end of file diff --git a/README.yaml b/README.yaml index ba16020..9fde254 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,29 @@ 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..0a9bd32 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..61f9b1e 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 2554e09..97c5ad0 100644 --- a/variables.tf +++ b/variables.tf @@ -6,39 +6,39 @@ 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." } @@ -48,15 +48,14 @@ variable "alias" { 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." } From 8776c98c02521fdd7771f2c1299f3ae162928ddd Mon Sep 17 00:00:00 2001 From: Nikita Dugar Date: Tue, 5 Nov 2019 11:06:22 +0530 Subject: [PATCH 2/4] make simplest --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index db34505..97c5ad0 100644 --- a/variables.tf +++ b/variables.tf @@ -44,7 +44,7 @@ variable "health_check_id" { variable "alias" { type = map - default = {"names"=[],"zone_ids"=[],"evaluate_target_healths"=[]} + default = {} description = "An alias block. Conflicts with ttl & records. Alias record documented below." } From 863f24224af07243fb38f4050287c5c9d77521a4 Mon Sep 17 00:00:00 2001 From: Nikita Dugar Date: Tue, 5 Nov 2019 11:08:03 +0530 Subject: [PATCH 3/4] Update README.md --- README.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/README.md b/README.md index 2ebf311..8c8fa0f 100644 --- a/README.md +++ b/README.md @@ -120,18 +120,6 @@ Here are some examples of how you can use this module in your inventory structur | zone_id | Zone ID. | string | `` | no | - - -## Testing -In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system. - -You need to run the following command in the testing folder: -```hcl - go test -run Test -``` - - - ## Feedback 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). @@ -150,4 +138,4 @@ At [CloudDrove][website], we offer expert guidance, implementation support and s [linkedin]: https://cpco.io/linkedin [twitter]: https://twitter.com/clouddrove/ [email]: https://clouddrove.com/contact-us.html - [terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language= \ No newline at end of file + [terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language= From f5e28b910f55de835887820ea0ac3fc6db2e6508 Mon Sep 17 00:00:00 2001 From: Nikita Dugar Date: Tue, 5 Nov 2019 11:30:55 +0530 Subject: [PATCH 4/4] make simplest --- README.md | 20 +++++++++----------- README.yaml | 20 +++++++++----------- _example/set-with-alias/example.tf | 2 +- _example/simple-set/example.tf | 2 +- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2ebf311..45a7f45 100644 --- a/README.md +++ b/README.md @@ -72,25 +72,23 @@ Here are some examples of how you can use this module in your inventory structur ### Simple set ```hcl module "route53-record" { - source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" - + 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" + name = "www" + type = "A" + ttl = "3600" + values = "10.0.0.27" } ``` ### Set with alias ```hcl module "route53-record" { - source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" - + 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 = "www." + type = "A" + alias = { name = "d130easdflja734js.cloudfront.net" zone_id = "Z2FDRFHATA1ER4" evaluate_target_health = false diff --git a/README.yaml b/README.yaml index 9fde254..ace56fe 100644 --- a/README.yaml +++ b/README.yaml @@ -37,25 +37,23 @@ usage : |- ### Simple set ```hcl module "route53-record" { - source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" - + 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" + name = "www" + type = "A" + ttl = "3600" + values = "10.0.0.27" } ``` ### Set with alias ```hcl module "route53-record" { - source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" - + 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 = "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 0a9bd32..57d32ba 100644 --- a/_example/set-with-alias/example.tf +++ b/_example/set-with-alias/example.tf @@ -6,7 +6,7 @@ module "route53-record" { source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" zone_id = "Z1XJD7SSBKXLC1" - name = "www." + name = "www" type = "A" alias = { name = "d130easdflja734js.cloudfront.net" diff --git a/_example/simple-set/example.tf b/_example/simple-set/example.tf index 61f9b1e..2d403eb 100644 --- a/_example/simple-set/example.tf +++ b/_example/simple-set/example.tf @@ -6,7 +6,7 @@ module "route53-record" { source = "git::https://github.com/clouddrove/terraform-aws-route53-record.git?ref=tags/0.12.1" zone_id = "Z1XJD7SSBKXLC1" - name = "www." + name = "www" type = "A" ttl = "3600" values = "10.0.0.27"