terraform-aws-modules / terraform-aws-elasticache

Terraform module to create AWS ElastiCache resources πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/elasticache/aws
Apache License 2.0
17 stars 28 forks source link

Error provisioning multi-az/read-replica redis instance #2

Closed fideloper closed 8 months ago

fideloper commented 8 months ago

Description

I'm attempting to create a redis instance with a read replica/multi-az failover. It doesn't really make sense to me:

Error: Invalid combination of arguments

"engine": only one of `engine,replication_group_id` can be specified, but `engine,replication_group_id` were specified.
image

I can see that engine is not conditionally applied, it's always set to either redis or memcached, so I can't unset it.

If I exclude replication_group_id, I receive this error:

Error: Missing required argument

The argument "replication_group_id" is required, but no definition was found.
image

This has put me in a weird state where I cannot even destroy the cluster parts that were created (I get the same error "engine": only one ofengine,replication_group_idcan be specified, butengine,replication_group_idwere specified.).

I'm having a hard time parsing out if this is an issue of my understanding, a quirk of this module, or if AWS's API is weird here.

Versions

1.0.0

Terraform v1.7.5
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.42.0
+ provider registry.terraform.io/hashicorp/random v3.6.0

Reproduction Code [Required]

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  profile = "default"
  region  = "us-east-2"
}

##
# VPC SETUP
###

data "aws_availability_zones" "available" {}

locals {
  azs      = slice(data.aws_availability_zones.available.names, 0, 3)
}

module "customer-ingress-vpc" {
  source = "terraform-aws-modules/vpc/aws"
  version = "5.7.0"

  name = "dev-test-customer-vpc"
  cidr = "10.0.0.0/16"

  azs              = local.azs
  private_subnets  = [for k, v in local.azs : cidrsubnet(var.ipv4_cider, 8, k)]
  public_subnets   = [for k, v in local.azs : cidrsubnet(var.ipv4_cider, 8, k + 4)]
  database_subnets = [for k, v in local.azs : cidrsubnet(var.ipv4_cider, 8, k + 8)]

  # One NAT gateway per AZ (instead of
  # default of per subnet)
  enable_nat_gateway = true
  single_nat_gateway = false
  one_nat_gateway_per_az = true

  enable_ipv6                                   = true
  public_subnet_assign_ipv6_address_on_creation = true

  public_subnet_ipv6_prefixes   = [0, 1, 2]
  private_subnet_ipv6_prefixes  = [3, 4, 5]
  database_subnet_ipv6_prefixes = [6, 7, 8]
}

##
# ELASTICACHE SETUP
###
module "routing-redis" {
  source  = "terraform-aws-modules/elasticache/aws"
  version = "1.0.0"

  cluster_id                 = "test-dev-routing-redis"
  create_cluster             = true
  create_replication_group   = true
  automatic_failover_enabled = true
  multi_az_enabled           = true
  num_cache_clusters         = 2
  replication_group_id       = "test-dev-routing-rplgrp"

  engine_version = "7.1"
  node_type      = "cache.t4g.medium"

  maintenance_window = "sun:05:00-sun:09:00"
  apply_immediately  = true

  # Security group
  vpc_id = module.customer-ingress-vpc.vpc_id
  security_group_rules = {
    ingress_vpc_ipv4 = {
      # Default type is `ingress`
      # Default port is based on the default engine port
      description = "VPC ipv4 private traffic"
      cidr_ipv4   = module.customer-ingress-vpc.vpc_cidr_block
    }
    ingress_vpc_ipv6 = {
      # Default type is `ingress`
      # Default port is based on the default engine port
      description = "VPC ipv6 private traffic"
      cidr_ipv6   = module.customer-ingress-vpc.vpc_ipv6_cidr_block
    }
  }

  # Subnet Group
  subnet_ids = module.customer-ingress-vpc.private_subnets

  # Parameter Group
  create_parameter_group = true
  parameter_group_family = "redis7"
  parameters = [
    {
      name  = "latency-tracking"
      value = "yes"
    }
  ]
}
fideloper commented 8 months ago

Hacking up the local copy of this module to comment out engine = var.engine seems to make it work:

(I'm happy for this to by my own misunderstanding tho :P )

image
fzwart commented 8 months ago

I experienced the same. While reading the documentation I noticed that in the examples they only create a replication_group.

Based on your configuration, this module creates both a aws_elasticache_cluster and aws_elasticache_replication_group resource while the documentation suggests you only need aws_elasticache_replication_group. Even though it's counter-intuitive this made me try to set 'create_cluster = false'.

For me this resulted in the desired cluster where you can control the number of replicas using num_cache_clusters.

fideloper commented 8 months ago

Thanks! That's likely it, i'll try it out

github-actions[bot] commented 7 months 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.