This error occurs when passing an argument to a module that either doesn't exist as a variable definition or has an incorrect type. Fix it by ensuring the module has the required variable declared and you're passing the correct data type.
This error happens when Terraform tries to pass a value to a module, but the module doesn't have a corresponding variable definition for that argument. Modules are self-contained Terraform configurations that accept inputs through input variables. If you're passing an argument that the module doesn't define, Terraform rejects it during validation. The error can appear in two main scenarios: the variable is completely missing from the module's variable definitions (you're passing "foo" but the module never declares variable "foo"), or the variable exists but the value you're passing doesn't match the expected type (e.g., passing a string when the variable expects a number or object). Terraform validates module arguments before planning or applying, so this error prevents any infrastructure changes from being attempted.
Examine the module's variables.tf file to see what input variables it actually accepts. Look for the variable blocks:
# In the module's variables.tf
variable "instance_type" {
description = "Type of instance to create"
type = string
default = "t2.micro"
}
variable "environment" {
description = "Environment name"
type = string
# No default - this is required
}Compare this with the arguments you're passing in your module call. Every argument you pass must have a corresponding variable block.
Verify that the argument name in your module call exactly matches the variable name in the module definition. Common mistakes include typos:
# Wrong - typo in "instance_type"
module "example" {
source = "./my-module"
instanc_type = "t2.micro" # Misspelled
}
# Correct - exact match with module's variable name
module "example" {
source = "./my-module"
instance_type = "t2.micro" # Matches variable "instance_type"
}Double-check every character of the argument name.
If you need to pass a new argument that the module doesn't support, add a variable block to the module's variables.tf:
# In module's variables.tf
variable "enable_logging" {
description = "Enable CloudWatch logging"
type = bool
default = false # Optional if you provide a default
}Then update your module call:
module "example" {
source = "./my-module"
instance_type = "t2.micro"
enable_logging = true # Now the variable exists
}Remember that variables without defaults are required; you must pass a value for them.
Ensure the value you pass matches the type declared in the variable:
# In module's variables.tf
variable "port" {
type = number
}
variable "tags" {
type = map(string)
}
variable "subnets" {
type = list(string)
}
# In your calling code - types must match
module "example" {
source = "./my-module"
port = 8080 # number - not a string "8080"
tags = { # map of strings
Name = "my-resource"
}
subnets = ["subnet-1", "subnet-2"] # list of strings
}Common type mismatches: passing a string when a number is expected, or a single value when a list is expected.
If you're using a module from the Terraform Registry, verify the argument name and type in the official documentation:
# View module source and variables
# For registry modules, check: https://registry.terraform.io/modules/...
# Look for the "Inputs" section
# For local modules, use terraform console to inspect
terraform console
> module.example.variable # List available variablesThe registry documentation shows all required and optional inputs with their types and descriptions.
After making changes, run terraform validate to ensure the module arguments are now recognized:
terraform validateThis will confirm that:
- All required module arguments are provided
- Argument values match the expected types
- No syntax errors remain
If validation passes, you can proceed with terraform plan.
For complex modules with nested object types, ensure all required nested attributes are provided. If a variable expects type object({ name = string, count = number }), you must provide both name and count in the right format.
When working with versioned modules from the Terraform Registry, version constraints matter. An argument that exists in version 2.0 might not exist in version 1.5. Check the version constraint in your module source (e.g., source = "registry.terraform.io/example/module" version = "~> 2.0") and ensure your argument names match that version.
For modules requiring complex configurations, consider using local values to build up the argument value:
locals {
module_config = {
instance_type = "t2.micro"
tags = {
Name = "example"
}
}
}
module "example" {
source = "./my-module"
# Pass the pre-built configuration
config = local.module_config
}This approach makes large module calls more readable and maintainable.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform