【问题标题】:The parameter CacheSubnetGroupName must be provided and must not be blank参数 CacheSubnetGroupName 必须提供且不能为空
【发布时间】:2021-02-19 15:22:43
【问题描述】:

我使用模块 https://github.com/cloudposse/terraform-aws-elasticache-redis 来配置 elasticache redis。以下是我运行 terraform apply 时的错误。我不知道这些错误。

Terraform 版本:v0.13.5

module.redis.aws_elasticache_parameter_group.default[0]:正在创建...

module.redis.aws_elasticache_subnet_group.default[0]:正在创建...

错误:创建 CacheSubnetGroup 时出错:InvalidParameterValue:必须提供参数 CacheSubnetGroupName 并且不能为空。 状态码:400,请求ID:a1ab57b1-fa23-491c-aa7b-a2d3804014c9

错误:创建缓存参数组时出错:InvalidParameterValue:必须提供参数 CacheParameterGroupName 并且不能为空。 状态码:400,请求ID:9abc80b6-bd3b-46fd-8b9e-9bf14d1913eb

redis.tf:

module "redis" {
  source                     = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=tags/0.25.0"
  availability_zones               = var.azs
  vpc_id                           = module.vpc.vpc_id
  allowed_security_groups          = [data.aws_security_group.default.id]
  subnets                          = module.vpc.private_subnets
  cluster_size                     = var.redis_cluster_size #number_cache_clusters
  instance_type                    = var.redis_instance_type
  apply_immediately                = true
  automatic_failover_enabled       = false
  engine_version                   = var.engine_version
  family                           = var.family
  replication_group_id             = var.replication_group_id
  elasticache_subnet_group_name    = var.elasticache_subnet_group_name
  #enabled                          = true
  enabled                          = var.enabled

  #at-rest encryption is to increase data security by encrypting on-disk data.
  at_rest_encryption_enabled       = var.at_rest_encryption_enabled

  #in-transit encryption protects data when it is moving from one location to another.
  transit_encryption_enabled       = var.transit_encryption_enabled

  cloudwatch_metric_alarms_enabled = var.cloudwatch_metric_alarms_enabled

  parameter = [
    {
      #Keyspace notifications send events for every operation affecting the Redis data space.
      name  = "notify-keyspace-events"
      value = "lK"
    }
  ]
  context = module.this.context
}

context.tf:
module "this" {
  source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.2"

  enabled             = var.enabled
  namespace           = var.namespace
  environment         = var.environment
  stage               = var.stage
  name                = var.name
  delimiter           = var.delimiter
  attributes          = var.attributes
  tags                = var.tags
  additional_tag_map  = var.additional_tag_map
  label_order         = var.label_order
  regex_replace_chars = var.regex_replace_chars
  id_length_limit     = var.id_length_limit

  context = var.context
}

variable "context" {
  type = object({
    enabled             = bool
    namespace           = string
    environment         = string
    stage               = string
    name                = string
    delimiter           = string
    attributes          = list(string)
    tags                = map(string)
    additional_tag_map  = map(string)
    regex_replace_chars = string
    label_order         = list(string)
    id_length_limit     = number
  })
  default = {
    enabled             = true
    namespace           = null
    environment         = null
    stage               = null
    name                = null
    delimiter           = null
    attributes          = []
    tags                = {}
    additional_tag_map  = {}
    regex_replace_chars = null
    label_order         = []
    id_length_limit     = null
  }
  description = <<-EOT
    Single object for setting entire context at once.
    See description of individual variables for details.
    Leave string and numeric variables as `null` to use default value.
    Individual variable settings (non-null) override settings in context object,
    except for attributes, tags, and additional_tag_map, which are merged.
  EOT
}

variable "enabled" {
  type        = bool
  default     = true
  description = "Set to false to prevent the module from creating any resources"
}

variable "namespace" {
  type        = string
  default     = null
  description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
}

variable "environment" {
  type        = string
  default     = null
  description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'"
}

variable "stage" {
  type        = string
  default     = null
  description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'"
}

variable "name" {
  type        = string
  default     = null
  description = "Solution name, e.g. 'app' or 'jenkins'"
}

variable "delimiter" {
  type        = string
  default     = null
  description = <<-EOT
    Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
    Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
  EOT
}

variable "attributes" {
  type        = list(string)
  default     = []
  description = "Additional attributes (e.g. `1`)"
}

variable "tags" {
  type        = map(string)
  default     = {}
  description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`"
}

variable "additional_tag_map" {
  type        = map(string)
  default     = {}
  description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`."
}

variable "label_order" {
  type        = list(string)
  default     = null
  description = <<-EOT
    The naming order of the id output and Name tag.
    Defaults to ["namespace", "environment", "stage", "name", "attributes"].
    You can omit any of the 5 elements, but at least one must be present.
  EOT
}

variable "regex_replace_chars" {
  type        = string
  default     = null
  description = <<-EOT
    Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
    If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
  EOT
}

variable "id_length_limit" {
  type        = number
  default     = null
  description = <<-EOT
    Limit `id` to this many characters.
    Set to `0` for unlimited length.
    Set to `null` for default, which is `0`.
    Does not affect `id_full`.
  EOT
}

【问题讨论】:

    标签: amazon-web-services redis terraform terraform-provider-aws amazon-elasticache


    【解决方案1】:

    如果您希望模块为您创建资源,包括子网组,请打开 context.tf 并将 variable "enabled" 设置为 true。

    否则,您必须自己创建所有 per-requsite 资源,其中包括 elasticache_subnet_group_name。

    【讨论】:

    • 我在 context.tf 中将 enabled 设置为 true。但是,我仍然遇到同样的错误。添加 elasticache_subnet_group_name 解决了这个问题。但是,我得到了另一个错误,“错误:创建缓存参数组时出错:无效参数值:必须提供参数 CacheParameterGroupName 并且不能为空”。在github.com/cloudposse/terraform-aws-elasticache-redis#inputs,没有找到输入参数匹配CacheParameterGroupName。
    • @MelissaJenner 定义为here。但是您必须启用variable "enabled" 才能使其工作。请仔细检查您的 context.tf。如果enabled 为真,则组名称为only creaded。
    • 感谢您花时间帮助我。我更新了源代码。请看上面的代码。它有 context.tf。我设置启用=真。我还设置了 enabled = var.enabled。 (启用的默认值 = true)。请告诉我错误是什么。谢谢。
    • @MelissaJenner 我认为必须退后一步。 github有full example。这个例子对你有用吗?我运行了这个示例,我可以确认它创建了 redis(之后它对我来说失败了,因为我没有对 route53 的完全权限)。
    • 我发现了问题。 context.tf 中 namespace/environment/stage/name 的默认值为 null。这导致了问题。设置这些值解决了问题。
    【解决方案2】:

    我发现了问题。 context.tf 中 namespace/environment/stage/name 的默认值为 null。这导致了问题。设置这些值可以解决问题。

    【讨论】:

      【解决方案3】:

      您需要提供模块input,可以在link you provided上找到。

      例如:

      错误:创建 CacheSubnetGroup 时出错:InvalidParameterValue:必须提供参数 CacheSubnetGroupName 并且不能为空。状态码:400,请求ID:a1ab57b1-fa23-491c-aa7b-a2d3804014c9

      这种情况下需要设置elasticache_subnet_group_name,以此类推:

      【讨论】:

      • 谢谢。添加 elasticache_subnet_group_name 解决了这个问题。但是,我得到了另一个错误,“错误:创建缓存参数组时出错:无效参数值:必须提供参数 CacheParameterGroupName 并且不能为空”。从您提供的链接中,我没有找到此错误的正确输入。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 2017-10-29
      • 2018-12-21
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多