hashicorp/terraform · error
preparing identity values for %s: %w
Error message
preparing identity values for %s: %w
What it means
Wraps an error from marshalIdentityValues while serializing the current (non-deposed) resource instance's identity blob in state. The %w carries the underlying cause; the resource address is included so the failing instance can be identified. This is the identity counterpart of error 628.
Source
Thrown at internal/command/jsonstate/state.go:464
}
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()
}
current.DependsOn = dependencies
}
if riObj.Status == states.ObjectTainted {
current.Tainted = true
}
ret = append(ret, current)
}
for _, deposedKey := range slices.Sorted(maps.Keys(ri.Deposed)) {
rios := ri.Deposed[states.DeposedKey(deposedKey)]View on GitHub (pinned to c9def3e214)
Solutions
- Inspect the wrapped (%w) inner error to find the true serialization cause.
- Re-apply with the current provider so the identity blob is rewritten under the current schema.
- Upgrade Terraform Core and provider to versions with stable identity schema support.
- If unrecoverable, remove the resource from state and re-import to regenerate its identity data.
Defensive patterns
Strategy: try-catch
Try / catch
if _, err := jsonstate.MarshalIdentity(riObj.Identity); err != nil {
// Wrapped identity error — re-apply to rewrite identity under the current schema.
return err
} Prevention
- Re-apply after identity schema changes to keep identity blobs serializable.
- Inspect the wrapped (%w) cause before escalating.
- Pin provider versions during identity feature rollouts.
When it happens
Trigger: Raised in jsonstate when marshalIdentityValues(riObj.Identity) returns a non-nil error for the current instance. Triggered during JSON state rendering when a resource has identity data (ri.Current.IdentityJSON != nil) that fails to marshal/decode.
Common situations: Occurs when the identity value in state is malformed, has an unsupported cty mark, or the identity schema has changed shape. Often accompanies provider/identity schema migrations that did not run cleanly.
Related errors
- preparing attribute values for %s: %w
- %s: cannot serialize value marked as %#v for inclusion in a
- The builtin provider does not support provider upgrades sinc
- failed to read state: %w
- cannot serialize updated credentials file: %s
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/afcc5a4e95522502.
Report an issue: GitHub.