Terraform Reference to Undeclared Resource: How to Fix
Fix the Terraform 'Reference to undeclared resource' error. Causes include typos, missing resources, wrong module references, and for_each/count confusion.
DevOps
Fix the Terraform 'An argument named X is not expected here' error. Common causes include wrong provider version, deprecated arguments, typos
The argument doesn't exist for this resource in your provider version. Check for:
Error: Unsupported argument
on main.tf line 5, in resource "aws_instance" "web":
5: instance_tenancy = "default"
An argument named "instance_tenancy" is not expected here.# ❌ Typo — "instace_type" instead of "instance_type"
resource "aws_instance" "web" {
ami = "ami-abc123"
instace_type = "t3.micro" # Missing 'n'!
}
# ✅ Correct
resource "aws_instance" "web" {
ami = "ami-abc123"
instance_type = "t3.micro"
}Check the Terraform Registry documentation for the exact argument names.
# ❌ "instance_tenancy" belongs to aws_vpc, not aws_instance
resource "aws_instance" "web" {
ami = "ami-abc123"
instance_type = "t3.micro"
instance_tenancy = "default" # This is a VPC argument!
}
# ✅ Correct resource
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default" # Correct here
}Check the documentation for the specific resource type you're using.
# This argument was added in AWS provider 5.40
resource "aws_eks_cluster" "main" {
compute_config {
enabled = true # Added in 5.40 — fails on 5.30
}
}Error: Unsupported argument
An argument named "compute_config" is not expected here.terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.50" # Upgrade to version that has the argument
}
}
}terraform init -upgrade# "tags" was moved from aws_s3_bucket to a separate resource
resource "aws_s3_bucket" "data" {
bucket = "my-data"
# ❌ Removed in AWS provider 4.x — use aws_s3_bucket_versioning instead
versioning {
enabled = true
}
}
# ✅ Correct for AWS provider 4.x+
resource "aws_s3_bucket" "data" {
bucket = "my-data"
}
resource "aws_s3_bucket_versioning" "data" {
bucket = aws_s3_bucket.data.id
versioning_configuration {
status = "Enabled"
}
}Check the provider changelog for removed/migrated arguments.
# ❌ "encrypted" is inside root_block_device, not at the top level
resource "aws_instance" "web" {
ami = "ami-abc123"
instance_type = "t3.micro"
encrypted = true # Wrong level!
}
# ✅ Correct nesting
resource "aws_instance" "web" {
ami = "ami-abc123"
instance_type = "t3.micro"
root_block_device {
encrypted = true # Correct — inside the block
}
}# ❌ Data sources have different arguments than resources
data "aws_instance" "web" {
instance_type = "t3.micro" # Not a filter — not supported here
}
# ✅ Data sources use filter blocks
data "aws_instance" "web" {
filter {
name = "instance-type"
values = ["t3.micro"]
}
}# 1. Check your provider version
terraform providers
# 2. Check the exact resource documentation
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance
# 3. Validate syntax
terraform validate
# 4. Format (catches some issues)
terraform fmt"Unsupported argument" almost always means one of five things: typo, wrong resource type, provider too old, argument removed in newer provider, or argument at the wrong nesting level. Check the Terraform Registry documentation for your specific resource and provider version. Run terraform validate to catch these errors before plan.
Fix the Terraform 'Reference to undeclared resource' error. Causes include typos, missing resources, wrong module references, and for_each/count confusion.
Fix the Terraform 'Backend configuration changed' error. Migrate state between backends (local to S3, S3 to S3), resolve lock conflicts
Fix Terraform provider version conflicts between modules, lock files, and constraint mismatches. Resolve dependency lock errors, upgrade providers safely
Fix Docker provider connection refused errors in Terraform. Covers Docker daemon socket permissions, TLS configuration, and remote host setup.