{"record":{"id":"701a743a71f11070","repo":"hashicorp/terraform","slug":"missing-field-in-set-s-s","errorCode":null,"errorMessage":"missing field in set: %s.%s","messagePattern":"missing field in set: (.+?)\\.(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/legacy/helper/schema/field_reader_diff.go","lineNumber":214,"sourceCode":"\t\tif !strings.HasPrefix(k, prefix) {\n\t\t\tcontinue\n\t\t}\n\t\tif strings.HasSuffix(k, \"#\") {\n\t\t\t// Ignore any count field\n\t\t\tcontinue\n\t\t}\n\n\t\t// Split the key, since it might be a sub-object like \"idx.field\"\n\t\tparts := strings.Split(k[len(prefix):], \".\")\n\t\tidx := parts[0]\n\n\t\traw, err := r.ReadField(append(address, idx))\n\t\tif err != nil {\n\t\t\treturn FieldReadResult{}, err\n\t\t}\n\t\tif !raw.Exists {\n\t\t\t// This shouldn't happen because we just verified it does exist\n\t\t\tpanic(\"missing field in set: \" + k + \".\" + idx)\n\t\t}\n\n\t\tset.Add(raw.Value)\n\t}\n\n\t// Determine if the set \"exists\". It exists if there are items or if\n\t// the diff explicitly wanted it empty.\n\texists := set.Len() > 0\n\tif !exists {\n\t\t// We could check if the diff value is \"0\" here but I think the\n\t\t// existence of \"#\" on its own is enough to show it existed. This\n\t\t// protects us in the future from the zero value changing from\n\t\t// \"0\" to \"\" breaking us (if that were to happen).\n\t\tif _, ok := r.Diff.Attributes[prefix+\"#\"]; ok {\n\t\t\texists = true\n\t\t}\n\t}\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/legacy/helper/schema/field_reader_diff.go#L196-L232","documentation":"A panic in `DiffFieldReader.readSet` (internal/legacy/helper/schema/field_reader_diff.go:214). While reconstructing a set from a diff, the reader iterates diff keys, reads each element via ReadField, and asserts the result `Exists`. If a key it just enumerated does not exist when re-read, it panics 'missing field in set: <key>.<idx>'. The comment notes 'This shouldn't happen because we just verified it does exist' — it is an internal consistency failure of the diff reader's own indexing.","triggerScenarios":"Applying/reading a diff that contains a set whose element keys were discovered via prefix scan but then resolve to non-existent fields on the nested ReadField call. Typically a symptom of a malformed diff, corrupted state, or a set element whose schema/hash changed between the plan and apply.","commonSituations":"Set element hashing changed (e.g. a provider altered the hash function / schema of a nested set block) so keys from the diff no longer map to existing fields; corrupted state with dangling set keys; race between concurrent state writes.","solutions":["Restore state from the most recent `.terraform.tfstate.backup` if state corruption is suspected.","Re-plan from a clean state to regenerate the diff consistently.","Ensure the provider version used for apply matches the one used for plan (set hashing must be stable across both).","Report a provider/Terraform bug if reproduced with matching versions and a fresh plan."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Go (provider): keep set element hashing stable across plan/apply\n// Ensure Schema.Hash or nested Elem schema is identical between the version\n// that planned and the version that applies; add a state migration on change.","typeGuard":null,"tryCatchPattern":"// Go: recover from the readSet consistency panic\ndefer func() {\n    if r := recover(); r != nil {\n        res = FieldReadResult{}\n        err = fmt.Errorf(\"set field consistency failure: %v; re-apply with a fresh plan\", r)\n    }\n}()\nres, err = r.readSet(address, schema)","preventionTips":["Use the same provider version for plan and apply so set hashing does not drift.","Restore from `.terraform.tfstate.backup` if state corruption is suspected.","Re-plan from clean state when a set schema changes.","Add state migrations whenever a nested set's schema/hash changes."],"tags":["terraform","provider-sdk","legacy-schema","field-reader","diff-reader","type-set","panic","state-corruption","internal-bug"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}