{"record":{"id":"d2ee47ba428ac494","repo":"hashicorp/terraform","slug":"s-s-all-attributes-within-computed-blocks-must-a","errorCode":null,"errorMessage":"%s%s: all attributes within computed blocks must also be computed","messagePattern":"(.+?)(.+?): all attributes within computed blocks must also be computed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":45,"sourceCode":"}\n\nfunc (b *Block) internalValidate(prefix string) error {\n\tvar multiErr error\n\n\tif prefix == \"\" && !b.Deprecated && b.DeprecationMessage != \"\" {\n\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"top-level block: DeprecationMessage must not be set when Deprecated is false\"))\n\t}\n\n\tfor name, attrS := range b.Attributes {\n\t\tif attrS == nil {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: attribute schema is nil\", prefix, name))\n\t\t\tcontinue\n\t\t}\n\t\tmultiErr = errors.Join(multiErr, attrS.internalValidate(name, prefix))\n\n\t\t// all attributes within a computed block must also be computed\n\t\tif b.Computed && !attrS.Computed {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: all attributes within computed blocks must also be computed\", prefix, name))\n\t\t}\n\t}\n\n\tfor name, blockS := range b.BlockTypes {\n\t\tif blockS == nil {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: block schema is nil\", prefix, name))\n\t\t\tcontinue\n\t\t}\n\n\t\tif _, isAttr := b.Attributes[name]; isAttr {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: name defined as both attribute and child block type\", prefix, name))\n\t\t} else if !validName.MatchString(name) {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: name may contain only lowercase letters, digits and underscores\", prefix, name))\n\t\t}\n\t\tif !blockS.Deprecated && blockS.DeprecationMessage != \"\" {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: DeprecationMessage must not be set when Deprecated is false\", prefix, name))\n\t\t}\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L27-L63","documentation":"When a Block has Computed=true, every Attribute inside it must also be Computed (checked at lines 44-46), because a provider-supplied (computed) block cannot contain user-mutable fields. The validator iterates each attribute and appends this error if attrS.Computed is false while the parent block is computed.","triggerScenarios":"Marking a nested block Computed = true (typical for data-source/ephemeral/object attributes) but leaving one of its attributes as Optional-only or Required.","commonSituations":"Converting a config block to a computed output, framework migration where object attributes weren't all marked computed, partially-computed nested objects.","solutions":["Set Computed = true on every attribute inside the computed block.","If the attribute is genuinely user-settable, the parent block must not be Computed - move it out or drop Computed on the block."],"exampleFix":"// before\n&configschema.Block{\n    Computed: true,\n    Attributes: map[string]*configschema.Attribute{\n        \"id\":   {Type: cty.String, Computed: true},\n        \"name\": {Type: cty.String, Optional: true},  // illegal under Computed block\n    },\n}\n\n// after\n&configschema.Block{\n    Computed: true,\n    Attributes: map[string]*configschema.Attribute{\n        \"id\":   {Type: cty.String, Computed: true},\n        \"name\": {Type: cty.String, Computed: true},\n    },\n}","handlingStrategy":"validation","validationCode":"// Enforce: all attributes of a computed block are computed.\nif block.Computed {\n    for n, a := range block.Attributes {\n        if a != nil && !a.Computed { return fmt.Errorf(\"%s must be computed under a Computed block\", n) }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When flipping a block to Computed, audit every child attribute and set Computed on each.","Keep computed-output blocks fully computed; don't mix user-settable fields in."],"tags":["configschema","provider-sdk","computed","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}