opentofu/opentofu · error

No '=' value in arg: %s

Error message

No '=' value in arg: %s

What it means

FlagStringKV implements Go's flag.Value to parse -var arguments of the form key=value for OpenTofu's CLI. Set splits the raw argument on the first '=' via strings.Cut; when no '=' is present it returns this error verbatim. It is the standard rejection path for a malformed -var flag.

Source

Thrown at internal/command/flags/flag_kv.go:26

import (
	"flag"
	"fmt"
	"strings"
)

// FlagStringKV is a flag.Value implementation for parsing user variables
// from the command-line in the format of '-var key=value', where value is
// only ever a primitive.
type FlagStringKV map[string]string

func (v *FlagStringKV) String() string {
	return ""
}

func (v *FlagStringKV) Set(raw string) error {
	before, after, ok := strings.Cut(raw, "=")
	if !ok {
		return fmt.Errorf("No '=' value in arg: %s", raw)
	}

	if *v == nil {
		*v = make(map[string]string)
	}

	key, value := before, after
	(*v)[key] = value
	return nil
}

// FlagStringSlice is a flag.Value implementation which allows collecting
// multiple instances of a single flag into a slice. This is used for flags
// such as -target=aws_instance.foo and -var x=y.
type FlagStringSlice []string

var _ flag.Value = (*FlagStringSlice)(nil)

View on GitHub (pinned to 3561785c48)

Solutions

  1. Rewrite the flag as '-var key=value' (equal sign required, e.g. -var environment=prod)
  2. Quote the whole pair if it contains shell metacharacters: -var "key=value with spaces"
  3. Move many variables into a .tfvars file and use -var-file=terraform.tfvars instead
  4. If generating args programmatically, validate each contains '=' before passing it to the CLI

Example fix

# before
tofu apply -var environment

# after
tofu apply -var environment=prod
Defensive patterns

Strategy: validation

Validate before calling

for _, raw := range varArgs {
    if _, _, ok := strings.Cut(raw, "="); !ok {
        return fmt.Errorf("invalid -var %q: expected key=value form", raw)
    }
}

Prevention

When it happens

Trigger: Invoking tofu plan/apply/destroy with '-var key' (no '=' and value), '-var "key value"' where the '=' was typo'd to ':' or a space, an empty string argument, or CI scripts that concatenate '-var' with an environment variable that is unset.

Common situations: Typos in shell commands, unquoted arguments split by the shell, dynamically built CI/CD variable lists where one value is missing, or copy-pasting -var syntax from docs of tools that use ':' separators.

Related errors


AI-assisted analysis of opentofu/opentofu@3561785c48 (2026-08-15). Data as JSON: /api/errors/272ea40a30bfc887. Report an issue: GitHub.