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_elasticache_cluster: Introduce initial CustomizeDiff #3857

Merged
merged 2 commits into from
Mar 21, 2018

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Mar 21, 2018

Closes #1702
Closes #2421

  • 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

* 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
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/elasticache Issues and PRs that pertain to the elasticache service. labels Mar 21, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 21, 2018
@bflad bflad requested review from radeksimko and a team March 21, 2018 07:06
Copy link
Contributor

@paultyng paultyng left a 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:

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")
Copy link
Contributor

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(...)

Copy link
Contributor Author

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") {
Copy link
Contributor

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

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 21, 2018
@bflad bflad force-pushed the f-aws_elasticache_cluster-customizediff-start branch from 19b84f6 to b583b26 Compare March 21, 2018 18:08
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Mar 21, 2018
@bflad
Copy link
Contributor Author

bflad commented Mar 21, 2018

Short-circuit logic is passing acceptance testing:

13 tests passed (all tests)
=== RUN   TestAccAWSElasticacheCluster_NumCacheNodes_Redis_Ec2Classic
--- PASS: TestAccAWSElasticacheCluster_NumCacheNodes_Redis_Ec2Classic (3.06s)
=== RUN   TestAccAWSElasticacheCluster_AZMode_Redis_Ec2Classic
--- PASS: TestAccAWSElasticacheCluster_AZMode_Redis_Ec2Classic (492.09s)
=== RUN   TestAccAWSElasticacheCluster_AZMode_Memcached_Ec2Classic
--- PASS: TestAccAWSElasticacheCluster_AZMode_Memcached_Ec2Classic (504.87s)
=== RUN   TestAccAWSElasticacheCluster_basic
--- PASS: TestAccAWSElasticacheCluster_basic (529.05s)
=== RUN   TestAccAWSElasticacheCluster_importBasic
--- PASS: TestAccAWSElasticacheCluster_importBasic (544.75s)
=== RUN   TestAccAWSElasticacheCluster_multiAZInVpc
--- PASS: TestAccAWSElasticacheCluster_multiAZInVpc (627.27s)
=== RUN   TestAccAWSElasticacheCluster_vpc
--- PASS: TestAccAWSElasticacheCluster_vpc (678.90s)
=== RUN   TestAccAWSElasticacheCluster_NodeTypeResize_Redis_Ec2Classic
--- PASS: TestAccAWSElasticacheCluster_NodeTypeResize_Redis_Ec2Classic (816.04s)
=== RUN   TestAccAWSElasticacheCluster_NodeTypeResize_Memcached_Ec2Classic
--- PASS: TestAccAWSElasticacheCluster_NodeTypeResize_Memcached_Ec2Classic (918.65s)
=== RUN   TestAccAWSElasticacheCluster_EngineVersion_Memcached_Ec2Classic
--- PASS: TestAccAWSElasticacheCluster_EngineVersion_Memcached_Ec2Classic (1071.12s)
=== RUN   TestAccAWSElasticacheCluster_decreasingCacheNodes
--- PASS: TestAccAWSElasticacheCluster_decreasingCacheNodes (1133.37s)
=== RUN   TestAccAWSElasticacheCluster_EngineVersion_Redis_Ec2Classic
--- PASS: TestAccAWSElasticacheCluster_EngineVersion_Redis_Ec2Classic (1145.27s)
=== RUN   TestAccAWSElasticacheCluster_snapshotsWithUpdates
--- PASS: TestAccAWSElasticacheCluster_snapshotsWithUpdates (1352.50s)

Merging!

@bflad bflad merged commit 1733f75 into master Mar 21, 2018
@bflad bflad deleted the f-aws_elasticache_cluster-customizediff-start branch March 21, 2018 18:40
@bflad bflad added this to the v1.12.0 milestone Mar 21, 2018
bflad added a commit that referenced this pull request Mar 21, 2018
@bflad
Copy link
Contributor Author

bflad commented Mar 23, 2018

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.

@ghost
Copy link

ghost commented Apr 7, 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 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elasticache Issues and PRs that pertain to the elasticache service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Downgrading Redis engine version should force new resource
2 participants