可以对通过 terraformer 生成的文件运行 terraform 命令

Posted

技术标签:

【中文标题】可以对通过 terraformer 生成的文件运行 terraform 命令【英文标题】:Can run terraform commands on files generated via terraformer 【发布时间】:2021-10-29 19:09:23 【问题描述】:

我有通过 terraformer 生成的 tf 文件,当我运行“terraform plan/refresh”时,它给了我一堆错误,例如:

    Error: Invalid combination of arguments

  on instance.tf line 400, in resource "aws_instance" "worker-node":
 400:     id   = "lt-xxxxxxxxxxxxxxx"

"launch_template.0.id": only one of
`launch_template.0.id,launch_template.0.name` can be specified, but
`launch_template.0.id,launch_template.0.name` were specified.


Error: Invalid combination of arguments

  on instance.tf line 401, in resource "aws_instance" "worker-node":
 401:     name = "eksctl-workernode"

"launch_template.0.name": only one of
`launch_template.0.id,launch_template.0.name` can be specified, but
`launch_template.0.id,launch_template.0.name` were specified.

这只是关于 EC2 的问题,对于每个其他服务,它都会给出不同的错误。导致错误的实例是 EKS 节点。

【问题讨论】:

产生错误的代码是什么? 如何查看错误码? 【参考方案1】:

您的启动模板变量似乎不正确。您可能有一些需要纠正的工作节点代码。您是否尝试使用EKS node groups?

【讨论】:

没有。不过我解决了。显然在启动模板中有一些配置在“启动模板”下编写时会导致错误。所以我删除了 lauch 模板名称,只留下了 id 和 terraform plan/refresh 工作。【参考方案2】:

来自 cmets 的社区回答:

启动模板中有配置。这导致在launch template下写入错误

所以我删除了launch template 名称,只留下了id

然后terraform plan/apply 工作了

【讨论】:

以上是关于可以对通过 terraformer 生成的文件运行 terraform 命令的主要内容,如果未能解决你的问题,请参考以下文章

terraform-远程状态存储

Terraform 学习总结——Terraform 命令详解

如何使用 terraform 生成 yml 配置文件

Terraform GCP 启动脚本本地文件而不是内联文件

如何在 Terraform 中管理本地生成的有状态文件

Terraform 使用数据源输出动态生成字符串