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

Error: Either number_cache_clusters or cluster_mode must be set when both are #10458

Closed
ghost opened this issue Oct 10, 2019 · 5 comments
Closed
Labels
service/elasticache Issues and PRs that pertain to the elasticache service.

Comments

@ghost
Copy link

ghost commented Oct 10, 2019

This issue was originally opened by @alepeltier as hashicorp/terraform#23044. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.12.10

Terraform Configuration Files

resource "aws_elasticache_replication_group" "shared_microservice_cache" {
  engine                = "redis"
  node_type             = var.elasticache_instance_type
  port                  = 6379
 number_cache_clusters = 3

  // Time is in UTC
  maintenance_window = "sun:03:00-sun:06:00"

  snapshot_retention_limit = var.elasticache_snapshot_rentention_limit
  snapshot_window          = "00:00-02:00"

  subnet_group_name  = aws_elasticache_subnet_group.default.name
  security_group_ids = [module.security_group.id]

  automatic_failover_enabled = true

  replication_group_description = format("%s %s %s",
    "A redis cache which can be used by any microservice in the",
    var.environment,
    "environment"
  )

  replication_group_id = format("%s-%s",
    "microservice",
    var.environment
  )

  at_rest_encryption_enabled = true
  transit_encryption_enabled = true
  auth_token                 = random_password.redis_password.result

  cluster_mode {
    replicas_per_node_group = var.elasticache_replicas_per_node_group
    num_node_groups         = var.elasticache_num_node_groups
  }
}

Expected Behavior

According to the documentation, I should be able to make a clustered Redis cache by setting either cluster_mode or number_cache_clusters. I have both set in the above code however when I run an apply Terraform throws an error saying I need to have them set. I've had this issue multiple times and don't think it is the expected behaviour unless I'm doing something wrong.

Actual Behavior

I get the following error

Error: Either `number_cache_clusters` or `cluster_mode` must be set

  on main.tf line 82, in resource "aws_elasticache_replication_group" "shared_microservice_cache":
  82: resource "aws_elasticache_replication_group" "shared_microservice_cache" {

Steps to Reproduce

1: Run terraform apply

@ghost ghost added the service/elasticache Issues and PRs that pertain to the elasticache service. label Oct 10, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 10, 2019
@pauliuspetka
Copy link

pauliuspetka commented Oct 10, 2019

I think You can solve this by adding cluster_mode to condition:

`    dynamic "cluster_mode" {
        for_each = "${var.cacheClusterMode == 0 ? [] : var.eCaches}"
         content { 
                 replicas_per_node_group = "${cluster_mode.value.replicas_per_node_group}"
                 num_node_groups         = "${cluster_mode.value.num_node_groups}"
         }
        }`

@alepeltier
Copy link

@pauliuspetka

Thanks for your reply. I'm struggling to see how a dynamic block will help in this situation though. The cluster block always has populated variables and I always want it to be enabled. Dynamic blocks are usually used if you want to dynamically render some code which I'm not particularly interested in doing.

For me, if cluster_mode {} is set the code should automatically create a clustered instance. Have I missed something here I'd be interested in hearing how you go round this issue?

@syntastical
Copy link

The ElastiCache Terraform is very confusing and in my opinion needs to be revamped and updated. However, you should either specify number_cache_clusters or cluster_mode, not both. The official documentation states the follow "number_cache_clusters - (Required for Cluster Mode Disabled) ".

@gdavison
Copy link
Contributor

gdavison commented Jan 7, 2021

As mentioned above, only one of cluster_mode or number_cache_clusters. More recent versions give a better error message.

We have also opened #14959 to address the design of the ElastiCache resources

@gdavison gdavison closed this as completed Jan 7, 2021
@ghost
Copy link
Author

ghost commented Feb 6, 2021

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 as resolved and limited conversation to collaborators Feb 6, 2021
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/elasticache Issues and PRs that pertain to the elasticache service.
Projects
None yet
Development

No branches or pull requests

5 participants