0
votes

When running a terraform apply on Atlas for and it fails on AWS route 53, I encounter the following error:

Apply execution has failed
The apply encountered an errored while executing 10 minutes ago. State information was persisted and subsequent applies will continue making changes in a safe way.
Terraform v0.6.11

Setting up remote state...
Downloading remote modules...
Refreshing Terraform state prior to plan...
aws_route53_zone.zone: Destroying...
module.prod_website.aws_iam_access_key.website: Creating...
  secret:            "" => "<computed>"
  ses_smtp_password: "" => "<computed>"
  status:            "" => "<computed>"
  user:              "" => "domain.tld"
module.prod_website.aws_iam_access_key.website: Creation complete
Error applying plan:

1 error(s) occurred:

* aws_route53_zone.zone: HostedZoneNotEmpty: The specified hosted zone contains non-required resource record sets  and so cannot be deleted.
    status code: 400, request id: 8305ce48-cab3-11e5-92ae-d57244aa6db1

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

How do I figure out the ID of the hosted zone so that I can delete it? Alternatively, how can I figure out the resource being used and taint that resource? The repo for this apply is here: https://github.com/zinedistro/infrastructure

Edit: Here are the full debug logs

4
Can you run again with debug enabled? TF_LOG=DEBUG; terraform apply.What do you get?BMW

4 Answers

0
votes

It looks like the hosted zone that terraform is trying to create/destroy/manipulate in some way already exists. This could be from a previous failed creation attempt or someone manually adding the zone previously. One option to resolve this error is to go in through the console and determine what specific zone ("website"?) exists already and just manually delete it and then recreate with Terraform.

0
votes

Using the AWS CLI, you can run aws route53 list-hosted-zones to get a list of hosted zones.

Additonally, you can go to the AWS console > Route 53 > Hosted Zones and look at the Hosted Zone ID column.

0
votes

A hosted zone cannot be deleted if there is even one non-default record set. Check this in the AWS docs.

0
votes

Terraform 0.7.1 introduced the ability to specify the force_destroy parameter to the zone which if set to true will delete all the records in the zone and then delete the zone itself.

This might be useful if you want Terraform to completely manage the zone but other tooling may add records that Terraform has no knowledge of.