hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.17k forks source link

aws_route53_record import at the zone apex #2160

Closed erkolson closed 4 years ago

erkolson commented 7 years ago

Terraform Version

Terraform v0.10.3

Affected Resource(s)

Terraform Configuration Files

resource "aws_route53_record" "mydomain" {
  zone_id = "${aws_route53_zone.mydomain.zone_id}"
  name    = ""
  type    = "A"
  ttl     = "60"

  records = [
    "100.10.10.10"
  ]
}

Debug Output

Error during run:

* aws_route53_record.mydomain: aws_route53_record.mydomain: diffs didn't match during apply. This is a bug with Terraform and should be reported as a GitHub Issue.

Please include the following information in your report:

    Terraform Version: 0.10.3
    Resource ID: aws_route53_record.mydomain
    Mismatch reason: attribute mismatch: name
    Diff One (usually from plan): *terraform.InstanceDiff{mu:sync.Mutex{state:0, sema:0x0}, Attributes:map[string]*terraform.ResourceAttrDiff{"records.29155466":*terraform.ResourceAttrDiff{Old:"104.198.176.34", New:"104.198.176.34", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "fqdn":*terraform.ResourceAttrDiff{Old:"mydomain.com", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "name":*terraform.ResourceAttrDiff{Old:"mydomain.com", New:"", NewComputed:false, NewRemoved:false, NewExtra:"", RequiresNew:true, Sensitive:false, Type:0x0}, "ttl":*terraform.ResourceAttrDiff{Old:"300", New:"60", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "zone_id":*terraform.ResourceAttrDiff{Old:"Z9YQDB516JSG0", New:"Z9YQDB516JSG0", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "type":*terraform.ResourceAttrDiff{Old:"A", New:"A", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "records.#":*terraform.ResourceAttrDiff{Old:"1", New:"1", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}}, Destroy:false, DestroyDeposed:false, DestroyTainted:false, Meta:map[string]interface {}(nil)}
    Diff Two (usually from apply): *terraform.InstanceDiff{mu:sync.Mutex{state:0, sema:0x0}, Attributes:map[string]*terraform.ResourceAttrDiff{"records.#":*terraform.ResourceAttrDiff{Old:"", New:"1", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "records.29155466":*terraform.ResourceAttrDiff{Old:"", New:"104.198.176.34", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "ttl":*terraform.ResourceAttrDiff{Old:"", New:"60", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "type":*terraform.ResourceAttrDiff{Old:"", New:"A", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "fqdn":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "zone_id":*terraform.ResourceAttrDiff{Old:"", New:"Z9YQDB516JSG0", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Sensitive:false, Type:0x0}}, Destroy:false, DestroyDeposed:false, DestroyTainted:false, Meta:map[string]interface {}(nil)}

Expected Behavior

The apply should complete without error, but also, after importing, there should be no need to apply anything (assuming the TTL matches)? Possibly related to this: https://github.com/terraform-providers/terraform-provider-aws/issues/1031

Actual Behavior

I imported an A record at the zone apex, then did a terraform plan. It showed the following changes:

-/+ aws_route53_record.mydomain (new resource required)
      fqdn:             "mydomain.com" => "<computed>"
      name:             "mydomain.com" => "" (forces new resource)
      records.#:        "1" => "1"
      records.29155466: "100.10.10.10" => "100.10.10.10"
      ttl:              "300" => "60"
      type:             "A" => "A"
      zone_id:          "ZOMGZONEID" => "ZOMGZONEID"

Then when I ran terraform apply the error above occured.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create an A record at the zone apex in the AWS console
  2. terraform import ...
  3. terraform plan
  4. terraform apply

Important Factoids

I did the exact same thing, terraform import, terraform plan, terraform apply with a CNAME at www.mydomain.com at the same time. That applied with no issues but still wanted to destroy/create because of the name bug (the ttl in the case of the CNAME matched what was already there in the record).

References

bandesz commented 6 years ago

I'm getting the same error with v0.11.3. Also you can't import an Apex record with its correct id which would be e.g. "ZONEID__MX".

Error: aws_route53_record.mx (import id: ZONEID__MX): 1 error(s) occurred:

* import aws_route53_record.mx result: ZONEID__MX: aws_route53_record.mx: Error Importing aws_route_53 record. Please make sure the record ID is in the form ZONEID_RECORDNAME_TYPE (i.e. Z4KAPRWWNC7JR_dev_A

I can import it with "ZONEID_DOMAINNAME_MX" but then the resource will be recreated at the next apply as the ids don't match.

After doing the import the second way I got the same "diffs didn't match during apply" error mentioned in this issue.

github-actions[bot] commented 4 years ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!