hashicorp/terraform · critical

unknown nesting mode: %d

Error message

unknown nesting mode: %d

What it means

Panics in mocking.fillAttribute (fill.go:67). When filling placeholder values for a nested-type attribute, the switch handles the known configschema nesting modes (Single, Group, Set, List, Map); an unrecognized nesting integer panics, indicating a schema with an invalid/out-of-range Nesting value.

Source

Thrown at internal/moduletest/mocking/fill.go:67

				if in.Type().HasAttribute(name) {
					child, err := fillAttribute(in.GetAttr(name), attribute.NestedType.Attributes[name], path.GetAttr(name))
					if err != nil {
						return cty.NilVal, err
					}
					children[name] = child
					continue
				}
				children[name] = GenerateValueForAttribute(attribute.NestedType.Attributes[name])
			}
			return cty.ObjectVal(children), nil
		case configschema.NestingSet:
			return cty.SetValEmpty(attribute.ImpliedType().ElementType()), nil
		case configschema.NestingList:
			return cty.ListValEmpty(attribute.ImpliedType().ElementType()), nil
		case configschema.NestingMap:
			return cty.MapValEmpty(attribute.ImpliedType().ElementType()), nil
		default:
			panic(fmt.Errorf("unknown nesting mode: %d", attribute.NestedType.Nesting))
		}
	}

	return fillType(in, attribute.Type, path)
}

// FillType makes the input value match the target type by adding attributes
// directly to it or to any nested objects. Essentially, this is a "safe"
// conversion between two objects.
//
// This function can error if one of the embedded types within value doesn't
// match the type expected by target.
//
// If the supplied value isn't an object (or a map that can be treated as an
// object) then a normal conversion is attempted from value into target.
//
// Superfluous attributes within the supplied value (ie. attributes not
// mentioned by the target type) are dropped without error.

View on GitHub (pinned to c9def3e214)

Solutions

  1. Ensure NestedType.Nesting uses defined configschema constants.
  2. Regenerate the mock schema from the real provider schema.
  3. Align the mock schema with the nesting modes this build supports.
Defensive patterns

Strategy: validation

Validate before calling

func nestingModeKnown(n configschema.NestingMode) error {
    switch n {
    case configschema.NestingSingle, configschema.NestingGroup,
        configschema.NestingSet, configschema.NestingList, configschema.NestingMap:
        return nil
    }
    return fmt.Errorf("unknown nesting mode: %d", n)
}

Prevention

When it happens

Trigger: A mocked resource/attribute whose NestedType.Nesting is set to an undefined value (not one of the configschema.Nesting constants), exercised via the mock_provider / test mocking feature.

Common situations: Bugs in schema construction for mocks, or a configschema.Nesting value from a newer/incompatible version not handled by this fill implementation.

Related errors


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