我想要做的是將密鑰名稱串列提供給一個模塊,該模塊將用于在機密管理器中生成許多具有不同隨機密碼的機密。
我嘗試了很多不同的東西,但到目前為止都失敗了。
這是我目前所擁有的:
module "secrets-manager-1" {
source = "lgallard/secrets-manager/aws"
for_each = var.list
secrets = {
"${each.value}" = {
description = each.value
recovery_window_in_days = 7
secret_string = random_password.special_password.result
}
}
tags = var.standard_tags
}
resource "random_password" "special_password" {
count = 2
length = 16
special = true
}
variable "list" {
type = list(string)
default = [
"secret_key_1",
"secret_key_2"
]
}
錯誤:
│ Error: Invalid for_each argument
│
│ on ..\..\modules\jitsi\jitsi_secrets.tf line 54, in module "secrets-manager-1":
│ 54: for_each = var.list
│ ├────────────────
│ │ var.list is list of string with 2 elements
│
│ The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type list of string.
?
Releasing state lock. This may take a few moments...
uj5u.com熱心網友回復:
不幸的是,您提供的甚至不是有效的 Terraform 代碼。我相信您希望實作以下目標:
// Create N random password. In this case N = 2
resource "random_password" "special_password" {
count = 2
length = 16
special = true
}
// Import a third party module
module "secrets-manager-1" {
source = "lgallard/secrets-manager/aws"
// Loop through the random_passowrd resouces and create the secrets
secrets = {
for index, pwd in random_password.special_password.*.result : "${element(var.list, index)}" => {
secret_string: "${pwd}",
recovery_window_in_days = 7
}
}
}
您可能想要查看splat 運算式,以便能夠迭代多個資源。這用于模塊中的for運算式secrets-manager-1。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/390846.html
標籤:亚马逊网络服务 for循环 地形 aws-secrets-manager
上一篇:函式包含無限回圈,看起來一切正常
