Skip to content
Latchkey

Terraform "Missing required argument" for a module variable in CI

A module declares an input variable with no default, so it is required. The module block that calls it does not pass a value for that argument, and Terraform refuses to plan until it is supplied.

What this error means

plan or validate stops with "Error: Missing required argument" and "The argument \"X\" is required, but no definition was found." pointing at a module block.

Terraform
Error: Missing required argument

  on main.tf line 5, in module "network":
   5: module "network" {

The argument "cidr_block" is required, but no definition was found.

Common causes

A required module input was not passed

The module defines variable "cidr_block" {} with no default, so every caller must set it in the module block.

A module upgrade added a new required input

A newer module version introduced a required variable that the existing module block does not yet provide.

How to fix it

Pass the required argument

  1. Open the module and list variables without a default.
  2. Set each one in the module block.
  3. Re-run plan to confirm no required arguments remain.
main.tf
module "network" {
  source     = "./modules/network"
  cidr_block = "10.0.0.0/16"
}

Give the module input a default where appropriate

If a value is optional, add a default to the module's variable so callers are not forced to set it.

modules/network/variables.tf
variable "cidr_block" {
  type    = string
  default = "10.0.0.0/16"
}

How to prevent it

  • Set all no-default module inputs in every module block.
  • Review module upgrade changelogs for new required inputs.
  • Run terraform validate in CI to catch missing arguments early.

Frequently asked questions

What causes ""Missing required argument" (module)"?
The module defines variable "cidr_block" {} with no default, so every caller must set it in the module block.
How do I fix "Missing required argument" (module)?
Pass the required argument

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card