hashicorp/terraform · error

preparing attribute values for %s: %w

Error message

preparing attribute values for %s: %w

What it means

Wraps an error from marshalAttributeValues while serializing the current (non-deposed) resource instance's attributes in state. The %w carries the underlying cause (typically a value that cannot be marshaled, e.g. an unserializable cty mark). The message identifies which resource's attributes failed so the offending instance can be located.

Source

Thrown at internal/command/jsonstate/state.go:452

					}

					if schema.Identity == nil {
						return nil, fmt.Errorf("no resource identity schema found for %s (in provider %s)", resAddr.String(), r.ProviderConfig.Provider)
					}

					current.IdentitySchemaVersion = &ri.Current.IdentitySchemaVersion
				}

				riObj, err := ri.Current.Decode(schema)
				if err != nil {
					return nil, err
				}

				var value cty.Value
				var sensitivePaths []cty.Path
				value, current.AttributeValues, sensitivePaths, err = marshalAttributeValues(riObj.Value)
				if err != nil {
					return nil, fmt.Errorf("preparing attribute values for %s: %w", current.Address, err)
				}
				sensitivePaths = append(sensitivePaths, schema.Body.SensitivePaths(value, nil)...)
				s := SensitiveAsBool(marks.MarkPaths(value, marks.Sensitive, sensitivePaths))
				v, err := ctyjson.Marshal(s, s.Type())
				if err != nil {
					return nil, err
				}
				current.SensitiveValues = v

				current.IdentityValues, err = marshalIdentityValues(riObj.Identity)
				if err != nil {
					return nil, fmt.Errorf("preparing identity values for %s: %w", current.Address, err)
				}

				if len(riObj.Dependencies) > 0 {
					dependencies := make([]string, len(riObj.Dependencies))
					for i, v := range riObj.Dependencies {
						dependencies[i] = v.String()

View on GitHub (pinned to c9def3e214)

Solutions

  1. Read the wrapped (%w) error text — it identifies the real cause (e.g. 'cannot serialize value marked as ...').
  2. Upgrade Terraform Core and the relevant provider; unsupported marks are usually internal bugs fixed in newer releases.
  3. If tied to one resource, `terraform state rm` it and re-import/re-apply to rewrite a clean object.
  4. Restore state from terraform.tfstate.backup if the corruption was introduced recently.
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := jsonstate.MarshalCurrentAttributes(riObj); err != nil {
    // Read the wrapped cause; if it's an unserializable mark, treat as internal bug and skip the instance.
    return fmt.Errorf("attribute serialization failed for %s: %w", addr, err)
}

Prevention

When it happens

Trigger: Raised in jsonstate when marshalAttributeValues(riObj.Value) returns a non-nil error for the current instance. Commonly the inner error is the unmarkValueForMarshaling failure (cannot serialize a value marked with an unrecognized mark) or a cty JSON marshal failure.

Common situations: Most often a downstream symptom of error 632 (unsupported cty mark in state). Also occurs with provider bugs that produce non-serializable values, or after partial state corruption. Triggered by any JSON state/plan rendering command.

Related errors


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