{"record":{"id":"26e49e9077e30a1c","repo":"hashicorp/terraform","slug":"s-s-cannot-set-both-computed-and-required","errorCode":null,"errorMessage":"%s%s: cannot set both Computed and Required","messagePattern":"(.+?)(.+?): cannot set both Computed and Required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":153,"sourceCode":"\treturn a.internalValidate(name, \"\")\n}\n\nfunc (a *Attribute) internalValidate(name, prefix string) error {\n\tvar err error\n\n\t/* FIXME: this validation breaks certain existing providers and cannot be enforced without coordination.\n\tif !validName.MatchString(name) {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: name may contain only lowercase letters, digits and underscores\", prefix, name))\n\t}\n\t*/\n\tif !a.Optional && !a.Required && !a.Computed {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: must set Optional, Required or Computed\", prefix, name))\n\t}\n\tif a.Optional && a.Required {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: cannot set both Optional and Required\", prefix, name))\n\t}\n\tif a.Computed && a.Required {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: cannot set both Computed and Required\", prefix, name))\n\t}\n\tif !a.Deprecated && a.DeprecationMessage != \"\" {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: DeprecationMessage must not be set when Deprecated is false\", prefix, name))\n\t}\n\n\tif a.Type == cty.NilType && a.NestedType == nil {\n\t\terr = errors.Join(err, fmt.Errorf(\"%s%s: either Type or NestedType must be defined\", prefix, name))\n\t}\n\n\tif a.Type != cty.NilType {\n\t\tif a.NestedType != nil {\n\t\t\terr = errors.Join(fmt.Errorf(\"%s: Type and NestedType cannot both be set\", name))\n\t\t}\n\t}\n\n\tif a.NestedType != nil {\n\t\tswitch a.NestedType.Nesting {\n\t\tcase NestingSingle, NestingMap, NestingGroup:","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L135-L171","documentation":"Raised when an Attribute has both Computed and Required set. Required forces the user to supply a value; Computed means the provider supplies it. The two are logically incompatible because the value cannot be both user-mandatory and provider-derived. The validator at internal_validate.go:152 rejects the combination.","triggerScenarios":"An Attribute struct literal with Computed: true and Required: true. internalValidate reaches line 152 and the condition holds.","commonSituations":"Marking a field Computed to surface provider defaults while leaving an old Required flag; merging schemas where one side set Required and the other set Computed; misunderstanding Computed as 'has a default'.","solutions":["If the provider supplies the value, drop Required and keep Computed (optionally add Optional for user override).","If the user must supply the value, drop Computed and keep Required.","For 'provider default the user may override', use Optional+Computed, never Required+Computed."],"exampleFix":"// before\n\"id\": {Type: cty.String, Required: true, Computed: true}\n\n// after\n\"id\": {Type: cty.String, Optional: true, Computed: true}","handlingStrategy":"validation","validationCode":"func assertNotComputedAndRequired(a *configschema.Attribute) error {\n    if a.Computed && a.Required {\n        return fmt.Errorf(\"cannot set both Computed and Required\")\n    }\n    return nil\n}","typeGuard":"func isNotComputedRequired(a *configschema.Attribute) bool {\n    return !(a.Computed && a.Required)\n}","tryCatchPattern":null,"preventionTips":["Required means user-must-supply; Computed means provider-supplies — they cannot coexist.","For provider-overridable values use Optional+Computed.","Add a linter rule rejecting Computed && Required on attributes."],"tags":["configschema","attribute","computed","required","mutual-exclusion","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}