create two aws_route53_record in different regions

372 views
Skip to first unread message

Mike Christofilopoulos

unread,
Nov 9, 2016, 11:24:33 AM11/9/16
to Terraform
Hi all,

I got the following resource

```
resource "aws_route53_record" "cdn-aws-region" {
    count = "${length(split(",", var.regions))}"
    zone_id = "${var.zone_id}"
    name = "${format("%s-cdn.%s%s", lower(var.continent), var.prefix, var.domain)}"
    type = "CNAME"
    ttl = "300"
    set_identifier = "${var.set_identifier}"
    records = [
        "${format("%s-cdn.%s%s", element(split(",", var.regions), count.index), var.prefix, var.domain)}"
    ]
    latency_routing_policy  {
        region = "${element(split(",", var.regions), count.index)}"
    }
}
```

and im trying to use it with this module


```
module "europe" {
    source = "../cdn"
    zone_id = "${aws_route53_zone.collection.zone_id}"
    set_identifier = "Europe"
    continent = "eu"
    regions = "eu-west-1,eu-central-1"
}
```

The problem is that its always creating only the second region entry, for example "eu-central-1", and not both of them.

Is there anything universally wrong that im doing ?

Cheers,
Mike

Tim Visher

unread,
Nov 10, 2016, 8:23:48 AM11/10/16
to terrafo...@googlegroups.com
Hi Mike,

You might want to change your regions var to a list like

regions = ["eu-west-1", "eu-central-1"]

Then you won't have to do the split trickery.

Other than that I don't see anything obviously wrong with what you're doing. And even that isn't 'wrong' so much as unoptimized.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/6687b316-08bd-44a7-96b3-ab1da2f448cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Christofilopoulos

unread,
Nov 10, 2016, 8:30:25 AM11/10/16
to Terraform
Thanks for the reply Tim.

I've tried using a list but terraform doesnt like this

with
```
module "europe" {
    source = "../cdn"
    zone_id = "${aws_route53_zone.collection.zone_id}"
    set_identifier = "Europe"
    continent = "eu"
    regions = ["eu-west-1", "eu-central-1"]
}
```

im getting

```
Error configuring: 1 error(s) occurred:

* variable regions in module route53.europe should be type string, got list
```

there is a high chance that im just completely wrong with how im setting things in a different part - im only starting using terraform.

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

Tim Visher

unread,
Nov 10, 2016, 9:29:36 AM11/10/16
to terrafo...@googlegroups.com
Ah you have to declare the variable as a list like:

```
variable regions { type = "list" }
```

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/c3dc4639-d3e7-43f8-8936-155b7ae76103%40googlegroups.com.

Mike Christofilopoulos

unread,
Nov 10, 2016, 9:45:14 AM11/10/16
to Terraform
this helped with the list conversion you suggested, but the problem still remains. I've attached terraform output bellow


```
#terraform apply
module.route53.aws_route53_zone.collection: Refreshing state... (ID: AAAX0123UAACCC)
module.route53.europe.aws_route53_record.cdn-region: Refreshing state... (ID: AAAX0123UAACCC_cdn_CNAME_Europe)
module.route53.europe.aws_route53_record.cdn-aws-region.0: Refreshing state... (ID: AAAX0123UAACCC_eu-cdn.tf-domain.net_CNAME_Europe)
module.route53.europe.aws_route53_record.cdn-aws-region.1: Refreshing state... (ID: AAAX0123UAACCC_eu-cdn.tf-domain.net_CNAME_Europe)
module.route53.europe.aws_route53_record.cdn-aws-region.1: Modifying...
  latency_routing_policy.0.region: "eu-central-1" => "eu-west-1"
  records.1777403104:              "" => "eu-west-1-cdn.tf-domain.net"
  records.355646978:               "eu-central-1-cdn.tf-domain.net" => ""
```

Thats with regions = ["eu-central-1", "eu-west-1"]
If i switch the order, then the same route53 entry is changed to eu-central-1.

Tim Visher

unread,
Nov 10, 2016, 10:00:00 AM11/10/16
to terrafo...@googlegroups.com
Interesting. I wouldn't expect this to be the case but we are currently storing count variables for this exact purpose. I would expect length to work in this instance but we're not using it and our code is succeeding. ¯\_(ツ)_/¯

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/5cb78366-214f-4b14-ad28-fa584e928351%40googlegroups.com.

Mike Christofilopoulos

unread,
Nov 10, 2016, 10:13:47 AM11/10/16
to Terraform
im not sure how that would work if you dont specify the count (i've added a sample bellow).
Is that what you got ?
I've tried that w/o any success.


```
resource "aws_route53_record" "cdn-aws-region" {
    #count = "${length(var.regions)}"
    zone_id = "${var.zone_id}"
    name = "${format("%s-cdn.%s%s", lower(var.continent), var.prefix, var.domain)}"
    type = "CNAME"
    ttl = "300"
    set_identifier = "${var.set_identifier}"
    records = [
        "${format("%s-cdn.%s%s", element(var.regions, count.index), var.prefix, var.domain)}"
    ]
    latency_routing_policy  {
        region = "${element(var.regions, count.index)}"
    }
}
```

Tim Visher

unread,
Nov 10, 2016, 10:16:15 AM11/10/16
to terrafo...@googlegroups.com
Sorry I mean I have something like:

```
resource "aws_route53_record" "charnock" {
  count = "${var.charnock_instance_count}"

  zone_id = "${var.box_dns_zone_id}"
  name = "${element(data.template_file.charnock_dns_entry.*.rendered, count.index)}"
  type = "A"
  ttl = 60

  records = ["${element(aws_opsworks_instance.charnock.*.private_ip, count.index)}"]
}
```

See the `var.charnock_instance_count` variable? So we explicitly count them rather than relying on a length interpolation.

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/3837c80f-b27f-4c01-b424-661206cf1501%40googlegroups.com.

Mike Christofilopoulos

unread,
Nov 10, 2016, 10:27:38 AM11/10/16
to terrafo...@googlegroups.com
no luck with the hardcoded count :(


For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/UJRdfKobfsA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAHa53uwXaAj6kndKDfpjBvppuweXW6_Ffs4orJoVOPWsSSgz6Q%40mail.gmail.com.

Tim Visher

unread,
Nov 10, 2016, 10:34:49 AM11/10/16
to terrafo...@googlegroups.com
Sorry. Not sure what else to tell you. :(

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/UJRdfKobfsA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-tool+unsubscribe@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CADkFEJ%2B1_DKimBapN-Pw31qLOR2PTtaeB6M0zDRcPKCD4iii%3Dw%40mail.gmail.com.

Mike Christofilopoulos

unread,
Nov 10, 2016, 12:57:11 PM11/10/16
to Terraform
Thanks to this[1] i found out that the `set_identifier` needs to have a different value for each region.

```
resource "aws_route53_record" "cdn-aws-region" {
    count = "${length(var.regions)}"
    zone_id = "${var.zone_id}"
    name = "${format("%s-cdn.%s%s", lower(var.continent), var.prefix, var.domain)}"
    type = "CNAME"
    ttl = "300"
    set_identifier = "${format("%s-%s", var.set_identifier, element(var.regions, count.index))}"
    records = [
        "${format("%s-cdn.%s%s", element(var.regions, count.index), var.prefix, var.domain)}"
    ]
    latency_routing_policy  {
        region = "${element(var.regions, count.index)}"
    }
}

For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/UJRdfKobfsA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-too...@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages