gpt4 book ai didi

azure - 如何使用多个keyvault并使用循环?地形

转载 作者:行者123 更新时间:2023-12-03 05:27:56 26 4
gpt4 key购买 nike

我有 5 个 keyvaults,有 5 个 secret ,问题是我不希望我的 terraform 文件有 10 个这样的数据 block :

data "azurerm_key_vault" "kv1" {
name = "mykeyvault"
resource_group_name = "myrg"
}

data "azurerm_key_vault_secret" "kv1" {
name = var.secret_name
key_vault_id = var..key_vault_id
}
data "azurerm_key_vault" "kv2" {
name = "mykeyvault"
resource_group_name = "myrg"
}

data "azurerm_key_vault_secret" "kv2" {
name = var.secret_name
key_vault_id = var..key_vault_id
}
data "azurerm_key_vault" "kv3" {
name = "mykeyvault"
resource_group_name = "myrg"
}

data "azurerm_key_vault_secret" "kv3" {
name = var.secret_name
key_vault_id = var..key_vault_id
}
data "azurerm_key_vault" "kv4" {
name = "mykeyvault"
resource_group_name = "myrg"
}

data "azurerm_key_vault_secret" "kv4" {
name = var.secret_name
key_vault_id = var..key_vault_id
}
data "azurerm_key_vault" "kv5" {
name = "mykeyvault"
resource_group_name = "myrg"
}

data "azurerm_key_vault_secret" "kv5" {
name = var.secret_name
key_vault_id = var..key_vault_id
}
.....

是否有其他方法可以在一个 block 中使用它来分配 5 个 keyvaults 数据 block 和 5 个 secret 数据 block ?

谢谢

最佳答案

您可以使用计数功能。应该是这样的:

variable key_vaults {
type = list(string)
default = ["kv1","kv2","kv3","kv4","kv5"]
}

data "azurerm_key_vault" "kv" {
count = length(var.key_vaults)
name = var.key_vaults[count.index]
resource_group_name = "myrg"
}

data "azurerm_key_vault_secret" "kvs" {
count = length(var.key_vaults)
name = "secret"
key_vault_id = data.azurerm_key_vault.kv[count.index].id
}

关于azure - 如何使用多个keyvault并使用循环?地形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67387653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com