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

feat(aws): Adds support for Elasticache. #218

Closed
wants to merge 7 commits into from

Conversation

robh007
Copy link
Contributor

@robh007 robh007 commented Nov 11, 2020

Objective:

Adds support for elasticahe_cluster & elasticache_replication_group

** Closes ** #105

Example output:

  NAME                                                    MONTHLY QTY  UNIT       PRICE   HOURLY COST  MONTHLY COST  

  aws_elasticache_cluster.this                                                                                       
  ├─ Elasticache (on-demand, cache.m4.large)                      730  hours      0.1560       0.1560      113.8800  
  └─ Elasticache snapshot storage                                   0  GB-months  0.0850       0.0000        0.0000  
  Total                                                                                        0.1560      113.8800  
                                                                                                                     
  aws_elasticache_replication_group.cluster                                                                          
  └─ Elasticache (on-demand, cache.m4.large)                   11,680  hours      0.1560       2.4960    1,822.0800  
  Total                                                                                        2.4960    1,822.0800  
                                                                                                                     
  aws_elasticache_replication_group.non-cluster                                                                      
  └─ Elasticache (on-demand, cache.m4.large)                    2,190  hours      0.1560       0.4680      341.6400  
  Total                                                                                        0.4680      341.6400  
                                                                                                                     
  aws_elasticache_replication_group.non-cluster-snapshot                                                             
  ├─ Elasticache (on-demand, cache.m4.large)                   11,680  hours      0.1560       2.4960    1,822.0800  
  └─ Elasticache snapshot storage                                   0  GB-months  0.0850       0.0000        0.0000  
  Total                                                                                        2.4960    1,822.0800  
                                                                                                                     
  OVERALL TOTAL (USD)                                                                          5.6160    4,099.6800  

Pricing details:

The elasticache service provides 2 pricing components described in https://aws.amazon.com/elasticache/pricing/. This adds support for the Elasticache clusters & replication_groups.

@alikhajeh1 alikhajeh1 self-assigned this Nov 12, 2020
Copy link
Member

@alikhajeh1 alikhajeh1 left a comment

Choose a reason for hiding this comment

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

Thanks @robh007! I left my suggestions, they also apply to aws_elasticache_replication_group.

Also, what happened to this discussion:

Rob I've added support for elasticache cluster. However with elasticache cluster you can also create an elasticache_replcation_group. So in terraform there's two resources, the cluster can reference the replication group. So the cost is associated with the replication group. I was thinking that I add the elasticache_replication_group as another supported resource. If the cluster specifies the replication group the cost will be shown in the replication group & not the cluster. Does that make sense? I looked at what DynamoDB does with Global tables, but that's slightly different as the dynamoDB resource supports global tables & there's also an actual resource for global_tables.
Ali: Yeah I think that makes sense, so if aws_elasticache_cluster.replication_group_id is set, it gets no costs and the aws_elasticache_replication_group.number_cache_clusters/node_type are used to calculate the cost, right?
Rob: Yeah that appears to be correct. It's only applicable for Redis clusters.


if snapShotRetentionLimit.GreaterThan(decimal.NewFromInt(0)) {
costComponents = append(costComponents, &schema.CostComponent{
Name: "Elasticache snapshot storage",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Name: "Elasticache snapshot storage",
Name: "Backup storage",

We use that already and it matches the AWS pricing page


if cacheEngine == "redis" && d.Get("snapshot_retention_limit").Exists() {
snapShotRetentionLimit = decimal.NewFromInt(d.Get("snapshot_retention_limit").Int())
backupRetention = snapShotRetentionLimit.Sub(decimal.NewFromInt(1))
Copy link
Member

Choose a reason for hiding this comment

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

This should only be done if snapShotRetentionLimit > 0, right? the docs mention "f the value of SnapshotRetentionLimit is set to zero (0), backups are turned off."


snapShotRetentionLimit := decimal.Zero
backupRetention := decimal.Zero
monthlyBackupStorageTotal := decimal.Zero
Copy link
Member

Choose a reason for hiding this comment

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

I think we should default this to nil (not zero), that means that the costComponent's MonthlyQuantity defaults to nil, so the table/json output shows -/nil for the cost but the price should be shown. Zero implies that either we or the user has provided params that can be used to calculate the cost, and that cost might be 0, but nil means it's unknown.

backupRetention = snapShotRetentionLimit.Sub(decimal.NewFromInt(1))
}

if u != nil && u.Get("monthly_backup_storage").Exists() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if u != nil && u.Get("monthly_backup_storage").Exists() {
if u != nil && u.Get("backup_storage").Exists() {

This might be clearer? so the user defines backup_storage.snapshot_storage_size and we multiply that by the backupRetention to calculate the monthly storage vs the user providing the monthly_backup_storage...

},
}

if snapShotRetentionLimit.GreaterThan(decimal.NewFromInt(0)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if snapShotRetentionLimit.GreaterThan(decimal.NewFromInt(0)) {
if cacheEngine == "redis" && snapShotRetentionLimit.GreaterThan(decimal.NewFromInt(1)) {

How about if we show this costComponent for redis where the retention is more than 1 (0 means no backups so no point in showing it, and 1 means it's free per the AWS pricing page)? Lines 35-42 could also move inside this if block, makes it slightly easier to read the code...

@alikhajeh1 alikhajeh1 assigned robh007 and unassigned alikhajeh1 Nov 13, 2020
@alikhajeh1 alikhajeh1 added this to In progress in Main Nov 13, 2020
@alikhajeh1 alikhajeh1 moved this from In progress to Merged to master in Main Nov 13, 2020
@alikhajeh1 alikhajeh1 moved this from Merged to master to In progress in Main Nov 13, 2020
@alikhajeh1 alikhajeh1 removed this from In progress in Main Nov 13, 2020
@robh007
Copy link
Contributor Author

robh007 commented Nov 14, 2020

@alikhajeh1 I've updated inline with your comments. Plus I've added the reference to the replication_group_id if present within the cluster configuration.

@alikhajeh1
Copy link
Member

Closing this as #222 has an updated/refactored version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants