[英]How to get the data.token from Kubernetes_secret terraform resource
I am trying to access the Kubernetes_secret
data.token
attribute in terraform, but I keep on getting the error我正在尝试访问 terraform 中的Kubernetes_secret
data.token
属性,但我不断收到错误消息
Resource 'data.kubernetes_secret.misp_whitelist_secret' does not have attribute 'data.token' for variable 'data.kubernetes_secret.misp_whitelist_secret.data.token'
Whats the way to resolve this issue?解决这个问题的方法是什么?
resource "kubernetes_service_account" "misp_whitelist_sa" {
metadata {
name = "misp-whitelist-sa"
}
}
data "kubernetes_secret" "misp_whitelist_secret" {
metadata {
name = "${kubernetes_service_account.misp_whitelist_sa.default_secret_name}"
namespace = "${kubernetes_service_account.misp_whitelist_sa.metadata.0.namespace}"
}
depends_on = [
"kubernetes_service_account.misp_whitelist_sa",
]
}
And I'm trying to access the data.token inside the terraform google_cloud_function resource我正在尝试访问 terraform google_cloud_function 资源中的 data.token
resource "google_cloudfunctions_function" "misp_whitelist_function" {
name = "${var.cluster}-misp-whitelist"
....<additional data> .....
environment_variables = {
CLUSTER = "${var.cluster}"
PROJECT = "${var.project}"
AUTH = "${data.kubernetes_secret.misp_whitelist_secret.data.token}"
}
}
访问数据密钥的正确方法是:
AUTH = "${data.kubernetes_secret.misp_whitelist_secret.data["token"]}"
Ok banged my head against a wall here for a really long time.好吧,我的头撞在墙上很长时间了。 The other answer is correct, but skips a crucial step.另一个答案是正确的,但跳过了关键步骤。
You need to make sure that the secret declares the correct type (and also maybe specify the annotation?)您需要确保秘密声明了正确的类型(还可能指定注释?)
resource "kubernetes_secret" "vault" {
metadata {
name = "vault-token"
annotations = {
"kubernetes.io/service-account.name" = "vault"
}
}
type = "kubernetes.io/service-account-token" // THIS!
}
Then, once you have the proper type specified, you can use the token然后,一旦指定了正确的类型,就可以使用令牌
output "token" {
value = kubernetes_secret.vault.data.token
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.