skip to Main Content

I’m trying to create an aws_elasticache_replication_group using Redis

resource "aws_elasticache_cluster" "encryption-at-rest" {
  count           = 1
  cluster_id      = "${var.namespace}-${var.environment}-encryption-at-rest"
  engine          = "redis"
  engine_version  = var.engine_version
  node_type       = var.node_type
  num_cache_nodes = 1
  port            = var.redis_port
  #az_mode            = var.az_mode
  replication_group_id = aws_elasticache_replication_group.elasticache_replication_group.id
  security_group_ids   = [aws_security_group.redis_security_group.id]
  subnet_group_name    = aws_elasticache_subnet_group.default.name
  apply_immediately    = true
  tags = {
    Name = "${var.namespace}-${var.environment}-redis"
  }

}

resource "aws_elasticache_replication_group" "elasticache_replication_group" {

  automatic_failover_enabled    = false               //var.sharding_automatic_failover_enabled
  availability_zones            = ["ap-southeast-1a"] //data.terraform_remote_state.network.outputs.availability_zones
  replication_group_id          = "${var.namespace}-${var.environment}-encryption-at-rest"
  replication_group_description = "${var.namespace} ${var.environment} replication group"
  security_group_ids            = [aws_security_group.redis_security_group.id]
  subnet_group_name             = aws_elasticache_subnet_group.default.name
  node_type                     = var.node_type
  number_cache_clusters         = 1 //2
  parameter_group_name          = aws_elasticache_parameter_group.param_group.name
  port                          = var.redis_port
  at_rest_encryption_enabled    = true
  kms_key_id                    = data.aws_kms_alias.kms_redis.target_key_arn
  apply_immediately             = true
}

resource "aws_elasticache_parameter_group" "param_group" {
  name   = "${var.namespace}-${var.environment}-params"
  family = "redis5.0"
}

But I get the following error:

aws_security_group_rule.redis_ingress[0]: Refreshing state... [id=sgrule-3474516270]
aws_security_group_rule.redis_ingress[1]: Refreshing state... [id=sgrule-2582511137]
aws_elasticache_replication_group.elasticache_replication_group: Refreshing state... [id=cbpl-uat-encryption-at-rest]

Error: "replication_group_id": conflicts with engine_version

  on redis.tf line 1, in resource "aws_elasticache_cluster" "encryption-at-rest":
   1: resource "aws_elasticache_cluster" "encryption-at-rest" {


Releasing state lock. This may take a few moments...

2

Answers


  1. The aws_elasticache_cluster resource docs say this:

    • replication_group_id – (Optional) The ID of the replication group to
      which this cluster should belong. If this parameter is specified, the
      cluster is added to the specified replication group as a read replica;
      otherwise, the cluster is a standalone primary that is not part of any
      replication group.

    • engine – (Required unless replication_group_id is provided) Name
      of the cache engine to be used for this cache cluster. Valid values
      for this parameter are memcached or redis

    If you’re going to join it to a replication group then the engine must match the replication group’s engine type and so it shouldn’t be set on the aws_elasticache_cluster.

    Login or Signup to reply.
  2. The AWS provider overloads the aws_elasticache_cluster structure to handle multiple dissimilar configurations. The internal logic contains a set of ‘ConflictsWith’ validations which are based on the premise that certain arguments simply cannot be specified together because they represent different modes of elasticache clusters (or nodes).

    If you are specifying a replication_group_id then the value of engine_version will be managed by the corresponding aws_elasticache_replication_group.

    Therefore, the solution is simply to remove the engine_version argument from your aws_elasticache_cluster resource specification. If you so choose (or in cases where it is required), you can also add that argument to the aws_elasticache_replication_group.

    Example: Redis Cluster Mode Disabled Read Replica Instance

    // These inherit their settings from the replication group.
    resource "aws_elasticache_cluster" "replica" {
      cluster_id           = "cluster-example"
      replication_group_id = aws_elasticache_replication_group.example.id
    }
    

    In this mode, the aws_elasticache_cluster structure requires very few arguments.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search