hashicorp/terraform · error

: attribute schema is nil

Error message

%s: attribute schema is nil

What it means

Sibling of [844] but on the Object validator: while iterating Object.Attributes, a nil *Attribute was found for some name. The error is reported as just the attribute name (no prefix), and the loop continues so the rest of the schema is still validated. It is a structural defect in the Object's attribute map.

Solutions

  1. Remove nil-valued entries from Object.Attributes so every key has a concrete *Attribute.
  2. Replace each nil with a minimal valid *Attribute ({Type: cty.X, Optional: true}) or delete the key.
  3. Centralize Object construction behind a builder that rejects nil values at insert time.

Example fix

// before
schema := &configschema.Block{
    Attributes: map[string]*configschema.Attribute{
        "id": {Type: cty.String, Computed: true},
        "name": nil,
    },
}

// after
schema := &configschema.Block{
    Attributes: map[string]*configschema.Attribute{
        "id":   {Type: cty.String, Computed: true},
        "name": {Type: cty.String, Optional: true},
    },
}
Defensive patterns

Strategy: validation

Validate before calling

func stripNilObjectAttributes(o *configschema.Object) {
    if o == nil { return }
    for name, a := range o.Attributes {
        if a == nil { delete(o.Attributes, name) }
    }
}

Type guard

func objectHasNoNilAttrs(o *configschema.Object) bool {
    if o == nil { return true }
    for _, a := range o.Attributes {
        if a == nil { return false }
    }
    return true
}

Prevention

When it happens

Trigger: Object.Attributes map containing a key mapped to nil — same shape as [844] but at the Object (typically top-level resource) layer rather than inside a NestedType. Common when assembling the root resource schema and leaving placeholder nils for attributes filled in elsewhere.

Common situations: Provider resource schema builders that allocate the map with all expected keys then conditionally populate them; schema merge operations that fail to delete a key when its value was removed; deserialization that maps unknown attribute names to nil.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/2b473d9a726db318. Report an issue: GitHub.

Appendix: source

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

				continue
			}
			err = errors.Join(err, attrS.internalValidate(name, prefix))
		}
	}

	return err
}

func (o *Object) InternalValidate() error {
	var err error

	if o.Nesting == nestingModeInvalid {
		return fmt.Errorf("object schema nesting mode is invalid")
	}

	for name, attrS := range o.Attributes {
		if attrS == nil {
			err = errors.Join(err, fmt.Errorf("%s: attribute schema is nil", name))
			continue
		}
		err = errors.Join(err, attrS.internalValidate(name, ""))
	}

	return err
}

View on GitHub (pinned to d32a084675)