{"record":{"id":"afcc5a4e95522502","repo":"hashicorp/terraform","slug":"preparing-identity-values-for-s-w","errorCode":null,"errorMessage":"preparing identity values for %s: %w","messagePattern":"preparing identity values for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/jsonstate/state.go","lineNumber":464,"sourceCode":"\t\t\t\t}\n\n\t\t\t\tvar value cty.Value\n\t\t\t\tvar sensitivePaths []cty.Path\n\t\t\t\tvalue, current.AttributeValues, sensitivePaths, err = marshalAttributeValues(riObj.Value)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"preparing attribute values for %s: %w\", current.Address, err)\n\t\t\t\t}\n\t\t\t\tsensitivePaths = append(sensitivePaths, schema.Body.SensitivePaths(value, nil)...)\n\t\t\t\ts := SensitiveAsBool(marks.MarkPaths(value, marks.Sensitive, sensitivePaths))\n\t\t\t\tv, err := ctyjson.Marshal(s, s.Type())\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tcurrent.SensitiveValues = v\n\n\t\t\t\tcurrent.IdentityValues, err = marshalIdentityValues(riObj.Identity)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"preparing identity values for %s: %w\", current.Address, err)\n\t\t\t\t}\n\n\t\t\t\tif len(riObj.Dependencies) > 0 {\n\t\t\t\t\tdependencies := make([]string, len(riObj.Dependencies))\n\t\t\t\t\tfor i, v := range riObj.Dependencies {\n\t\t\t\t\t\tdependencies[i] = v.String()\n\t\t\t\t\t}\n\t\t\t\t\tcurrent.DependsOn = dependencies\n\t\t\t\t}\n\n\t\t\t\tif riObj.Status == states.ObjectTainted {\n\t\t\t\t\tcurrent.Tainted = true\n\t\t\t\t}\n\t\t\t\tret = append(ret, current)\n\t\t\t}\n\n\t\t\tfor _, deposedKey := range slices.Sorted(maps.Keys(ri.Deposed)) {\n\t\t\t\trios := ri.Deposed[states.DeposedKey(deposedKey)]","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/jsonstate/state.go#L446-L482","documentation":"Thrown by jsonstate right after the attribute-values step: marshalIdentityValues(riObj.Identity) failed and the error is wrapped with the resource address. It means the resource's identity cty value could not be converted to the JSON identity representation, usually because the identity value's type disagrees with the identity schema or it is malformed.","triggerScenarios":"Identity value decoded with a schema whose shape differs from the stored bytes; identity value carries marks/types marshalIdentityValues rejects; provider identity schema/value mismatch after a version change.","commonSituations":"Provider upgrade changing identity shape without a matching identity-schema-version bump; corrupt identity bytes in state; forked provider with divergent identity handling.","solutions":["Run `terraform apply -refresh-only` to refresh identity from the provider.","Align the provider version with the state's identity schema.","Examine the wrapped (%w) error for the specific marshal failure.","Clear or repair the identity entry via `terraform state pull`/edit/`push` if it is corrupt."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := jsonstate.Marshal(state, schemas); err != nil {\n    if strings.Contains(err.Error(), \"preparing identity values\") {\n        log.Printf(\"identity marshal failed for a resource; run 'terraform apply -refresh-only' or align provider version: %v\", err)\n    }\n    return err\n}","preventionTips":["After any provider identity-schema change, refresh state to recompute identity values.","Inspect the wrapped error to identify the identity field that failed.","Avoid carrying identity-bearing state across provider versions that disagree on identity shape."],"tags":["terraform","json-state","identity","serialization","cty"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}