{"record":{"id":"f6eb9c3356be11c8","repo":"hashicorp/terraform","slug":"can-t-serialize-backend-configuration-as-json-s","errorCode":null,"errorMessage":"Can't serialize backend configuration as JSON: %s","messagePattern":"Can't serialize backend configuration as JSON: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":1795,"sourceCode":"\t\tif err := stateLocker.Lock(sMgr, \"backend from plan\"); err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"Error locking state: %s\", err))\n\t\t\treturn nil, diags\n\t\t}\n\t\tdefer stateLocker.Unlock()\n\t}\n\n\t// Store the metadata in our saved state location\n\ts := sMgr.State()\n\tif s == nil {\n\t\ts = workdir.NewBackendStateFile()\n\t}\n\ts.Backend = &workdir.BackendConfigState{\n\t\tType: c.Type,\n\t\tHash: uint64(cHash),\n\t}\n\terr := s.Backend.SetConfig(configVal, b.ConfigSchema())\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Can't serialize backend configuration as JSON: %s\", err))\n\t\treturn nil, diags\n\t}\n\n\t// Verify that selected workspace exists in the backend.\n\tif opts.Init && b != nil {\n\t\terr := m.selectWorkspace(b)\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(err)\n\n\t\t\t// FIXME: A compatibility oddity with the 'remote' backend.\n\t\t\t// As an awkward legacy UX, when the remote backend is configured and there\n\t\t\t// are no workspaces, the output to the user saying that there are none and\n\t\t\t// the user should create one with 'workspace new' takes the form of an\n\t\t\t// error message - even though it's happy path, expected behavior.\n\t\t\t//\n\t\t\t// Therefore, only return nil with errored diags for everything else, and\n\t\t\t// allow the remote backend to continue and write its configuration to state\n\t\t\t// even though no workspace is selected.","sourceCodeStart":1777,"sourceCodeEnd":1813,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L1777-L1813","documentation":"In Meta.backend_C_r_s (meta_backend.go:1795), after locking, Terraform calls BackendConfigState.SetConfig(configVal, b.ConfigSchema()) to serialize the decoded backend config value into JSON for storage in the workdir-state file. If SetConfig fails, the config value cannot be represented against the backend's schema as JSON. This usually points to a backend-implementation schema bug or an unsupported value type rather than a user typo.","triggerScenarios":"A custom or built-in backend whose ConfigSchema does not faithfully describe the values it accepts, so the cty.Value round-trips through JSON encoding with an error; an exotic/sensitive value type the schema/JSON marshaler cannot handle.","commonSituations":"Using a backend plugin/binary with a schema bug; a regression after upgrading the Terraform binary or a backend-specific dependency.","solutions":["Read the wrapped `%s`; if it names a JSON/cty type error, the backend's schema is the culprit, not your HCL.","Simplify the backend block to isolate which argument triggers serialization failure.","Verify the backend type/version is supported by your Terraform version; downgrade/upgrade if a regression is suspected.","Report the schema bug to the backend maintainer (or Terraform core for built-in backends) with the block and error."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate the backend config value round-trips through its schema JSON before init writes it.\nfunc backendConfigSerializes(b backend.Backend, val cty.Value) error {\n    st := &workdir.BackendConfigState{Type: \"x\"}\n    return st.SetConfig(val, b.ConfigSchema())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin a known-good Terraform and backend version pair in CI.","Keep backend blocks simple and avoid exotic/sensitive types the schema may not serialize.","Test backend reconfiguration in a scratch workdir before applying to a real environment.","Report backend schema defects upstream rather than working around them."],"tags":["backend","schema","json","serialization","init"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}