Adding a new MX Record on an existing Hosted zones on AWS Route 53 by using Terraform

191 views Asked by At

I'm trying to add an MX Record on an existing hosted zone on AWS Route 53 by using Terraform and receiving the error:

 resource \"aws_route53_record\" \"amazonses_verification_record\" {", "", "", "Error: creating Route 53 Record: InvalidChangeBatch: [Tried to create resource record set [name='stackoverflow.com', type='MX'] but it already exists]

In my understanding, that is happening because the hosted zone was created manually and it has other records. When Terraform tries to recreate it, it cannot destroy it giving this error.

Is there any way to instantiate the Hosted Zone without the necessity of destroying it?

Here is the code used for creating the MX Record:

data "aws_region" "current" {}

data "aws_route53_zone" "hostedZone" {
  name         = "stackoverflow.com"
  private_zone = false
}

resource "aws_route53_record" "mx_record" {

  name    = data.aws_route53_zone.hostedZone.name
  type    = "MX"
  zone_id = data.aws_route53_zone.hostedZone.zone_id
  ttl     = "600"
  records = ["10 inbound-smtp.${data.aws_region.current.name}.amazonaws.com"]
}

Any help is welcomed. Thank you in advance

0

There are 0 answers