Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: route53_zone import saves name with trailing . in state causing plan to detect a change and try to recreate the zone #3982

Merged
merged 1 commit into from
Apr 10, 2018

Conversation

kaofelix
Copy link
Contributor

When creating a aws_route53_zone in terraform, you define the name of the domain as in the documentation:

resource "aws_route53_zone" "primary" {
  name = "example.com"
}

However, when importing an existing aws_route53_zone, terraform is using the name returned by AWS which has a trailing "." in the end of it which is the name displayed in the web console. The name with the trailing "." gets saved into your state causing an inconsistency, so if you run a plan right after importing the zone you get something like:

-/+ aws_route53_zone.test_zone (new resource required)
      id:             "Z273SRWTYTM3GQ" => <computed> (forces new resource)
      comment:        "Managed by Terraform" => "Managed by Terraform"
      force_destroy:  "" => "false"
      name:           "example.com." => "example.com" (forces new resource)
      name_servers.#: "4" => <computed>
      tags.%:         "2" => "0"
      tags.team:      "foobar" => ""
      tags.vertical:  "foobar" => ""
      vpc_region:     "" => <computed>
      zone_id:        "Z1234567890123" => <computed>

due to the difference in name. This PR fixes it buy removing the trailing "." when reading the zone name during an import. I also removed it from the data used in the acceptance tests since it doesn't match the example suggested in the docs.

@ghost ghost added the size/XS Managed by automation to categorize the size of a PR. label Mar 29, 2018
@bflad bflad added bug Addresses a defect in current functionality. service/route53 Issues and PRs that pertain to the route53 service. labels Mar 29, 2018
@bflad
Copy link
Contributor

bflad commented Mar 29, 2018

Hi @kaofelix thanks for this contribution!

Generally its preferable to not touch how an attribute is saved from the API as it can cause a breaking change in people's configurations when they upgrade. Instead, we can likely just tell Terraform that the attribute is equivalent with or without the period, by adding a DiffSuppressFunc on the attribute.

Something like this should be able to accomplish what we're looking for on the name attribute in the schema:

DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
  return strings.TrimSuffix(old, ".") == strings.TrimSuffix(new, ".")
},

Can you try that out?

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 29, 2018
@ghost ghost added size/S Managed by automation to categorize the size of a PR. and removed size/XS Managed by automation to categorize the size of a PR. labels Mar 29, 2018
@kaofelix
Copy link
Contributor Author

@bflad thanks for the tip, I wasn't aware of that! I just pushed a new implementation with your suggestion and it seems to work perfectly.

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Mar 29, 2018
@bflad bflad added this to the v1.14.1 milestone Apr 10, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- thanks! 🚀

8 tests passed (all tests)
=== RUN   TestAccAWSRoute53Zone_private_basic
--- PASS: TestAccAWSRoute53Zone_private_basic (59.30s)
=== RUN   TestAccAWSRoute53Zone_basic
--- PASS: TestAccAWSRoute53Zone_basic (66.12s)
=== RUN   TestAccAWSRoute53Zone_importBasic
--- PASS: TestAccAWSRoute53Zone_importBasic (70.36s)
=== RUN   TestAccAWSRoute53Zone_updateComment
--- PASS: TestAccAWSRoute53Zone_updateComment (73.61s)
=== RUN   TestAccAWSRoute53Zone_private_region
--- PASS: TestAccAWSRoute53Zone_private_region (85.55s)
=== RUN   TestAccAWSRoute53ZoneAssociation_basic
--- PASS: TestAccAWSRoute53ZoneAssociation_basic (107.61s)
=== RUN   TestAccAWSRoute53ZoneAssociation_region
--- PASS: TestAccAWSRoute53ZoneAssociation_region (115.55s)
=== RUN   TestAccAWSRoute53Zone_forceDestroy
--- PASS: TestAccAWSRoute53Zone_forceDestroy (377.81s)

@bflad bflad merged commit 33ca6e8 into hashicorp:master Apr 10, 2018
bflad added a commit that referenced this pull request Apr 10, 2018
@bflad
Copy link
Contributor

bflad commented Apr 11, 2018

This has been released in version 1.14.1 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 6, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/route53 Issues and PRs that pertain to the route53 service. size/S Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants