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

Defining more cache nodes than you have availability zones is not supported #27

Closed
gusse opened this issue Feb 2, 2021 · 1 comment · Fixed by #28
Closed

Defining more cache nodes than you have availability zones is not supported #27

gusse opened this issue Feb 2, 2021 · 1 comment · Fixed by #28
Labels
bug 🐛 An issue with the system

Comments

@gusse
Copy link
Contributor

gusse commented Feb 2, 2021

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

You cannot define more cache nodes than you have defined availability zones.

Expected Behavior

You should be able to have more nodes than AZs (max 20 for memcached), terraform documentation does mention that the preferred_availability_zones parameter should have a list with same amount of AZ as you have num_cache_nodes defined (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster#preferred_availability_zones) so I do understand the attempt to use slice() function in https://github.com/cloudposse/terraform-aws-elasticache-memcached/blob/master/main.tf#L101, but I doesn't work for this use case.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Define more nodes than AZs, e.g. 2 AZs and 3 nodes.
module "memcached" {
  source             = "git::https://github.com/cloudposse/terraform-aws-elasticache-memcached.git?ref=tags/0.9.2"
  name               = "test"
  availability_zones = ["us-east-1a", "us-east-1b"]
  vpc_id             = "vpc-123456"
  cluster_size       = 3
  instance_type      = "cache.r5.large"
  engine_version     = "1.5.16"
}
  1. Run terraform plan
  2. See error
Error: Invalid function argument

  on .terraform/modules/memcached/main.tf line 101, in resource "aws_elasticache_cluster" "default":
 101:   preferred_availability_zones = slice(var.availability_zones, 0, var.cluster_size)
    |----------------
    | var.cluster_size is 3

Invalid value for "end_index" parameter: end index must not be greater than
the length of the list.

Additional Context

I'll try to figure out a way to construct a list with AZs that matches the number of cache nodes and make a PR myself.

@gusse gusse added the bug 🐛 An issue with the system label Feb 2, 2021
@gusse
Copy link
Contributor Author

gusse commented Feb 2, 2021

Oh yea, I guess you could define the same AZ multiple times in the var.availability_zones list, like follows:

...
  availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c" ,"us-east-1d", "us-east-1e", "us-east-1f", "us-east-1a"]
  cluster_size       = 7
...

But that is a workaround..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant