DNS record for an existing route53 zone

790 views
Skip to first unread message

Cassiano Aquino

unread,
Sep 7, 2016, 8:09:36 AM9/7/16
to Terraform
Hi,

I'm trying to setup an environment where I need to use existing domains, which I don't want to be destroyed/created by terraform as the DNS servers will change and this will require changes to the registar.

I need to get the dns nameservers for an internal zone to add to my dhcp records, is there any way to do it with terraform?

If not is there any plans for route53 data source to query this kind of information?

Jonathan Camp

unread,
Sep 9, 2016, 8:45:52 AM9/9/16
to Terraform
Same issue here. I tried adding an external resource using `terraform import`, but that seems to then make it eligible for destruction. 

Dominik Żyła

unread,
Sep 12, 2016, 1:45:46 PM9/12/16
to terrafo...@googlegroups.com
After you import it, you need to write its definition in your terraform files. Otherwise, indeed, terraform would mark it for destruction.

Best,
— 
Dominik Zyla

On 9 Sep 2016, at 13:45, Jonathan Camp <jona...@yaresse.com> wrote:

Same issue here. I tried adding an external resource using `terraform import`, but that seems to then make it eligible for destruction. 

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/a76ad64b-7ecf-4359-b14d-205fd798922b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Hodgson

unread,
Sep 12, 2016, 1:45:46 PM9/12/16
to terrafo...@googlegroups.com
Hi,

When you create the records in the existing zone, use a variable for the zone ID and populate it with the existing zone ID that is for the existing zone. I do this and it works fine for me for managing zones where I have a mix of records managed by Terraform and not managed by Terraform.

Andrew.

________________________________________
From: 'Cassiano Aquino' via Terraform [terrafo...@googlegroups.com]
Sent: 07 September 2016 13:09
To: Terraform
Subject: [terraform] DNS record for an existing route53 zone
--
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<mailto:terraform-too...@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/48b953ca-8d11-411b-bcc3-9b2958a7e9c3%40googlegroups.com<https://groups.google.com/d/msgid/terraform-tool/48b953ca-8d11-411b-bcc3-9b2958a7e9c3%40googlegroups.com?utm_medium=email&utm_source=footer>.

Dominik Żyła

unread,
Sep 12, 2016, 1:45:53 PM9/12/16
to terrafo...@googlegroups.com

Hi Cassiano,

I think you could import the existing zone with its records using terraform import. This won't create the new one with new name servers so no registrar changes needed. This would require terraform 0.7.

Best,

Dominik Zyla


--
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/48b953ca-8d11-411b-bcc3-9b2958a7e9c3%40googlegroups.com.

Cassiano Aquino

unread,
Sep 12, 2016, 2:08:39 PM9/12/16
to terrafo...@googlegroups.com
Hi all,

I tried to import the resource and mark it to not be deleted in the terraform configuration, but this also makes terraform to fail, so I did a workaround to make it happen.

I'm using a module to create my DNS zones, what I did was to emulate a conditional using count, not creating a new zone if the zone_id is defined and only manage the records.



If you pass the variable zone_id, it will not create a zone, if you don't a new zone will be created.

I tested this approach, and it works as expected, only the records inside of the zone are deleted for existing zones.

As terraform does not have a function "defined" to check if a variable was defined or not, I needed to use an ugly hack to achieve this:

variable "is_defined" {
  type = "map"
  default = {
    "0" = "1"
  }
}

resource "aws_route53_zone" "main" {
  count   = "${lookup(var.is_defined,length(var.zone_id),0)}"
  name    = "${var.name}"
  vpc_id  = "${var.vpc_id}"
  comment = ""
}

When the length of zone_id is 0, which means undefined, I will do a lookup on the is_defined map and for length 0 it will return 1, and for any other length for zone_id it will return 0 as the third parameter for lookup.

This hack looks ugly and could be solved if we have a not operator in terraform doing a 

count = "${not legth(var.zone_id)}" 

or a defined function

count = "${defined(var.zone)}"

I hope this helps someone else.

Thanks,
Cassiano 

PS: I will do a more clear and structure blog post about this

On Mon, Sep 12, 2016 at 6:45 PM Dominik Żyła <domini...@gmail.com> wrote:

Hi Cassiano,

I think you could import the existing zone with its records using terraform import. This won't create the new one with new name servers so no registrar changes needed. This would require terraform 0.7.

Best,

Dominik Zyla

On 7 Sep 2016 1:09 pm, "'Cassiano Aquino' via Terraform" <terrafo...@googlegroups.com> wrote:
Hi,

I'm trying to setup an environment where I need to use existing domains, which I don't want to be destroyed/created by terraform as the DNS servers will change and this will require changes to the registar.

I need to get the dns nameservers for an internal zone to add to my dhcp records, is there any way to do it with terraform?

If not is there any plans for route53 data source to query this kind of information?

--
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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CABOW3gZ9SJp3hvukc_Kg544gDVwRbGC9K-Msi3d-oMR-eb6S5w%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
--
Reply all
Reply to author
Forward
0 new messages