terraform-kubernetes-provider如何创建类似于从文件创建的密钥。

huangapple go评论62阅读模式
英文:

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=&lt;api-key&gt;
password=&lt;api-secret&gt;

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 &quot;kubernetes_secret&quot; &quot;k8s_secret&quot; {
  metadata {
    namespace = var.namespace
    name      = var.secret_name
  }
  data = {
    basic.txt           = &quot;username=${var.api_key}password=${var.api_secret}&quot;
  }
}

答案1

得分: 1

根据官方 TF 文档,您可以使用 &lt;&lt;EOT 来传递多行字符串,就像这样:

resource &quot;kubernetes_secret&quot; &quot;k8s_secret&quot; {
  metadata {
    namespace = &quot;default&quot;
    name      = &quot;test&quot;
  }
  data = {
  &quot;basic.txt&quot;           = &lt;&lt;EOT
username=&lt;api-key&gt;
password=&lt;api-secret&gt;
  EOT
  }
}

在应用之前,请不要忘记将 Secret 的键(basic.text)放在引号内。

英文:

As per the official TF documentation, You can use &lt;&lt;EOT to pass multi line string like this:

resource &quot;kubernetes_secret&quot; &quot;k8s_secret&quot; {
  metadata {
    namespace = &quot;default&quot;
    name      = &quot;test&quot;
  }
  data = {
  &quot;basic.txt&quot;           = &lt;&lt;EOT
username=&lt;api-key&gt;
password=&lt;api-secret&gt;
  EOT
  }
}

Don't forget to place Secret's key (basic.text) within the quotes before applying.

huangapple
  • 本文由 发表于 2023年6月2日 08:32:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76386505.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定