hashicorp/terraform · critical

Unknown type: %#v

Error message

Unknown type: %#v

What it means

Panics in MapFieldWriter.set (internal/legacy/helper/schema/field_writer_map.go:114). The switch over schema.Type handles TypeBool/TypeInt/TypeFloat/TypeString/TypeList/TypeMap/TypeSet/typeObject; the default branch panics, meaning schema.Type is not a recognized ValueType constant (most often TypeInvalid/0 because Type was never set).

Source

Thrown at internal/legacy/helper/schema/field_writer_map.go:114

	schemaList := addrToSchema(addr, w.Schema)
	if len(schemaList) == 0 {
		return fmt.Errorf("Invalid address to set: %#v", addr)
	}

	schema := schemaList[len(schemaList)-1]
	switch schema.Type {
	case TypeBool, TypeInt, TypeFloat, TypeString:
		return w.setPrimitive(addr, value, schema)
	case TypeList:
		return w.setList(addr, value, schema)
	case TypeMap:
		return w.setMap(addr, value, schema)
	case TypeSet:
		return w.setSet(addr, value, schema)
	case typeObject:
		return w.setObject(addr, value, schema)
	default:
		panic(fmt.Sprintf("Unknown type: %#v", schema.Type))
	}
}

func (w *MapFieldWriter) setList(
	addr []string,
	v interface{},
	schema *Schema) error {
	k := strings.Join(addr, ".")
	setElement := func(idx string, value interface{}) error {
		addrCopy := make([]string, len(addr), len(addr)+1)
		copy(addrCopy, addr)
		return w.set(append(addrCopy, idx), value)
	}

	var vs []interface{}
	if err := mapstructure.Decode(v, &vs); err != nil {
		return fmt.Errorf("%s: %s", k, err)
	}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Set Type on every Schema entry to one of the schema.Type* constants.
  2. Add a schema-validation pass in provider tests (or a Test() on each Resource) that asserts Type != TypeInvalid before exercising WriteField.
  3. Search the resource's Schema map for any entry with Type == 0.

Example fix

// before
"tags": { Elem: &schema.Schema{Type: schema.TypeString} },
// after
"tags": { Type: schema.TypeMap, Elem: &schema.Schema{Type: schema.TypeString} },
Defensive patterns

Strategy: validation

Validate before calling

func validValueType(t schema.ValueType) bool {
    switch t {
    case schema.TypeBool, schema.TypeInt, schema.TypeFloat, schema.TypeString,
        schema.TypeList, schema.TypeMap, schema.TypeSet:
        return true
    }
    return false
}
// assert before WriteField
for k, s := range resource.Schema {
    if !validValueType(s.Type) { panic("invalid Type on " + k) }
}

Type guard

func schemaTypeIsKnown(s *schema.Schema) bool { return s.Type != schema.TypeInvalid }

Prevention

When it happens

Trigger: Writing a field whose Schema has an unset or out-of-range Type (TypeInvalid), e.g. a provider schema entry missing the Type field, or a dynamically-built schema with an uninitialized Type. WriteField -> set -> default panic.

Common situations: Provider authors forgetting `Type:` on a schema entry, copy-paste mistakes, or schema maps assembled via reflection/composition that leave Type at its zero value.

Related errors


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