cloudposse / terraform-aws-elasticache-redis

Terraform module to provision an ElastiCache Redis Cluster
https://cloudposse.com/accelerate
Apache License 2.0
143 stars 247 forks source link

name parameter throws error #31

Closed veilig2000 closed 5 years ago

veilig2000 commented 5 years ago

for some reason when I include the name parameter in my module config - I get an error thrown. When I remove or comment out the parameter, the error goes away and everything works as expected. I've tried to include the replication_group_id variable - but the same error is thrown as well. I'm using terragrunt and have a simple wrapper around your module. I'm not sure why it would work when the variable is missing but fail when its present?

terraform.tfvars

# ------------------------
# TERRAGRUNT CONFIGURATION
# ------------------------

terragrunt = {
  terraform {
    source = "git::git@github.com:myrepo/terraform-modules.git//aws/
database/elasticache/redis?ref=v1.4.0"
  }

# Include all settings from the root terraform.tfvars file
  include {
    path = "${find_in_parent_folders()}"
  }
}

# -------------------------------------------------------
# MODULE PARAMETERS
# These are the variables we have to pass in to use the
# module specifieid in the terragrunt configuration above
# -------------------------------------------------------

aws_region  = "us-east-1"
environment = "production"
application = "streaming"

automatic_failover = "true"

vpc_remote_state_key = "account-production/us-east-1/prod/vpc/connection/terraform.tfstate"

cluster_size = "2"

route53_hosted_zone_id = "my-zone-id"
availability_zones = ["us-east-1a", "us-east-1b"]

namespace = "foo"
name      = "app-cache"

security_groups = [
  "sg-0123456790abc"
]

variables.tf

...
  variable "name" {
    description = "Elasticache name"
    default     = "redis"
  }

  variable "namespace" {
    description = "Elasticache namespace"
    default     = "global"
  }
...

main.tf

terraform {
  backend "s3" {}
}

provider "aws" {
  version = "~> 1.52.0"
  region  = "${var.aws_region}"
  profile = "${var.aws_profile}"
}

data "terraform_remote_state" "vpc" {
  backend = "s3"

  config {
    bucket  = "${var.tfstate_global_bucket}"
    key     = "${var.vpc_remote_state_key}"
    region  = "${var.tfstate_global_bucket_region}"
    profile = "${var.aws_profile}"
  }
}

locals {
  common_tags = "${map(
    "Terraform", "true",
    "Environment", var.environment,
    "Application", var.application
  )}"
  expanded_common_tags = "${merge(local.common_tags, var.additional_tags)}"
}

// Generate a random string for auth token, no special chars
resource "random_string" "auth_token" {
  length = 64
  special = false
}

module "elasticache-redis" {
  source  = "cloudposse/elasticache-redis/aws"
  version = "0.8.1"

  namespace       = "${var.namespace}"
  name            = "${var.name}"
  stage           = "${var.environment}"
  zone_id         = "${var.route53_hosted_zone_id}"
  security_groups = ["${var.security_groups}"]

  auth_token                   = "${random_string.auth_token.result}"
  vpc_id                       = "${data.terraform_remote_state.vpc.vpc_id}"
  subnets                      = "${data.terraform_remote_state.vpc.elasticache_subnets}"
  maintenance_window           = "${var.maintenance_window}"
  cluster_size                 = "${var.cluster_size}"
  instance_type                = "${var.instance_type}"
  engine_version               = "${var.engine_version}"
  alarm_cpu_threshold_percent  = "${var.alarm_cpu_threshold_percent}"
  alarm_memory_threshold_bytes = "${var.alarm_memory_threshold_bytes}"
  apply_immediately            = "${var.apply_immediately}"
  availability_zones           = "${var.availability_zones}"

  transit_encryption_enabled  = "${var.transit_encryption_enabled}"

  tags = "${local.expanded_common_tags}"

  automatic_failover = "${var.automatic_failover}"
}

ERROR Error: module.elasticache-redis.aws_elasticache_replication_group.default: "replication_group_id" must contain from 1 to 20 alphanumeric characters or hyphens

veilig2000 commented 5 years ago

Was not paying attention and realized the length of my id was above 20 chars.