hashicorp/terraform · critical

resource has an unsupported mode

Error message

resource %s has an unsupported mode %s

What it means

Thrown by marshalResources when a configured resource's Mode is neither addrs.ManagedResourceMode nor addrs.DataResourceMode. The resource address and the unexpected mode string are included. This indicates an internal/state divergence: the configs layer should only ever produce managed or data resources.

Solutions

  1. Report as a Terraform bug with the config and version, since HCL authoring cannot produce other modes.
  2. Ensure you are running a released, mutually-consistent Terraform build (not a partial custom build).
  3. Remove recently added custom patches to addrs/configs and use official binaries.
Defensive patterns

Strategy: type-guard

Validate before calling

// Guard before marshaling: only marshal known modes.
func supportedMode(m addrs.ResourceMode) bool {
    return m == addrs.ManagedResourceMode || m == addrs.DataResourceMode
}

Type guard

func isValidResourceMode(m addrs.ResourceMode) bool {
    return m == addrs.ManagedResourceMode || m == addrs.DataResourceMode
}

Prevention

When it happens

Trigger: A resource in the loaded configuration carries a mode value outside the two valid cases. In practice unreachable through HCL authoring; would arise from a programmatic/buggy config load or an internal addrs package change introducing a new mode not handled here.

Common situations: Terraform internal bug; mismatched versions between addrs and configs packages; custom builds that extend ResourceMode without updating marshalResources.

Related errors


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

Appendix: source

Thrown at internal/command/jsonconfig/config.go:488

func marshalResources(resources map[string]*configs.Resource, schemas *terraform.Schemas, moduleAddr string) ([]resource, error) {
	var rs []resource
	for _, v := range resources {
		providerConfigKey := opaqueProviderKey(v.ProviderConfigAddr().StringCompact(), moduleAddr)
		r := resource{
			Address:           v.Addr().String(),
			Type:              v.Type,
			Name:              v.Name,
			ProviderConfigKey: providerConfigKey,
		}

		switch v.Mode {
		case addrs.ManagedResourceMode:
			r.Mode = "managed"
		case addrs.DataResourceMode:
			r.Mode = "data"
		default:
			return rs, fmt.Errorf("resource %s has an unsupported mode %s", r.Address, v.Mode.String())
		}

		cExp := marshalExpression(v.Count)
		if !cExp.Empty() {
			r.CountExpression = &cExp
		} else {
			fExp := marshalExpression(v.ForEach)
			if !fExp.Empty() {
				r.ForEachExpression = &fExp
			}
		}

		schema := schemas.ResourceTypeConfig(
			v.Provider,
			v.Mode,
			v.Type,
		)
		if schema.Body == nil {

View on GitHub (pinned to d32a084675)