英文:
terraform-kubernetes-provider how to create secret similar to a secret created from a file
问题
我正在尝试在TF中模拟kubectl命令。
Kubectl命令
```plaintext
kubectl create secret generic cloud-access \
--from-file=basic.txt=$TUTORIAL_HOME/creds-sasl-user.txt
creds-sasl-user.txt的内容
username=<api-key>
password=<api-secret>
在我的Terraform运行中,我已经创建了API密钥和API秘钥,但我不确定如何模拟确切的行为。到目前为止,我有以下内容,但我觉得不正确:
resource "kubernetes_secret" "k8s_secret" {
metadata {
namespace = var.namespace
name = var.secret_name
}
data = {
basic.txt = "username=${var.api_key}password=${var.api_secret}"
}
}
英文:
I am trying to simulate the kubectl commands in TF.
Kubectl command
kubectl create secret generic cloud-access \
--from-file=basic.txt=$TUTORIAL_HOME/creds-sasl-user.txt
Contents of creds-sasl-user.txt
username=<api-key>
password=<api-secret>
In my Terraform run, I have the API key and API secret created but I am not sure how I can simulate the exact behaviour. This is what I have so far but doesn't seems correct to me
resource "kubernetes_secret" "k8s_secret" {
metadata {
namespace = var.namespace
name = var.secret_name
}
data = {
basic.txt = "username=${var.api_key}password=${var.api_secret}"
}
}
答案1
得分: 1
根据官方 TF 文档,您可以使用 <<EOT
来传递多行字符串,就像这样:
resource "kubernetes_secret" "k8s_secret" {
metadata {
namespace = "default"
name = "test"
}
data = {
"basic.txt" = <<EOT
username=<api-key>
password=<api-secret>
EOT
}
}
在应用之前,请不要忘记将 Secret 的键(basic.text
)放在引号内。
英文:
As per the official TF documentation, You can use <<EOT
to pass multi line string like this:
resource "kubernetes_secret" "k8s_secret" {
metadata {
namespace = "default"
name = "test"
}
data = {
"basic.txt" = <<EOT
username=<api-key>
password=<api-secret>
EOT
}
}
Don't forget to place Secret's key (basic.text
) within the quotes before applying.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论