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

provider/aws: ElastiCache (Redis) snapshot window and retention limits #3707

Merged

Conversation

stack72
Copy link
Contributor

@stack72 stack72 commented Oct 31, 2015

This fixes #3075

make testacc TEST=./builtin/providers/aws TESTARGS='-run=ElasticacheCluster_snapshots' 2>~/tf.log
go generate ./...
TF_ACC=1 go test ./builtin/providers/aws -v -run=ElasticacheCluster_snapshots -timeout 90m
=== RUN   TestAccAWSElasticacheCluster_snapshots
--- PASS: TestAccAWSElasticacheCluster_snapshots (366.93s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    366.946s

Also tested the ValidateFunc:

terraform [aws-elasticache-cluster-snapshoting●] % make testacc TEST=./builtin/providers/aws TESTARGS='-run=ElasticacheCluster_snapshots' 2>~/tf.log
go generate ./...
TF_ACC=1 go test ./builtin/providers/aws -v -run=ElasticacheCluster_snapshots -timeout 90m
=== RUN   TestAccAWSElasticacheCluster_snapshots
--- FAIL: TestAccAWSElasticacheCluster_snapshots (0.11s)
    testing.go:137: Step 0 error: Configuration is invalid.

        Warnings: []string(nil)

        Errors: []string{"aws_elasticache_cluster.bar: snapshot retention limit cannot be more than 35 days"}
FAIL

Creates the values as can be seen in the console:

screen shot 2015-10-30 at 23 57 53

@@ -344,6 +372,15 @@ func resourceAwsElasticacheClusterUpdate(d *schema.ResourceData, meta interface{
requestUpdate = true
}

if d.HasChange("snapshot_window") {
req.EngineVersion = aws.String(d.Get("snapshot_window").(string))
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not EngineVersion 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

D'OH!

@stack72
Copy link
Contributor Author

stack72 commented Nov 2, 2015

@catsby ok, sorry about that. these silly copy paste errors have been fixed now

@catsby
Copy link
Contributor

catsby commented Nov 2, 2015

Thanks @stack72 – some where things here... I thought you'd need to specify Computed: true for these attributes, but then I found you did not... so I dug in and found that SnapshotRetentionLimit and SnapshotWindow are nil in the API response... not sure why.

I did try to update the SnapshotWindow attribute and got a weird error:

* aws_elasticache_cluster.test: [WARN] Error updating ElastiCache cluster (test), error: InvalidParameterCombination: Instance type does not support snapshotting. Snapshot window parameter should not be specified.
    status code: 400, request id: 7e2dcf24-81ab-11e5-8466-199fd0904dd9

Not sure what that's about, the debug output of the update didn't mention instance type..

Plan:

~ aws_elasticache_cluster.test
    snapshot_window: "Wed:09:00-Wed:09:30" => "05:00-09:00"

Log:

[DEBUG]: 2015/11/02 15:48:47 [DEBUG] Modifying ElastiCache Cluster (test), opts:
[DEBUG]: {
[DEBUG]:   ApplyImmediately: false,
[DEBUG]:   CacheClusterId: "test",
[DEBUG]:   SnapshotWindow: "05:00-09:00"
[DEBUG]: }

Do you get this behavior too?

@catsby catsby added the waiting-response An issue/pull request is waiting for a response from the community label Nov 2, 2015
@stack72
Copy link
Contributor Author

stack72 commented Nov 2, 2015

@catsby I added an acceptance test to show these in motion and to make sure that they are set as expected and both worked. I was able to control my instance based on this as well

I think you are specifying a Memcached cluster?

If so, it only works for Redis clusters

@catsby
Copy link
Contributor

catsby commented Nov 2, 2015

Nah, I'm using Redis:

provider "aws" {
  region = "us-west-2"
}
resource "aws_vpc" "default" {
  cidr_block = "10.250.0.0/16"
  tags {
    Name = "ec-sub-test"
  }
}

resource "aws_subnet" "private" {
  vpc_id = "${aws_vpc.default.id}"
  cidr_block = "10.250.3.0/24"
}

resource "aws_subnet" "private2" {
  vpc_id = "${aws_vpc.default.id}"
  cidr_block = "10.250.2.0/24"
}

resource "aws_elasticache_subnet_group" "test" {
  name        = "test"
  description = "Test Redis"
  subnet_ids = [
    "${aws_subnet.private.*.id}", 
    "${aws_subnet.private2.id}",
  ]
}

resource "aws_elasticache_cluster" "test" {
  cluster_id = "test"
  subnet_group_name = "${aws_elasticache_subnet_group.test.name}"
  num_cache_nodes = 1
  node_type = "cache.t2.micro"
  engine = "redis"
  port = 6379

  snapshot_retention_limit = 1
  snapshot_window = "05:00-09:00"
}

The code seems to work, but adding debug statements in the read shows those attributes are nil from the API... at least for me..

@stack72
Copy link
Contributor Author

stack72 commented Nov 2, 2015

I'll have another look at the debugging of this in the morning and print some info

Thanks for checking this

…work. Also added some debugging to show that the API returns the Elasticache retention period info
@stack72
Copy link
Contributor Author

stack72 commented Nov 3, 2015

@catsby ok, I just added an extra test to make sure that updating works as expected. Also added some debug logic to the file to make sure that it writes INFO messages to the tf.log when running tests

I definitely get results on my side and I am using this logic in my code from this morning as a check

@@ -149,6 +204,76 @@ resource "aws_elasticache_cluster" "bar" {
port = 11211
parameter_group_name = "default.memcached1.4"
security_group_names = ["${aws_elasticache_security_group.bar.name}"]
snapshot_window = "05:00-09:00"
snapshot_retention_limit = 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Engine memcached does not support snapshotting, so the TestAccAWSElasticacheCluster_basic test now fails with this addition :/

@catsby
Copy link
Contributor

catsby commented Nov 4, 2015

I definitely get results on my side and I am using this logic in my code from this morning as a check

Do you get results if those attributes are omitted in the config?

@@ -344,6 +374,14 @@ func resourceAwsElasticacheClusterUpdate(d *schema.ResourceData, meta interface{
requestUpdate = true
}

if d.HasChange("snapshot_window") {
Copy link
Contributor

Choose a reason for hiding this comment

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

snapshot_window and snapshot_retention_limit are not toggling the requestUpdate bit, so they're never actually being sent in any update call.

@stack72
Copy link
Contributor Author

stack72 commented Nov 5, 2015

ok, @catsby all is working as expected now :)

I was able to code out the cache.t2 sizing as follows:

if !strings.Contains(d.Get("node_type").(string), "cache.t2") {
        if v, ok := d.GetOk("snapshot_retention_limit"); ok {
            req.SnapshotRetentionLimit = aws.Int64(int64(v.(int)))
        }

        if v, ok := d.GetOk("snapshot_window"); ok {
            req.SnapshotWindow = aws.String(v.(string))
        }
    }

I was also able to get the updates working (was missing requestUpdate=true):

if d.HasChange("snapshot_window") {
            req.SnapshotWindow = aws.String(d.Get("snapshot_window").(string))
            requestUpdate = true
        }

        if d.HasChange("snapshot_retention_limit") {
            req.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int)))
            requestUpdate = true
        }

also made sure not to cause panics in the Read event:

if c.SnapshotWindow != nil {
            d.Set("snapshot_window", c.SnapshotWindow)
        }
        if c.SnapshotRetentionLimit != nil {
            d.Set("snapshot_retention_limit", c.SnapshotRetentionLimit)
        }

The acceptance tests all work as expected now EXCEPT the vpc test which throws a panic. I just tried this on master and get the same error I'm afraid

P.

@@ -187,6 +205,16 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
req.CacheParameterGroupName = aws.String(v.(string))
}

if !strings.Contains(d.Get("node_type").(string), "cache.t2") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe this is the approach we should take. We should document that snapshotting does not work with cache.t2's , and we should bubble up the error if a user uses t2's anyway.

Only applying these params in this block would (especially without any message) would be misleading the user, as without an error, anything in their config that doesn't throw an error in applying will be written to state, so from Terraforms view, they are applied. But in reality, they are not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you thibk I should just log that snapshotting isn't available if the user specifies t2 and then just let the values be set? Or should I specifically check for snapahotting in conjunction with t2 (using a check like above) and throw an error?

@catsby
Copy link
Contributor

catsby commented Nov 5, 2015

Left a few additional notes, and we still need to document the snapshot limitation regarding t2s, otherwise looking good 😄

@catsby
Copy link
Contributor

catsby commented Nov 5, 2015

The acceptance tests all work as expected now EXCEPT the vpc test which throws a panic. I just tried this on master and get the same error I'm afraid

Yup, that's my fault 😦 it gets fixed in #3777

… We now allow the error to bubble up to the userr when the wrong instance type is used. The limitation for t2 instance types now allowing snapshotting is also now documented
@stack72
Copy link
Contributor Author

stack72 commented Nov 6, 2015

ok, @catsby, I have documented the t2 issue and now let the error bubble up to the user. I now get the following:

    * aws_elasticache_cluster.bar: Error creating Elasticache: InvalidParameterCombination: Instance type does not support snapshotting. Snapshot window parameter should not be specified.
            status code: 400, request id: 7b21df4b-8477-11e5-be36-5514cd0a8d29

This goes hand in hand with the NOTE added to the docs

resource "aws_elasticache_cluster" "bar" {
cluster_id = "tf-test-%03d"
engine = "redis"
node_type = "cache.t2.small"
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to be changed to cache.m1.small, or snapshot_window and snapshot_retention_limit need to be removed. The test that uses this config doesn't pass

Copy link
Contributor

Choose a reason for hiding this comment

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

Went ahead and made this change myself, thanks!

@catsby catsby merged commit 350f91e into hashicorp:master Nov 6, 2015
@catsby
Copy link
Contributor

catsby commented Nov 6, 2015

Thanks!

@stack72 stack72 deleted the aws-elasticache-cluster-snapshoting branch November 8, 2015 16:24
omeid pushed a commit to omeid/terraform that referenced this pull request Mar 30, 2018
resource/key_pair: drop custom ValidateFunc for name_prefix
@ghost
Copy link

ghost commented Apr 30, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement provider/aws waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWS Feature: Automated Backups for elasticache redis cluster
3 participants