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

resource/aws_route53_record: Suppress uppercase alias name diff #3119

Merged
merged 2 commits into from
Jan 25, 2018

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Jan 24, 2018

Closes #361
Closes #439
Closes #1005

Uppercase ALB/ELB names generate an uppercase dns_name attribute from AWS which is subsequently saved into Terraform. When these are used for alias Route53 records, Route53 normalizes these to lowercase and only returns the lowercase value. Most folks have used the workaround (myself included) of using name = "${lower(aws_elb.X.dns_name)}".

I do not believe a state migration should be necessary for this change since uppercase name would have always generated the perpetual diff with the hash and name attribute itself.

Previously:

=== RUN   TestAccAWSRoute53Record_aliasUppercase
--- FAIL: TestAccAWSRoute53Record_aliasUppercase (234.96s)
	testing.go:513: Step 0 error: After applying this step, the plan was not empty:

		DIFF:

		UPDATE: aws_route53_record.alias
		  alias.1754141646.evaluate_target_health: "true" => "false"
		  alias.1754141646.name:                   "foobar-terraform-elb-1n1r4g62w0-123456789012.us-west-2.elb.amazonaws.com" => ""
		  alias.1754141646.zone_id:                "ZONEID" => ""
		  alias.561810618.evaluate_target_health:  "" => "true"
		  alias.561810618.name:                    "" => "FOOBAR-TERRAFORM-ELB-1n1r4g62w0-123456789012.us-west-2.elb.amazonaws.com"
		  alias.561810618.zone_id:                 "" => "ZONEID"

Passes local testing for me:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSRoute53Record'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSRoute53Record -timeout 120m
=== RUN   TestAccAWSRoute53Record_basic
--- PASS: TestAccAWSRoute53Record_basic (146.94s)
=== RUN   TestAccAWSRoute53Record_basic_fqdn
--- PASS: TestAccAWSRoute53Record_basic_fqdn (142.64s)
=== RUN   TestAccAWSRoute53Record_txtSupport
--- PASS: TestAccAWSRoute53Record_txtSupport (146.45s)
=== RUN   TestAccAWSRoute53Record_spfSupport
--- PASS: TestAccAWSRoute53Record_spfSupport (131.89s)
=== RUN   TestAccAWSRoute53Record_caaSupport
--- PASS: TestAccAWSRoute53Record_caaSupport (157.52s)
=== RUN   TestAccAWSRoute53Record_generatesSuffix
--- PASS: TestAccAWSRoute53Record_generatesSuffix (148.82s)
=== RUN   TestAccAWSRoute53Record_wildcard
--- PASS: TestAccAWSRoute53Record_wildcard (192.87s)
=== RUN   TestAccAWSRoute53Record_failover
--- PASS: TestAccAWSRoute53Record_failover (137.64s)
=== RUN   TestAccAWSRoute53Record_weighted_basic
--- PASS: TestAccAWSRoute53Record_weighted_basic (138.17s)
=== RUN   TestAccAWSRoute53Record_alias
--- PASS: TestAccAWSRoute53Record_alias (170.03s)
=== RUN   TestAccAWSRoute53Record_aliasUppercase
--- PASS: TestAccAWSRoute53Record_aliasUppercase (210.80s)
=== RUN   TestAccAWSRoute53Record_s3_alias
--- PASS: TestAccAWSRoute53Record_s3_alias (159.76s)
=== RUN   TestAccAWSRoute53Record_weighted_alias
--- PASS: TestAccAWSRoute53Record_weighted_alias (296.04s)
=== RUN   TestAccAWSRoute53Record_geolocation_basic
--- PASS: TestAccAWSRoute53Record_geolocation_basic (153.61s)
=== RUN   TestAccAWSRoute53Record_latency_basic
--- PASS: TestAccAWSRoute53Record_latency_basic (150.90s)
=== RUN   TestAccAWSRoute53Record_TypeChange
--- PASS: TestAccAWSRoute53Record_TypeChange (168.72s)
=== RUN   TestAccAWSRoute53Record_SetIdentiferChange
--- PASS: TestAccAWSRoute53Record_SetIdentiferChange (250.73s)
=== RUN   TestAccAWSRoute53Record_AliasChange
--- PASS: TestAccAWSRoute53Record_AliasChange (263.28s)
=== RUN   TestAccAWSRoute53Record_empty
--- PASS: TestAccAWSRoute53Record_empty (177.55s)
=== RUN   TestAccAWSRoute53Record_longTXTrecord
--- PASS: TestAccAWSRoute53Record_longTXTrecord (197.82s)
=== RUN   TestAccAWSRoute53Record_multivalue_answer_basic
--- PASS: TestAccAWSRoute53Record_multivalue_answer_basic (209.47s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	3751.723s

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Just few comments, but nothing major.

if strings.ToLower(old) == strings.ToLower(new) {
return true
}
return false
Copy link
Member

Choose a reason for hiding this comment

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

The whole function can be reduced to a single line:

return strings.ToLower(old) == strings.ToLower(new)

😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 good catch

@@ -968,6 +1005,36 @@ resource "aws_elb" "main" {
}
`

const testAccRoute53ElbAliasRecordUppercase = `
resource "aws_route53_zone" "main" {
name = "notexample.com"
Copy link
Member

Choose a reason for hiding this comment

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

I know other zones are static (so far), but can you randomize the name here, please? We can address others in a separate PR in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You got it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha! You'll love this. We actually hardcode it in the exists/destroy functions too: https://github.com/terraform-providers/terraform-provider-aws/blob/b-aws_route53_record-alias-name-diffsuppressfunc/aws/resource_aws_route53_record_test.go#L586

Its all or nothing 👎 -- I will get that nitpick merged though 👍

@bflad bflad added this to the v1.8.0 milestone Jan 25, 2018
@bflad bflad merged commit 35ccd6c into master Jan 25, 2018
@bflad bflad deleted the b-aws_route53_record-alias-name-diffsuppressfunc branch January 25, 2018 17:22
bflad added a commit that referenced this pull request Jan 25, 2018
@bflad
Copy link
Contributor Author

bflad commented Jan 29, 2018

This has been released in terraform-provider-aws version 1.8.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 8, 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 8, 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.
Projects
None yet
2 participants