OpenTofu Error: 'Missing required argument' — Cause, Fix, and Troubleshooting Guide
Fix OpenTofu 'Error: Missing required argument' by supplying required resource attributes, module inputs, or nested block fields.
- #opentofu
- #iac
- #troubleshooting
- #errors
Fixing errors like this? Get 500 free DevOps AI prompts
500 copy-paste AI prompts for the stack you actually run — one PDF, free.
Overview
Provider schemas and module interfaces mark some arguments as required. If you omit one — a mandatory resource attribute, a nested-block field, or a module variable with no default — OpenTofu refuses to proceed and names exactly what is missing:
Error: Missing required argument
on main.tf line 8, in resource "aws_instance" "web":
8: resource "aws_instance" "web" {
The argument "instance_type" is required, but no definition was found.
Symptoms
tofu validate/planfails withMissing required argument.- The message names the required argument and the block it belongs to.
- Common with new resources copied from partial examples, or module calls missing an input.
- Nested-block variants say the argument is required “in a X block.”
Common Root Causes
- Omitted required attribute — e.g.,
instance_type,bucket,name. - Module input without a default not passed by the caller.
- Missing nested-block field — a required key inside
ebs,setting,filter, etc. - Conditional set to null — a ternary produced
nullfor a required argument. - Removed line during a refactor that dropped a required field.
How to diagnose
OpenTofu names the argument and location — go there first:
tofu validate
Confirm which arguments a resource requires via the schema:
tofu providers schema -json \
| jq '.provider_schemas["registry.opentofu.org/hashicorp/aws"].resource_schemas["aws_instance"].block.attributes
| to_entries | map(select(.value.required==true)) | map(.key)'
For a module call, list its required variables (those without a default):
grep -rnA4 'variable ' modules/network/ | grep -B3 -L 'default'
Fixes
Supply the required attribute:
resource "aws_instance" "web" {
ami = var.ami_id
instance_type = "t3.micro" # was missing
}
Pass the missing module input:
module "network" {
source = "./modules/network"
cidr_block = "10.0.0.0/16" # required variable, no default
}
Avoid null for a required argument — provide a real fallback:
instance_type = var.size != null ? var.size : "t3.micro"
Re-validate:
tofu validate && tofu plan
What to watch out for
nullcounts as “not set” for required arguments — a ternary must yield a concrete value.- The provider schema is authoritative about what is required; grep it rather than guessing from examples.
- Give module variables sensible
defaults where appropriate so callers are not forced to set everything. - Run
tofu validatein CI to catch missing arguments before any API calls.
Related
- OpenTofu Error: ‘Unsupported argument’ — Cause, Fix, and Troubleshooting Guide
- OpenTofu Error: ‘Invalid function argument’ — Cause, Fix, and Troubleshooting Guide
- OpenTofu Error: ‘Unsuitable value type’ — Cause, Fix, and Troubleshooting Guide
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.