Terraform is giving an error: "unsupported argument in module when running terraform plan"

10.2k views Asked by At

I am getting the Error: Unsupported argument, when I run the Terraform plan in version 12.24.

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"?

This is the code in the .tf file:

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

I am not sure how to fix this error. The above error was fixed by removing "=" after timeouts.

I am also getting more errors that need solutions:

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"?

Code in the .tf file:

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

How can I fix this?

2

There are 2 answers

3
DanielG On

I am copying the solution that worked for me from GitHub, and credits go to the HashiCorp member bflad:

In Terraform 0.12 (or higher), the configuration language parser is stricter about the distinction between arguments and configuration blocks. This error:

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

Generally means the = (equals sign) needs to be removed from an argument assignment so it parses correctly as a configuration block, e.g.

root_block_device {

This distinction in HCL syntax may seem trivial, but under the hood this stricter type checking allowed for consistency with JSON syntax. More information about this change can be found in the Terraform 0.12 Upgrade Guide. Speaking of which, in that guide it does point to the helpful terraform 0.12upgrade command, which should automatically fix issues like these across your Terraform configurations when upgrading from Terraform 0.11.

1
BartusZak On

Error

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

Problem

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."
}

Solution

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."
}