【问题标题】:terraform giving error: unsupported argument in module when running terraform plan?terraform 给出错误:运行 terraform 计划时模块中的参数不受支持?
【发布时间】:2021-01-16 13:57:08
【问题描述】:

当我在版本 12.24 中运行 terraform plan 时,我收到错误:不支持的参数。

Error: Unsupported argument
  on .terraform/modules/app/main.tf line 261, in resource "aws_db_instance" "db_instance":
 261:   timeouts = {
An argument named "timeouts" is not expected here. Did you mean to define a
block of type "timeouts"?

这是tf文件中的代码:

timeouts = {
    create = "${var.db_instance_create_timeout}"
    update = "${var.db_instance_update_timeout}"
    delete = "${var.db_instance_delete_timeout}"
  }

我不确定如何修复此错误。

  • 通过在超时后删除“=”修复了上述错误。

我也遇到了更多错误,需要解决方案:

Error: Unsupported argument

  on .terraform/modules/rds/main.tf line 150, in resource "aws_db_parameter_group" "db_parameter_group":
 150:   parameter = concat(var.parameters, local.parameters[local.parameter_lookup])

An argument named "parameter" is not expected here. Did you mean to define a
block of type "parameter"?

tf 文件中的代码:

  parameter = concat(var.parameters, local.parameters[local.parameter_lookup])

如何解决这个问题?

【问题讨论】:

  • 错误消息声称您应该使用块而不是 timeouts 的参数,并且文档同意:registry.terraform.io/providers/hashicorp/aws/latest/docs/…。你试过吗?
  • terraform.io/docs/configuration/resources.html... 超时后不应有等号.... 超时 {
  • 我做到了,它成功了..谢谢!
  • 我在问题中添加了另一个我面临的问题.. 也需要帮助解决这个问题!
  • 这又是完全相同的问题。正如错误消息所暗示的那样,您在那里添加了一个不必要的 = 使其成为参数而不是块。

标签: amazon-web-services syntax-error terraform terraform-provider-aws terraform-modules


【解决方案1】:

我正在复制对我有用的解决方案 from github,感谢 hashcorp 成员 bflad:

在 Terraform 0.12(或更高版本)中,配置语言解析器对参数和配置块之间的区别更加严格。这个错误:

An argument named "XXX" is not expected here. Did you mean to
define a block of type "XXX"?

通常意味着 =(等号)需要从参数分配中删除,以便正确解析为配置块,例如

root_block_device {

HCL 语法中的这种区别可能看起来微不足道,但在底层,这种更严格的类型检查允许与 JSON 语法保持一致。有关此更改的更多信息,请参阅 Terraform 0.12 升级指南。说到这一点,在该指南中它确实指向了有用的 terraform 0.12upgrade 命令,当从 Terraform 0.11 升级时,它应该会自动修复您的 Terraform 配置中的此类问题。 ?

【讨论】:

  • 使用不那么严格的解析,可以执行 "root_block_device = "${var.root_block_device}"。这似乎不再可行。是否有另一种分配给配置块的方法?
猜你喜欢
  • 2021-01-30
  • 2021-01-16
  • 2021-06-27
  • 1970-01-01
  • 2021-02-18
  • 1970-01-01
  • 2020-09-18
  • 2018-10-11
  • 2021-06-07
相关资源
最近更新 更多