如何从 terraform 中的本地地图中删除键值对?
how to remove a key value pair from local map in terraform?
我有一个如下所示的本地值,我想从中删除 Mongo-S 对,因为它没有 dbv 值
merged_mongo_locals = {
MongoA-0 = {
az = "ap-south-1a"
dbv = 50
service_name = "MongoA"
}
MongoC-0 = {
az = "ap-south-1a"
dbv = 50
service_name = "MongoC"
}
MongoC-1 = {
az = "ap-south-1b"
dbv = 50
service_name = "MongoC"
}
MongoD-0 = {
az = "ap-south-1a"
dbv = 100
service_name = "MongoD"
}
MongoD-1 = {
az = "ap-south-1b"
dbv = 100
service_name = "MongoD"
}
MongoD-2 = {
az = "ap-south-1c"
dbv = 100
service_name = "MongoD"
}
MongoM-0 = {
az = "ap-south-1a"
dbv = 50
service_name = "MongoM"
}
MongoS-0 = {
az = "ap-south-1a"
service_name = "MongoS"
}
MongoS-1 = {
az = "ap-south-1b"
service_name = "MongoS"
}
}
我正在使用以下方法删除 MongoS 密钥对
输出“Mongo-ips”{
value = {for k,v in local.merged_mongo_locals: k => v if !包含(值(v),“dbv”)}
}
但输出如下所示,它没有排除 MongoS 对,即使它没有 dbv 值
Changes to Outputs:
+ Mongo-ips = {
+ MongoA-0 = {
+ az = "ap-south-1a"
+ dbv = 50
+ service_name = "MongoA"
}
+ MongoC-0 = {
+ az = "ap-south-1a"
+ dbv = 50
+ service_name = "MongoC"
}
+ MongoC-1 = {
+ az = "ap-south-1b"
+ dbv = 50
+ service_name = "MongoC"
}
+ MongoD-0 = {
+ az = "ap-south-1a"
+ dbv = 100
+ service_name = "MongoD"
}
+ MongoD-1 = {
+ az = "ap-south-1b"
+ dbv = 100
+ service_name = "MongoD"
}
+ MongoD-2 = {
+ az = "ap-south-1c"
+ dbv = 100
+ service_name = "MongoD"
}
+ MongoM-0 = {
+ az = "ap-south-1a"
+ dbv = 50
+ service_name = "MongoM"
}
+ MongoS-0 = {
+ az = "ap-south-1a"
+ service_name = "MongoS"
}
+ MongoS-1 = {
+ az = "ap-south-1b"
+ service_name = "MongoS"
}
}
请指导我这里有什么问题
这应该对你有帮助。
output "Mongo-ips" {
value = { for k, v in local.merged_mongo_locals : k => v if contains(keys(v), "dbv") }
}
我有一个如下所示的本地值,我想从中删除 Mongo-S 对,因为它没有 dbv 值
merged_mongo_locals = {
MongoA-0 = {
az = "ap-south-1a"
dbv = 50
service_name = "MongoA"
}
MongoC-0 = {
az = "ap-south-1a"
dbv = 50
service_name = "MongoC"
}
MongoC-1 = {
az = "ap-south-1b"
dbv = 50
service_name = "MongoC"
}
MongoD-0 = {
az = "ap-south-1a"
dbv = 100
service_name = "MongoD"
}
MongoD-1 = {
az = "ap-south-1b"
dbv = 100
service_name = "MongoD"
}
MongoD-2 = {
az = "ap-south-1c"
dbv = 100
service_name = "MongoD"
}
MongoM-0 = {
az = "ap-south-1a"
dbv = 50
service_name = "MongoM"
}
MongoS-0 = {
az = "ap-south-1a"
service_name = "MongoS"
}
MongoS-1 = {
az = "ap-south-1b"
service_name = "MongoS"
}
}
我正在使用以下方法删除 MongoS 密钥对
输出“Mongo-ips”{ value = {for k,v in local.merged_mongo_locals: k => v if !包含(值(v),“dbv”)} }
但输出如下所示,它没有排除 MongoS 对,即使它没有 dbv 值
Changes to Outputs:
+ Mongo-ips = {
+ MongoA-0 = {
+ az = "ap-south-1a"
+ dbv = 50
+ service_name = "MongoA"
}
+ MongoC-0 = {
+ az = "ap-south-1a"
+ dbv = 50
+ service_name = "MongoC"
}
+ MongoC-1 = {
+ az = "ap-south-1b"
+ dbv = 50
+ service_name = "MongoC"
}
+ MongoD-0 = {
+ az = "ap-south-1a"
+ dbv = 100
+ service_name = "MongoD"
}
+ MongoD-1 = {
+ az = "ap-south-1b"
+ dbv = 100
+ service_name = "MongoD"
}
+ MongoD-2 = {
+ az = "ap-south-1c"
+ dbv = 100
+ service_name = "MongoD"
}
+ MongoM-0 = {
+ az = "ap-south-1a"
+ dbv = 50
+ service_name = "MongoM"
}
+ MongoS-0 = {
+ az = "ap-south-1a"
+ service_name = "MongoS"
}
+ MongoS-1 = {
+ az = "ap-south-1b"
+ service_name = "MongoS"
}
}
请指导我这里有什么问题
这应该对你有帮助。
output "Mongo-ips" {
value = { for k, v in local.merged_mongo_locals : k => v if contains(keys(v), "dbv") }
}