一千萬個為什麽

搜索

如何在不丟失所有狀態的情況下將分片添加到由Terraform管理的Redis群集中?



我已經使用Terraform建立了一個Redis集群。設置如下所示:

resource "aws_elasticache_replication_group" "instance" {
  replication_group_id = "test"

  node_type                     = "cache.t2.micro"
  port                          = 6379
  parameter_group_name          = "default.redis3.2.cluster.on"
  subnet_group_name             = "${aws_elasticache_subnet_group.instance.name}"
  security_group_ids            = ["${aws_security_group.instance.id}"]

  cluster_mode {
    replicas_per_node_group = 0
    num_node_groups         = "${var.cluster_size}"
  }

  automatic_failover_enabled = true
  apply_immediately = true
}

當我將 var.cluster_size 從2更改為3時,我原本期望Terraform將執行更新。但事實並非如此:

-/+ module.groupsign_redis.aws_elasticache_replication_group.instance (new resource required)
  id:                                              "test" =>  (forces new resource)
  apply_immediately:                               "true" => "true"
  at_rest_encryption_enabled:                      "false" => "false"
  auto_minor_version_upgrade:                      "true" => "true"
  automatic_failover_enabled:                      "true" => "true"
  cluster_mode.#:                                  "1" => "1"
  cluster_mode.3760271746.num_node_groups:         "" => "3" (forces new resource)
  cluster_mode.3760271746.replicas_per_node_group: "" => "0" (forces new resource)
  cluster_mode.3784625311.num_node_groups:         "2" => "0" (forces new resource)
  cluster_mode.3784625311.replicas_per_node_group: "0" => "0"

這也在文檔中得到了確認:

num_node_groups - (必需)指定此Redis復制組的節點組(分片)數。更改此數字將強制使用新資源。

目前,我只看到使用Terraform進行初始部署的選項,然後使用AWS UI添加或刪除分片,AWS UI將在適當的位置執行更新。

您是否知道使用Terraform執行就地更新的方法? 或者是在沒有丟失數據庫狀態的情況下添加分片,而目前Terraform是不可能的?

也許可以手動添加/刪除分片(通過AWS UI),然後將新狀態導入Terraform。我試圖運行 terraform refresh ,但它確實成功完全同步了狀態。 terraform apply 仍然認為必須更改資源。

Update: What does work though is to simply ignore the change. Updating other Terraform resources still works. However, it is a bit confusing as the cluster size that is specified in the Terraform file does not match the actual size that is deployed. You then loose the ability to look at the Terraform setup and see exactly what is currently deployed.

目前,這是我最好的選擇。

轉載註明原文: 如何在不丟失所有狀態的情況下將分片添加到由Terraform管理的Redis群集中?

一共有 1 個回答:

您可以創建 aws_elasticache_replication_group 資源並使用數據源 aws_elasticache_cluster 用於檢索實際的節點數量。這樣你就不應該寫 ignore_changes