【发布时间】:2021-11-13 19:48:15
【问题描述】:
我正在尝试预置 AWS Elasitcache 全局复制组。这分两个阶段进行。在第一阶段,主要区域 aws_elasticache_replication_group 和全局 aws_elasticache_global_replication_group 被配置。在第二阶段,次要区域 aws_elasticache_replication_group 使用 global_replication_group_id 属性配置并附加到全局数据存储。次要区域已配置并附加到全局复制组。但是,默认情况下,第二个集群将自动故障转移设置为 true。默认情况下,根据文档,这应该是错误的。 Terraform 计划显示自动故障转移为 false,但是当运行 terraform apply 时,自动故障转移设置为 true。所以现在如果我重新运行 terraform apply,辅助集群会尝试将自动故障转移更改为 false,这是正确的默认值,这会导致 terraform apply 失败,因为无法修改。
number_of _cache_clusters 在主要和次要中都设置为 2。我尝试只在二级集群中使用一个集群,结果相同。
module.elasticache_redis_global.aws_elasticache_replication_group.redis_cache_cluster_sec: 正在修改... [id=sp360commercial-pdx-dev-test4-redis]
231Error:更新 ElastiCache 复制组时出错 (sp360commercial-pdx-dev-test4-redis):请求修改时出错: 无效参数值:集群 [sp360commercial-pdx-dev-test4-redis] 是全球集群的一部分 [ldgnf-sp360commercial-iad-dev-test4-global]。请求被拒绝。
232 状态码:400,请求 id:b15e578b-7906-412f-aef8-1d038c9fbb81
233 在…/…/…/modules/aws/elasticache-global/redis.tf 第 1 行,在 资源“aws_elasticache_replication_group” “redis_cache_cluster_sec”:
234 1:资源“aws_elasticache_replication_group” “redis_cache_cluster_sec” {
236清理基于文件的变量
如果我在辅助集群配置中将自动故障转移显式设置为 true,我会收到一条错误消息,指出自动故障转移属性与全局复制组 ID 属性冲突
错误:ConflictsWith
173 在…/…/…/modules/aws/elasticache-global/redis.tf 第 4 行,在 资源“aws_elasticache_replication_group” “redis_cache_cluster_sec”:
174 4: global_replication_group_id = “${local.globalstore_prefix}-global”
175“global_replication_group_id”:与 automatic_failover_enabled
176Terraform 应用被跳过,因为 DISRUPTERRA_DRY_RUN 设置为 真的。
Terraform 版本 v0.12.24 AWS 提供商版本 3.37.0
我也尝试使用 Terraform 版本 v0.12.31 和 AWS 提供商 3.58,但他的问题存在。 我使用 config.yml 文件作为此代码的输入。以下是文件内容。这将在被 terraform 资源使用之前由 shell 脚本转换为 json 文件
storage:
elasticache:
instances:
test4:
nodeType: cache.r5.large
applyImmediately: true
numShards: 1
numReplicas: 2
atRestEncryption: true
transitEncryption: true
multiAz: true
globalDatastore:
primaryRegion: us-east-1
secondaryRegion: us-west-2
主集群和全局集群
resource "aws_elasticache_global_replication_group" "redis_global_datastore" {
count = 1
global_replication_group_id_suffix = "${local.cluster_prefix}-global"
primary_replication_group_id = aws_elasticache_replication_group.redis_cache_cluster.id
}
resource "aws_elasticache_replication_group" "redis_cache_cluster" {
replication_group_id = "${local.cluster_prefix}-redis"
replication_group_description = "Provisioned using Terraform"
number_cache_clusters = 2
node_type = lookup(local.config, "nodeType", "cache.t2.micro")
port = 6379
engine_version = lookup(local.config, "engineVersion", "5.0.6")
parameter_group_name = contains(keys(local.config), "parameters") ? aws_elasticache_parameter_group.parameter_group[0].name : local.default_parameter_group
subnet_group_name = aws_elasticache_subnet_group.subnet_group.name
security_group_ids = [aws_security_group.redis_sg.id]
maintenance_window = lookup(local.config, "maintenanceWindow", "sun:02:00-sun:04:00")
automatic_failover_enabled = lookup(local.config, "numReplicas", 1) > 1 || lookup(local.config, "numShards", 1) > 1 ? true : false
apply_immediately = lookup(local.config, "applyImmediately", true)
at_rest_encryption_enabled = lookup(local.config, "atRestEncryption", false)
transit_encryption_enabled = lookup(local.config, "transitEncryption", false)
auth_token = var.auth_token
multi_az_enabled = lookup(local.config, "multiAz", false)
dynamic "cluster_mode" {
for_each = lookup(local.config, "numShards", 1) > 1 ? [true] : []
content {
replicas_per_node_group = lookup(local.config, "numReplicas", 1)
num_node_groups = lookup(local.config, "numShards", 2)
}
}
lifecycle {
prevent_destroy = true
ignore_changes = [parameter_group_name]
}
}
二级集群
resource "aws_elasticache_replication_group" "redis_cache_cluster_sec" {
replication_group_id = "${local.cluster_prefix}-redis"
replication_group_description = "Provisioned using Terraform"
global_replication_group_id = "${local.globalstore_prefix}-global"
auth_token = var.auth_token
subnet_group_name = aws_elasticache_subnet_group.subnet_group.name
security_group_ids = [aws_security_group.redis_sg.id]
}
【问题讨论】:
-
你能分享产生错误的代码吗?
-
@Marcin 代码已添加。代码在第一次运行时运行良好。但是,如果我在不更改任何内容的情况下重新运行它,elasticache 会尝试将自动故障从 true 更改为 false(默认值)并失败
标签: terraform terraform-provider-aws amazon-elasticache terraform0.12+