hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.59k stars 9.54k forks source link

AWS: Elasticache Redis snapshot_arns cannot be blank #3121

Closed jonhatalla closed 8 years ago

jonhatalla commented 9 years ago

This is not a terraform issue, as AWS will not let the snapshot_arns param be blank.

However, for certain environments, we have parameters that will preload redis with a snapshot. For other environments, we would like an empty redis instance.

A couple of possible solutions:

  1. If snapshot_arns is empty, don't send the parameter
  2. Wrap the snapshot_arns = ["snapshot_id"] line in a conditional statement (i know there are a ton of threads already created on conditionals)

My workaround in code is to create 2 blocks for elasticache redis and two route 53 endpoints. I created a couple of flags which set the count to 1 or 0 depending on what option the environment variables passed in needs.

There is a lot of tooling around this in my code now, but wanted to throw this out there as others might run into this.

nTraum commented 8 years ago

Stumbled upon the same problem, thanks for opening an issue. If you are looking for a workaround until this is fixed:

Extract the value for the snapshot_arns parameter into a variable and let it default to an empty dump file (that you upload to S3). This is ugly, but enables you to use the same resource / module for ElastiCache clusters (regardless of wether they need to be seeded at creation or not).

# NOTE: The default value pointing to an empty Redis dump is a workaround.
# Specifying an empty string leads to an error at creation time (terraform 0.6.8).
# This can be removed when:
# * Terraform supports conditionals (so this variable / corrosponding parameter is only set when non-empty)
# * Terraform fixes this upstream (in the provider) and automatically ignores this parameter when it's empty
# See https://github.com/hashicorp/terraform/issues/3121
variable "snapshot_arns" {
  description = "String specifying an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in S3"
  default     = "arn:aws:s3:::redis-dumps/empty-dump.rdb"
}

You still need to use the split magic to create an array out of the string (terraform 0.6.8).

stack72 commented 8 years ago

Hi @jonhatalla

Can you tell me if this is still a problem? As far as the code goes, if there is no snapshot_arns provided to terraforn, then it will not send them as part of the request:

    snaps := d.Get("snapshot_arns").(*schema.Set).List()
    if len(snaps) > 0 {
        s := expandStringList(snaps)
        req.SnapshotArns = s
        log.Printf("[DEBUG] Restoring Redis cluster from S3 snapshot: %#v", s)
    }

Notice that we only add to the request if there is more than 1 defined

Paul

stack72 commented 8 years ago

Hi, I am going to close this out for now. This doesn't seem to be an issue in our nightly acceptance tests. IF this is still causing you issues, then please do let me know! :)

ghost commented 4 years ago

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.