hashicorp/terraform · error

%s%s: DeprecationMessage must not be set when Deprecated is

Error message

%s%s: DeprecationMessage must not be set when Deprecated is false

What it means

For a child NestedBlock, DeprecationMessage is non-empty while Deprecated is false (checked at lines 60-61) - the same invariant as 808 but at the per-nested-block level (it runs in the BlockTypes loop, not the top-level guard). The deprecation message is only meaningful when the block is actually marked deprecated.

Source

Thrown at internal/configs/configschema/internal_validate.go:61

		// all attributes within a computed block must also be computed
		if b.Computed && !attrS.Computed {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: all attributes within computed blocks must also be computed", prefix, name))
		}
	}

	for name, blockS := range b.BlockTypes {
		if blockS == nil {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: block schema is nil", prefix, name))
			continue
		}

		if _, isAttr := b.Attributes[name]; isAttr {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: name defined as both attribute and child block type", prefix, name))
		} else if !validName.MatchString(name) {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: name may contain only lowercase letters, digits and underscores", prefix, name))
		}
		if !blockS.Deprecated && blockS.DeprecationMessage != "" {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: DeprecationMessage must not be set when Deprecated is false", prefix, name))
		}

		if blockS.MinItems < 0 || blockS.MaxItems < 0 {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: MinItems and MaxItems must both be greater than zero", prefix, name))
		}

		// any nested blocks within a computed block must also be computed
		if b.Computed && !blockS.Computed {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: all nested blocks within computed blocks must also be computed", prefix, name))
		}

		switch blockS.Nesting {
		case NestingSingle:
			switch {
			case blockS.MinItems != blockS.MaxItems:
				multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: MinItems and MaxItems must match in NestingSingle mode", prefix, name))
			case blockS.MinItems < 0 || blockS.MinItems > 1:
				multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode", prefix, name))

View on GitHub (pinned to c9def3e214)

Solutions

  1. Set Deprecated = true on the NestedBlock alongside DeprecationMessage.
  2. Or remove the DeprecationMessage if the block isn't deprecated.

Example fix

// before
"settings": {Nesting: configschema.NestingSingle, Block: configschema.Block{DeprecationMessage: "use settings_v2"}}

// after
"settings": {Nesting: configschema.NestingSingle, Block: configschema.Block{Deprecated: true, DeprecationMessage: "use settings_v2"}}
Defensive patterns

Strategy: validation

Validate before calling

for n, nb := range block.BlockTypes {
    if nb != nil && !nb.Deprecated && nb.DeprecationMessage != "" {
        return fmt.Errorf("%s: DeprecationMessage set without Deprecated", n)
    }
}

Prevention

When it happens

Trigger: Setting nb.DeprecationMessage on a nested block without nb.Deprecated = true.

Common situations: Incremental deprecation edits, generated schemas, copy-paste missing the flag.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/d9117b5c8059f4b4. Report an issue: GitHub.