{"record":{"id":"7aaeff8c96a53d15","repo":"hashicorp/terraform","slug":"could-not-interpret-value-v-as-type-s-for-output","errorCode":null,"errorMessage":"could not interpret value %v as type %s for output %s: %w","messagePattern":"could not interpret value (.+?) as type (.+?) for output (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/state.go","lineNumber":678,"sourceCode":"\n// tfeOutputToCtyValue decodes a combination of TFE output value and detailed-type to create a\n// cty value that is suitable for use in terraform.\nfunc tfeOutputToCtyValue(output tfe.StateVersionOutput) (cty.Value, error) {\n\tvar result cty.Value\n\tbufType, err := json.Marshal(output.DetailedType)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"could not marshal output %s type: %w\", output.ID, err)\n\t}\n\n\tvar ctype cty.Type\n\terr = ctype.UnmarshalJSON(bufType)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"could not interpret output %s type: %w\", output.ID, err)\n\t}\n\n\tresult, err = gocty.ToCtyValue(output.Value, ctype)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"could not interpret value %v as type %s for output %s: %w\", result, ctype.FriendlyName(), output.ID, err)\n\t}\n\n\treturn result, nil\n}\n","sourceCodeStart":660,"sourceCodeEnd":683,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/cloud/state.go#L660-L683","documentation":"Thrown inside tfeOutputToCtyValue as the final conversion step when gocty.ToCtyValue cannot coerce the output's stored Value into the interpreted cty type. This means the type was parsed successfully (537 passed) but the actual value does not fit — for example a string value where a number type is declared, or a null where a non-nullable type is expected. The %w wraps the gocty error and includes the value, type, and output ID for diagnosis.","triggerScenarios":"The stored output value and its declared type disagree (data/type mismatch); a null value for a type that does not permit null; a number value stored as a JSON string but typed as number in a way gocty rejects; schema drift between the value the provider produced and the type recorded in state.","commonSituations":"Provider version change that altered an output's value encoding without updating the recorded type; manual state edits that changed a value but not its type; state written by one provider version read by another with different nullability semantics.","solutions":["Review the TF_LOG output to see the mismatched value and type for the named output","Correct the output in configuration or re-run apply with a consistent provider version to rewrite the state","If the state is corrupted, use terraform taint/replace on the resource producing the output, or manually fix via state pull/push","Pin the provider to the version that originally wrote the state to read it, then upgrade in a controlled manner"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate value-type consistency before conversion:\nbufType, _ := json.Marshal(output.DetailedType)\nvar t cty.Type\n_ = t.UnmarshalJSON(bufType)\nif _, err := gocty.ToCtyValue(output.Value, t); err != nil {\n    log.Printf(\"[WARN] output %s value does not match type %s: %v\", output.ID, t.FriendlyName(), err)\n}","typeGuard":null,"tryCatchPattern":"_, err := state.GetRootOutputValues(ctx)\nif err != nil && strings.Contains(err.Error(), \"could not interpret value\") {\n    // value/type mismatch in the stored state; the output needs to be rewritten\n    return fmt.Errorf(\"state output value/type mismatch; re-apply to rewrite state: %w\", err)\n}","preventionTips":["Pin provider versions to avoid output schema/value drift across upgrades","After provider upgrades, run apply on a staging workspace to rewrite state with consistent types","Avoid manual state edits that change values without updating their recorded types"],"tags":["outputs","cty","type-mismatch","value-coercion","tfe","terraform"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}