This error occurs when Terraform configuration contains invalid or unsupported arguments in resources, modules, or variables. Fix it by verifying argument names against provider documentation, checking module variable definitions, and updating deprecated arguments.
The "argument not expected" error means that Terraform encountered an argument (configuration key) that doesn't exist or isn't recognized in the current context. This typically happens in three scenarios: 1. **Module variable mismatch**: You're passing an argument to a module that doesn't declare a corresponding variable in its `variables.tf` file. 2. **Provider version incompatibility**: You're using an argument that was deprecated, renamed, or removed in a newer provider version. For example, `number_cache_clusters` might have been renamed to `num_cache_clusters`. 3. **Syntax errors**: You're using incorrect block syntax where Terraform expects an argument assignment (with `=` sign), or vice versa. Terraform's "Did you mean Y?" suggestion appears when it detects a similar argument name, helping you quickly fix typos or outdated argument names.
Update your provider locks to the latest compatible versions. This helps identify version-specific argument changes:
terraform init -upgradeThis refreshes your .terraform.lock.hcl file and downloads the latest provider versions. After this, run terraform validate to see if the issue persists or resolves.
Terraform often suggests the correct argument name. If the error says "Did you mean X?", update your configuration to use X instead.
For example, if you see:
Error: An argument named "number_cache_clusters" is not expected here. Did you mean "num_cache_clusters"?Update your code:
# Wrong
resource "aws_elasticache_replication_group" "example" {
number_cache_clusters = 3
}
# Correct
resource "aws_elasticache_replication_group" "example" {
num_cache_clusters = 3
}If you're passing arguments to a module, ensure the child module declares them as variables:
# In your root module
module "example" {
source = "./modules/example"
custom_argument = "value" # ERROR: this arg must be declared in module
}
# Fix: add to modules/example/variables.tf
variable "custom_argument" {
type = string
description = "Description of the argument"
}
# Then use it in the module's main.tf
resource "some_resource" "example" {
name = var.custom_argument
}Visit the official provider documentation and verify the argument name and type for your provider version.
For AWS Provider:
- Go to https://registry.terraform.io/providers/hashicorp/aws/latest
- Find your resource type
- Check the "Argument Reference" section for exact names
For other providers, replace aws with your provider name at https://registry.terraform.io/
If upgrading a provider, check the changelog for breaking changes or deprecated arguments:
# View provider version info
terraform versionUpdate your required_providers block if needed:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0" # Update to desired version
}
}
}Run terraform validate to catch errors early and get detailed diagnostics:
terraform validateFor more detailed error information, enable debug logging:
TF_LOG=DEBUG terraform plan 2>&1 | head -100The full error output often shows the exact line and resource causing the issue, making it easier to pinpoint the problem.
Module Variable Caching: After updating module variables, Terraform may still use cached module metadata. Clear the cache by deleting the .terraform directory and running terraform init again:
rm -rf .terraform
terraform initProvider Breaking Changes: Major provider version upgrades frequently introduce breaking changes. Always review the changelog before upgrading. For example, AWS Provider 5.0 had significant argument renames and reorganizations. Test upgrades in a non-production environment first.
Block vs Argument Syntax: Terraform 0.12+ requires different syntax:
- Arguments (most resource settings): use = sign (e.g., name = "value")
- Blocks (nested structures): use no = sign (e.g., tags { ... })
If you see "Blocks of type 'X' are not expected here. Did you mean to define argument 'X'?", add an equals sign to convert it to an argument.
Cross-Module References: When modules reference variables from parent modules, ensure the variable is properly passed through. Use var.variable_name syntax and verify the variable is declared in all intermediate variables.tf files.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform