hashicorp/terraform · error

attribute %q not found

Error message

attribute %q not found

What it means

Returned by pathFromFlatmapKeyObject (paths.go:115) when the first dot-separated segment of a flatmap key does not match any attribute name in the object's attribute-types map. This means the flatmap key references an attribute that the schema does not declare — a structural mismatch between the key space and the type being decoded.

Source

Thrown at internal/configs/hcl2shim/paths.go:115

func pathSplit(p string) (string, string) {
	parts := strings.SplitN(p, ".", 2)
	head := parts[0]
	rest := ""
	if len(parts) > 1 {
		rest = parts[1]
	}
	return head, rest
}

func pathFromFlatmapKeyObject(key string, atys map[string]cty.Type) (cty.Path, error) {
	k, rest := pathSplit(key)

	path := cty.Path{cty.GetAttrStep{Name: k}}

	ty, ok := atys[k]
	if !ok {
		return path, fmt.Errorf("attribute %q not found", k)
	}

	if rest == "" {
		return path, nil
	}

	p, err := pathFromFlatmapKeyValue(rest, ty)
	if err != nil {
		return path, err
	}

	return append(path, p...), nil
}

func pathFromFlatmapKeyValue(key string, ty cty.Type) (cty.Path, error) {
	var path cty.Path
	var err error

View on GitHub (pinned to c9def3e214)

Solutions

  1. Look at the attribute name in the message; verify it exists in the current resource schema (it likely was renamed or removed).
  2. Perform a state migration to rename the attribute, or re-import the resource.
  3. Pin the provider version whose schema contains the attribute if a recent upgrade removed it.
  4. Audit the diff/RequiresReplace source to ensure only current-schema attribute keys are emitted.

Example fix

// before — key 'instnce_type' (typo) not in schema {'instance_type': ...}

// after — correct the flatmap key / state attribute name to 'instance_type'
Defensive patterns

Strategy: validation

Validate before calling

// Confirm every leading segment of a flatmap key exists in the schema
func keysExistInSchema(keys []string, atys map[string]cty.Type) []string {
    var missing []string
    for _, k := range keys {
        head, _, _ := strings.Cut(k, ".")
        if _, ok := atys[head]; !ok {
            missing = append(missing, head)
        }
    }
    return missing
}

Type guard

func attributeExists(name string, atys map[string]cty.Type) bool {
    _, ok := atys[name]
    return ok
}

Prevention

When it happens

Trigger: Converting a flatmap key (e.g. from a RequiresReplace diff or a diff path) into a cty.Path, where the leading segment is not present in ty.AttributeTypes(). The lookup `ty, ok := atys[k]` returns ok==false.

Common situations: Schema removed or renamed an attribute but state/diff still references the old name. A provider version change altered attribute names. Manually constructed flatmap keys with typos. Cross-provider state confusion.

Related errors


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