opentofu/opentofu · error
invalid schema: none of configschema.Attribute.Required/Comp
Error message
invalid schema: none of configschema.Attribute.Required/Computed/Optional set on
What it means
MockValueComposer (the engine behind tofu test mocks and overrides) requires every provider attribute to declare at least one of Required, Optional, or Computed (WriteOnly is handled earlier). If all three are false it cannot decide how to synthesize a value and panics, naming the attribute. This is a provider schema bug - your mock .tf files are not at fault.
Source
Thrown at internal/configs/hcl2shim/mock_value_composer.go:207
// at this time there is no possible way for providers to specify NestedGroup.
mockAttrs[k] = cty.NullVal(attr.ImpliedType())
}
} else if attr.Computed {
// Value from provider only
if hasConfig {
diags = diags.Append(tfdiags.WholeContainingBody(
tfdiags.Error,
fmt.Sprintf("Invalid mock/override field `%v`", k),
"Config value can not be specified for computed field",
))
}
if hasOverride {
mockAttrs[k] = ovConvert
} else {
mockAttrs[k] = mvc.getMockValueByType(attr.ImpliedType())
}
} else {
panic("invalid schema: none of configschema.Attribute.Required/Computed/Optional set on " + k)
}
}
return mockAttrs, diags
}
func (mvc MockValueComposer) composeMockValueForBlocks(schema *configschema.Block, configMap map[string]cty.Value, overrides map[string]cty.Value) (map[string]cty.Value, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
mockBlocks := make(map[string]cty.Value)
impliedTypes := schema.ImpliedType().AttributeTypes()
// Stable order is important here so random values match its fields between function calls.
for _, kv := range mapToSortedSlice(schema.BlockTypes) {
k, block := kv.k, kv.v
// Checking if the config value really present for the block.View on GitHub (pinned to 3561785c48)
Solutions
- Pin/downgrade the provider to the previous working version and re-run tofu test
- Identify the culprit attribute: tofu providers schema -json and look for attributes where required, optional and computed are all false
- Report to the provider maintainer with the attribute name from the panic message
- As a workaround, scope tests/mocks away from the resource or data source containing the broken attribute
Example fix
// before - provider attribute with no mode flags
"broken": {Type: cty.String, Optional: false, Required: false, Computed: false}
// after - declare a mode
"broken": {Type: cty.String, Optional: true} Defensive patterns
Strategy: validation
Validate before calling
$ tofu providers schema -json | jq '[.. | objects | select(has("required")) | select((.required // false) or (.optional // false) or (.computed // false)) | empty] // []
# inverted check: list attributes where all three flags are false should be empty Type guard
func attributeHasMode(a *configschema.Attribute) bool {
if a == nil {
return true
}
return a.Required || a.Optional || a.Computed || a.WriteOnly
} Prevention
- Run tofu test against a known-good provider pin in CI
- After provider upgrades, dump the schema and check for mode-less attributes
- Report flag-less attributes to provider maintainers immediately
When it happens
Trigger: Running tofu test with mocks (or any plan consuming composed mock values) against a provider whose schema contains an attribute with Required=false, Optional=false, Computed=false; the if/else chain in composeMockValueForAttrs falls through to the final else.
Common situations: Provider schemas converted over the wire that lost the mode flags; experimental provider frameworks emitting flag-less attributes; version skew between the provider and OpenTofu's test engine.
Related errors
- Invalid attribute schema: NestedType and Type cannot both be
- unsupported nesting mode %s
- unsupported nesting mode %s
- invalid set element type
- Unknown type for input: %#v
AI-assisted analysis of opentofu/opentofu@3561785c48 (2026-08-15).
Data as JSON: /api/errors/afcaf650a7aab1d9.
Report an issue: GitHub.