Terraform 给出错误:“运行 terraform 计划时模块中的参数不受支持”

问题描述 投票:0回答:2

当我在版本 12.24 中运行 Terraform 计划时,出现错误:不受支持的参数。

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])

我该如何解决这个问题?

amazon-web-services syntax-error terraform terraform-provider-aws terraform-modules
2个回答
8
投票

我正在复制对我有用的解决方案从github,归功于hashicorp成员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 配置中的此类问题。 👍


1
投票

错误

此处不需要名为“secret_environment_variables”的参数。 您的意思是定义一个“secret_environment_variables”类型的块吗?

问题

main.tf

resource "google_cloudfunctions_function" "this" {
 secret_environment_variables = var.secret_environment_variables
}

variables.tf

variable "secret_environment_variables" {
  type        = any
  default     = {}
  description = "Secret environment variables configuration."
}

解决方案

resource "google_cloudfunctions_function" "this" {
  secret_environment_variables {
    key     = var.secret_environment_variables_key
    secret  = var.secret_environment_variables_secret
    version = var.secret_environment_variables_version
  }
}
variable "secret_environment_variables_key" {
  type        = string
  default     = null
  nullable    = true
  description = "Name of the environment variable."
}
variable "secret_environment_variables_secret" {
  type        = string
  default     = null
  nullable    = true
  description = "ID of the secret in secret manager (not the full resource name)."
}
variable "secret_environment_variables_version" {
  type        = string
  default     = null
  nullable    = true
  description = "Version of the secret (version number or the string `latest`). It is recommended to use a numeric version for secret environment variables as any updates to the secret value is not reflected until new clones start."
}
© www.soinside.com 2019 - 2024. All rights reserved.