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
- Set Deprecated = true on the NestedBlock alongside DeprecationMessage.
- 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
- Always pair DeprecationMessage with Deprecated = true on nested blocks.
- Reuse a shared deprecation helper so the invariant holds everywhere.
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
- top-level block: DeprecationMessage must not be set when Dep
- top-level block schema is nil
- %s%s: attribute schema is nil
- %s%s: all attributes within computed blocks must also be com
- %s%s: block schema is nil
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/d9117b5c8059f4b4.
Report an issue: GitHub.