-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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_elasticache_cluster: Introduce initial CustomizeDiff #3857
Conversation
* Support plan time validation of az_mode * Support plan time validation of node_type requiring VPC for cache.t2 instances * Support plan time validation of num_cache_nodes > 1 for redis * ForceNew memcached on node_type changes * ForceNew on engine_version downgrades
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, but some style comments. The early return vs nesting thing is somewhat opinion based, but I think in Go with the error handling it somewhat favors early return style:
- https://golang.org/doc/effective_go.html#if
- https://arne-mertz.de/2016/12/early-return/
- http://www.danp.net/2015/11/02/reducing-go-nesting.html
etc.
func(diff *schema.ResourceDiff, v interface{}) error { | ||
// Plan time validation for az_mode | ||
// InvalidParameterCombination: Must specify at least two cache nodes in order to specify AZ Mode of 'cross-az'. | ||
azMode, azModeOk := diff.GetOk("az_mode") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not something to hold up merging, and probably leaning more towards preference, but you could rewrite this a little so you could just reuse the standard ok
and short circuiting a little earlier (also helping the line length a little):
if azMode, ok := diff.GetOk("az_mode"); !ok || azMode.(string) != elasticache.AZModeCrossAz {
return nil
}
if numCacheNodes, ok := diff.GetOk("num_cache_nodes"); !ok || numCacheNodes.(int) != 1 {
return nil
}
return errors.New(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I'll update this. (Personally I prefer early returns too)
// Plan time validation for engine_version | ||
// InvalidParameterCombination: Cannot modify memcached from 1.4.33 to 1.4.24 | ||
// InvalidParameterCombination: Cannot modify redis from 3.2.6 to 3.2.4 | ||
if diff.Id() != "" && diff.HasChange("engine_version") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the other short circuiting one, this flattens out if you just do the easy return first:
if diff.Id() == "" || !diff.HasChange("engine_version") {
return nil
}
// rest of it, but flatter indentation
19b84f6
to
b583b26
Compare
Short-circuit logic is passing acceptance testing:
Merging! |
This has been released in version 1.12.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
Closes #1702
Closes #2421