我有以下問題。我嘗試使用帶有 Gitlab CI/CD 的 Terraform 連接到 eks 集群,我收到錯誤訊息,但是在我的計算中嘗試時,沒有出現此錯誤,有人有同樣的錯誤嗎?
$ terraform output authconfig > authconfig.yaml
$ cat authconfig.yaml
<<EOT
apiVersion: v1
kind: ConfigMap
metadata:
name: aws-auth
namespace: kube-system
data:
mapRoles: |
- rolearn: "arn:aws:iam::503655390180:role/clusters-production-workers"
username: system:node:{{EC2PrivateDNSName}}
groups:
- system:bootstrappers
- system:nodes
EOT
$ kubectl create -f authconfig.yaml -n kube-system
error: error parsing authconfig.yaml: error converting YAML to JSON: yaml: line 2: mapping values are not allowed in this context
uj5u.com熱心網友回復:
輸出包括 EOT(EndOfText) 標記,因為它最初是作為多行字串生成的。
正如檔案所建議的那樣(terrafom 檔案鏈接)
不要使用“heredoc”字串來生成 JSON 或 YAML。相反,請使用 jsonencode 函式或 yamlencode 函式,以便 Terraform 負責保證有效的 JSON 或 YAML 語法。
在構建輸出之前使用 json 編碼或 yaml 編碼。
如果您想繼續使用您現在擁有的內容,請嘗試使用 output -json 或 -raw 提供這些選項
- terraform 輸出 -json authconfig > authconfig.yaml 或
- terraform 輸出 -raw authconfig > authconfig.yaml
uj5u.com熱心網友回復:
錯誤資訊告訴您 authconfig.yaml 檔案無法從 YAML 轉換為 JSON,這表明它不是有效的 yaml
您向我們展示的 cat authconfig.yaml 包含一些<<EOT和EOT標簽。我建議在運行之前洗掉它們kubectl create -f
您的評論表明您已經知道這一點 - 那么您為什么不詢問 terraform,而不是向我們展示 kubectl create 失敗呢?從您的帖子中,聽起來真的像是您復制/粘貼了作業的輸出,甚至沒有閱讀它。
所以,很明顯,下一步是對輸出 -raw 或 -json 進行 terraform,在他們的檔案或知識庫中有幾個提到,谷歌搜索會指向你:
- https://discuss.hashicorp.com/t/terraform-outputs-with-heredoc-syntax-leaves-eot-in-file/18584/7
- https://www.terraform.io/docs/cli/commands/output.html
最后:我們可以問為什么? terraform output >當您可以讓 terraform 寫入檔案時,您為什么要這樣做?
雖然作為一般規則,每當將 terraform stdout/stderr 寫入檔案時,我強烈建議使用無顏色。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/317630.html
標籤:Kubernetes 地形 gitlab-ci 亚马逊-eks
上一篇:RabbitMQpod意外崩潰
