【发布时间】:2022-01-16 01:52:13
【问题描述】:
我正在尝试在 Vault 中自动创建路径和策略。 你知道我该怎么做吗? 在 terraform 中声明的变量不会在 .hcl 文件中重新整理。 我试图将我的文件 client-ro-policy.hcl 重命名为 client-ro-policy.tf 但我有同样的问题 在扩展名为 .tf 的文件中识别变量
谢谢
main.tf
# Use Vault provider
provider "vault" {
# It is strongly recommended to configure this provider through the
# environment variables:
# - VAULT_ADDR
# - VAULT_TOKEN
# - VAULT_CACERT
# - VAULT_CAPATH
# - etc.
}
acl-ro-policy.hcl
path "${var.client[0]}/k8s/preprod/*" {
capabilities = ["read"]
}
policies.tf
#---------------------
# Create policies
#---------------------
# Create 'client' policy
resource "vault_policy" "ro-client" {
name = "${var.client[0]}_k8s_preprod_ro"
policy = file("./hcl-ro-policy.tf")
}
变量.tf
variable "client" {
type = list(string)
}
变量.tfvars
client = ["titi", "toto","itutu"]
保险库中的结果:
【问题讨论】:
-
我会尝试使用 json 格式,但也许我应该考虑 Ansible ?