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

resource/aws_elasticache_replication_group: Migrate from availability_zones TypeSet attribute to preferred_availability_zones TypeList attribute #5104

Closed
moose007 opened this issue Jul 6, 2018 · 7 comments
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elasticache Issues and PRs that pertain to the elasticache service.

Comments

@moose007
Copy link

moose007 commented Jul 6, 2018

This bug is very similar to #4741 but is for the other ElastiCache resource ("aws_elasticache_replication_group" vs "aws_elasticache_cluster")

provider "aws" {
    version = ">= 1.23.0"
    region = "${var.region}"
    profile = "${var.profile}"
}

I'm trying to create 2 primary shards with 1 read replica each.

cache_node_type = "cache.m4.large"
cache_node_groups = 2 
cache_replicas_per_node_group = 1
cache_availability_zones = ["us-west-2a", "us-west-2b"]]
cache_automatic_failover_enabled = true
resource "aws_elasticache_replication_group" "default" {
  engine                                          = "redis"
  engine_version                                  = "3.2.6"
  replication_group_id                            = "cache-env"
  replication_group_description                   = "some description"
  node_type                                       = "cache.m4.large"
  port                                            = 6379
  parameter_group_name                            = "${aws_elasticache_parameter_group.default.id}"
  subnet_group_name                               = "${aws_elasticache_subnet_group.default.name}"
  availability_zones           	                  = ["${var.cache_availability_zones}"]
  security_group_ids                              = ["${aws_security_group.elasticache.id}"]
  transit_encryption_enabled                      = true
  automatic_failover_enabled                      = "true"

  cluster_mode {
    replicas_per_node_group                       = "${var.replicas_per_node_group}"
    num_node_groups                               = "${var.node_groups}"
  }

  tags {
    Name = "cache-${var.env}"
  }
}
resource "aws_elasticache_parameter_group" "default" {
  name   = "cache-params-${var.env}"
  family = "redis3.2"

  parameter {
    name  = "cluster-enabled"
    value = "yes"
  }
}

I got the following error when terraform applying:

Error creating Elasticache Replication Group: InvalidParameterCombination: PreferredCacheClusterAZs can only be specified for one node group.

Note, by excluding the availability_zones attribute in the resource, you can workaround this and deploy a multi-shard Redis cluster with read replicas across multiple AZs.

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/elasticache Issues and PRs that pertain to the elasticache service. labels Jul 6, 2018
@bflad
Copy link
Contributor

bflad commented Jul 6, 2018

There are two separate feature requests here, so we should clarify this issue as one or the other (creating a separate issue as necessary).

This error is returning from the Elasticache API:

Error creating Elasticache Replication Group: InvalidParameterCombination: PreferredCacheClusterAZs can only be specified for one node group.

The reason this is occurring is because the availability_zones argument is not compatible with Redis Cluster Mode Enabled replication groups where there is more than 1 shard -- in the Elasticache SDK, this is the full documentation for the parameter that availability_zones sets:

    // A list of EC2 Availability Zones in which the replication group's clusters
    // are created. The order of the Availability Zones in the list is the order
    // in which clusters are allocated. The primary cluster is created in the first
    // AZ in the list.
    //
    // This parameter is not used if there is more than one node group (shard).
    // You should use NodeGroupConfiguration instead.
    //
    // If you are creating your replication group in an Amazon VPC (recommended),
    // you can only locate clusters in Availability Zones associated with the subnets
    // in the selected subnet group.
    //
    // The number of Availability Zones listed must equal the value of NumCacheClusters.
    //
    // Default: system chosen Availability Zones.
    PreferredCacheClusterAZs []*string `locationNameList:"AvailabilityZone" type:"list"`

So to explicitly configure availability_zones for the same availability zone multiple times for Redis Cluster Mode Disabled or single shard replication groups, the attribute does need to be migrated similar to how preferred_availability_zones was for the aws_elasticache_cluster resource.

For Redis Cluster Mode Enabled replication groups (e.g. when using cluster_mode in Terraform), we currently do not have the ability to set availability zones via the NodeGroupConfiguration parameter, which would likely require changing the cluster_mode argument.

@moose007
Copy link
Author

moose007 commented Jul 7, 2018

Thanks @bflad for that insight. Apparently I borrowed the availability_zones parameter from the aws_elasticache_cluster resource since it's not listed in attribute references documentation for elasticache_replication_group.

I created a second feature request (#5118) for supporting setting AZ in NodeGroupConfiguration, I personally do not need it at the moment, but I imagine it would be nice to have in some situations.

IMO, how "cheap" it would be to port over to port over what you did for aws_elasticache_cluster to this resource, would determine whether it should be done or not. I don't personally need it, and unfortunately I don't have any extra cycles to create a PR myself for it.

@HudsonAkridge
Copy link

HudsonAkridge commented Oct 2, 2018

We're also running into this issue.

@rinkymangal2010
Copy link

If we setup Redis Cluster (Cluster mode enabled) using Terraform, then currently terraform do not have ability to set single availability zone while it is doable directly via AWS console.

It will be great if this can be done by terraform. Because if we create cluster nodes in same availability zone(Same as server) then we can save data transfer cost.

@grjones
Copy link

grjones commented May 14, 2019

Is there any work-a-round for this?

@gdavison
Copy link
Contributor

As @bflad noted above, this issue combines two separate feature requests. I've created #18438 to add a corrected TypeList parameter preferred_cache_cluster_azs and deprecate availability_zones. The issue #5118 covers specifying availability zones when "Cluster Mode" is enabled.

Since we now have two specific issues to track the work separately, I'm going to close this issue.

@ghost
Copy link

ghost commented Apr 26, 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 Apr 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elasticache Issues and PRs that pertain to the elasticache service.
Projects
None yet
Development

No branches or pull requests

6 participants