尝试在EKS集群中应用configmap进行授权时出错



我有以下问题。我尝试使用giitlab CI/CD的Terraform连接到weeks集群,我收到错误消息,但是当我在计算中尝试时,这个错误没有出现,有人有同样的错误吗?


$ 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

输出包括EOT(EndOfText)标记,因为它最初是作为多行字符串生成的。

如文档所示(terrafom doc link)

不要使用"heredoc"字符串来生成JSON或YAML。相反,使用jsonencode函数或yamlencode函数,以便Terraform可以负责保证有效的JSON或YAML语法。

在构建输出之前使用json编码或yaml编码。

如果你想继续这样与你现在试着给这些选项输出json或原始

  • terraform output - authconfig>authconfig.yaml或
  • terraform output -raw authconfig>authconfig.yaml

错误消息告诉您authconfig。yaml文件不能从yaml转换为JSON,表明这不是一个有效的yaml

cat authconfig. conf您向我们展示的yaml包含一些<<EOTEOT标签。我建议在运行kubectl create -f

之前删除这些

你的评论表明你已经知道了这一点-那你为什么不问一下terraform,而不是向我们展示kubectl创建失败?从你的帖子中,听起来你真的像复制/粘贴了你的工作输出,甚至没有阅读它。

显然,下一步是对输出进行地形化-raw或-json,在他们的文档或知识库中有几个提到,谷歌搜索会指向:

  • 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

最后:我们可以问为什么?当你可以让terrform写文件的时候,为什么要用terraform output >呢?

作为一般规则,无论何时在文件中写入terraform stdout/stderr,我强烈建议使用no-color。

最新更新