hashicorp/terraform · error

unsupported variable option name %q (this is a bug in Terraf

Error message

unsupported variable option name %q (this is a bug in Terraform)

What it means

An internal assertion error in the default case of a switch over variable flag names during collectVariableValues. The source comment states this should never happen and indicates a bug in the code that built m.variableArgs. This is not a user-facing configuration error but a Terraform internal programming defect.

Source

Thrown at internal/command/arguments/vars.go:178

					fmt.Sprintf("Variable name %q is invalid due to trailing space. Did you mean -var=\"%s=%s\"?", name, strings.TrimSuffix(name, " "), strings.TrimPrefix(rawVal, " ")),
				))
				continue
			}
			ret[name] = unparsedVariableValueString{
				str:        rawVal,
				name:       name,
				sourceType: terraform.ValueFromCLIArg,
			}

		case "-var-file":
			varsFromFile, moreDiags := addVarsFromFile(flagNameValue.Value, terraform.ValueFromNamedFile, onFileLoad)
			maps.Copy(ret, varsFromFile)
			diags = diags.Append(moreDiags)

		default:
			// Should never happen; always a bug in the code that built up
			// the contents of m.variableArgs.
			diags = diags.Append(fmt.Errorf("unsupported variable option name %q (this is a bug in Terraform)", flagNameValue.Name))
		}
	}

	return ret, diags
}

func CollectValuesForTests(testsFilePath string, onFileLoad func(filename string, src []byte)) (map[string]UnparsedVariableValue, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	ret := map[string]UnparsedVariableValue{}

	// We collect the variables from the ./tests directory
	// there is no other need to process environmental variables
	// as this is done via collectVariableValues function
	if testsFilePath == "" {
		diags = diags.Append(tfdiags.Sourceless(
			tfdiags.Warning,
			"Missing test directory",
			"The test directory was unspecified when it should always be set. This is a bug in Terraform - please report it."))

View on GitHub (pinned to d32a084675)

Solutions

  1. Report a bug to the Terraform project at github.com/hashicorp/terraform/issues with the full command and version
  2. Downgrade to a known-stable Terraform version if this appeared after an upgrade
  3. If developing Terraform: add the missing case to the switch in internal/command/arguments/vars.go
Defensive patterns

Strategy: try-catch

Try / catch

// This error is an internal bug; wrap terraform invocation and surface it clearly
out, err := cmd.CombinedOutput()
if err != nil {
    if strings.Contains(string(out), "this is a bug in Terraform") {
        log.Fatal("internal Terraform bug detected; please report at " +
            "github.com/hashicorp/terraform/issues with the command and version")
    }
}

Prevention

When it happens

Trigger: The default case in the switch over flagNameValue.Name is reached during collectVariableValues. This would only happen if the code populating m.variableArgs introduced a new -var-related flag name without adding a corresponding case to this switch.

Common situations: This should never occur in released versions. If seen, it indicates a code regression during Terraform development where a new variable-related flag was added to the args map without updating the consumer switch.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/340124c054c50494. Report an issue: GitHub.