如何创建带有多个标签的单个dlm策略



尝试创建DLM(数据生命周期管理(策略,以每12小时拍摄一次ebs快照。AWS UI允许指定多个目标标签,将多个实例组合到一个策略中。

尝试使用地形创建相同的地形,https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dlm_lifecycle_policy#target_tags

target_tags似乎不接受多个地图值-

target_tags = {
Name = "g1n1",
Name = "g1n2"
}

Terraform计划从列表中获取最后一个地图值-

# aws_dlm_lifecycle_policy.example has changed
~ resource "aws_dlm_lifecycle_policy" "example" {
id                 = "policy-0719fc4b498671592"
tags               = {}
# (5 unchanged attributes hidden)
~ policy_details {
~ target_tags    = {
~ "Name" = "g1n1" -> "g1n2"
}
# (1 unchanged attribute hidden)
# (1 unchanged block hidden)
}
}

为了克服这个问题,我为每个实例创建了2个策略,但有没有办法为多个实例创建一个策略?

resource "aws_dlm_lifecycle_policy" "DLM_g1n1" {
description = "DLM_g1n1"
execution_role_arn = "AWSDataLifecycleManagerDefaultRole"
policy_details {
resource_types = ["INSTANCE"]
schedule {
name = "snapshot-every12hours"
create_rule {
interval      = 12
interval_unit = "HOURS"
times         = ["04:30"]
}         
retain_rule { count = 28 }
copy_tags = false
}
target_tags = {
Name = "g1n1"
}
}
}
resource "aws_dlm_lifecycle_policy" "DLM_g1n2" {
description = "DLM_g1n2"
execution_role_arn = "AWSDataLifecycleManagerDefaultRole"
policy_details {
resource_types = ["INSTANCE"]
schedule {
name = "cedcas-snapshot-every12hours"
create_rule {
interval      = 12
interval_unit = "HOURS"
times         = ["04:30"]
}         
retain_rule { count = 28 }
copy_tags = false
}
target_tags = {
Name = "g1n2"
}
}
}

在TF中似乎不可能。但是,您可以使用countfor_each:而不是创建完全独立的aws_dlm_lifecycle_policy

variable "tags" {
default = [{Name = "g1n1"}, {Name = "g1n2"}]
}
resource "aws_dlm_lifecycle_policy" "DLM_g1" {
count = length(var.tags)
description = "DLM_g1n${count.index}"
execution_role_arn = "AWSDataLifecycleManagerDefaultRole"
policy_details {
resource_types = ["INSTANCE"]
schedule {
name = "snapshot-every12hours"
create_rule {
interval      = 12
interval_unit = "HOURS"
times         = ["04:30"]
}         
retain_rule { count = 28 }
copy_tags = false
}
target_tags = var.tags[count.index]
}
}

相关内容

  • 没有找到相关文章