8

我正在尝试使用 Terraform 在 Elasticache 上启动 Redis 实例并遇到以下错误。

* module.main.module.redis.aws_elasticache_security_group.redis: 1 error(s) occurred:

* aws_elasticache_security_group.redis: Error creating CacheSecurityGroup: InvalidParameterValue: Use of cache security groups is not permitted in this API version for your account.

我在 GH 问题中发现的任何内容都没有帮助。这是我的 Terraform 的样子(我已确认变量已正确传递):

resource "aws_elasticache_subnet_group" "redis" {
  name       = "vpc-public-subnet"
  description = "subnet where redis will live"
  subnet_ids = ["${var.subnet}"]
}

resource "aws_elasticache_security_group" "redis" {
  name                 = "redis-security-group"
  security_group_names = ["${var.redis_sec_group}"]
}

resource "aws_elasticache_replication_group" "redis" {
  automatic_failover_enabled    = true
  availability_zones            = ["us-east-2a"]
  replication_group_id          = "${var.environment}-myapp-rep-group-1"
  replication_group_description = "redis rep group - ${var.environment} env"
  node_type                     = "cache.t2.micro"
  number_cache_clusters         = 2
  parameter_group_name          = "default.redis3.2"
  port                          = 6379
  at_rest_encryption_enabled    = true
  transit_encryption_enabled    = true

  subnet_group_name = "${aws_elasticache_subnet_group.redis.name}"
  security_group_ids = ["${aws_elasticache_security_group.redis.id}"]

  lifecycle {
    ignore_changes = ["number_cache_clusters"]
  }
}

resource "aws_elasticache_cluster" "redis" {
  cluster_id           = "${var.environment}-myapp"
  count                = 1
  replication_group_id = "${aws_elasticache_replication_group.redis.id}"
}

我认为问题可能出在我的 IAM 用户上,所以我添加了AmazonElastiCacheFullAccess策略,但它仍然说不允许这样做。在阅读 AWS 文档上关于API_CreateCacheSecurityGroup的帖子并确认这三个策略包含在AmazonElastiCacheFullAccess.

这些资源周围似乎有一些错误的行为

https://github.com/hashicorp/terraform/issues/10127


我的解决方案

抱歉,请在此忍耐一下。发布这个并完全写出来确实帮助我处理我的想法。我发现这aws_elasticache_security_group是不必要的,只是决定["${var.redis_sec_group}"]直接传递给security_group_idsfor aws_elasticache_replication_group

对于之前已经处理过这个问题的人来说,这似乎很明显,现在对我来说也是如此。但是进入这个全新的它不是。所以这不是我遇到的那个权限问题的解决方案。但是,就像很多事情一样,我退后一步,质疑我是否真的需要它,答案是否定的。

4

1 回答 1

8

您似乎已经意识到,aws_elasticache_security_group当您不使用 VPC 时,它仅适用于 EC2 经典账户。最近创建的账户不允许在 VPC 之外创建网络级资源(实例、负载均衡器、RDS 实例、Elasticache 实例等)。

在资源的Terraform 文档aws_elasticache_security_group中提到了这一点:

注意:ElastiCache 安全组仅在使用VPC外部的 ElastiCache 集群时使用。如果您使用的是 VPC,请参阅 ElastiCache 子网组资源。

Elasticache 安全组的AWS 文档更详细地介绍:

重要的

Amazon ElastiCache 安全组仅适用于不在 Amazon Virtual Private Cloud 环境 (VPC) 中运行的集群。如果您在 Amazon Virtual Private Cloud 中运行,安全组在控制台导航窗格中不可用。

如果您在 Amazon VPC 中运行 ElastiCache 节点,您可以使用不同于 ElastiCache 安全组的 Amazon VPC 安全组来控制对集群的访问。有关在 Amazon VPC 中使用 ElastiCache 的更多信息,请参阅 Amazon VPC 和 ElastiCache 安全性

于 2018-05-11T08:20:46.227 回答