{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/configs/configschema/internal_validate.go#L27-L63","documentation":"A Block has Computed set to true (the entire block is computed/derived), but one of its Attributes has Computed set to false. Terraform's consistency rule requires that if a block is computed, every attribute within it must also be computed — otherwise the schema is contradictory about whether values are user-settable.","triggerScenarios":"Block.Computed == true but an attribute within it has Computed == false (and is not also Optional, depending on interpretation). Triggered during NewContext schema validation when a provider defines a computed nested block with user-settable fields inside.","commonSituations":"Provider developer marks a block as Computed (read-only, server-assigned) but forgets to mark individual attributes as Computed too. Migration from terraform-plugin-sdk where Computed semantics propagate differently. Schema was partially refactored — the block-level flag was set but attributes weren't updated. Misunderstanding of the computed-propagation rule.","solutions":["Mark every attribute inside the computed block as Computed: true.","Alternatively, if the block should allow user input, remove Computed: true from the block itself.","Review the provider schema definition for the resource/data source and ensure consistency between block-level and attribute-level Computed flags.","Add a unit test calling InternalValidate() to catch schema inconsistencies early."],"exampleFix":"// before — computed block with non-computed attribute\n&Block{\n    Computed: true,\n    Attributes: map[string]*Attribute{\n        \"value\": {Type: String, Optional: true},  // ← not Computed\n    },\n}\n\n// after — attribute also computed\n&Block{\n    Computed: true,\n    Attributes: map[string]*Attribute{\n        \"value\": {Type: String, Computed: true},\n    },\n}","handlingStrategy":"validation","validationCode":"// Provider developers: enforce computed-propagation rule\nfunc enforceComputedConsistency(b *configschema.Block) error {\n    if !b.Computed {\n        return nil\n    }\n    for name, attr := range b.Attributes {\n        if attr != nil && !attr.Computed {\n            return fmt.Errorf(\"attribute %q must be Computed because parent block is Computed\", name)\n        }\n    }\n    return nil\n}\n\n// Unit test gate:\nfunc TestComputedBlockConsistency(t *testing.T) {\n    if err := myResourceSchema().InternalValidate(); err != nil {\n        t.Fatal(err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When marking a block as Computed, audit every attribute inside it and set Computed: true.","Add InternalValidate() to provider test suites.","Document the computed-propagation rule in your provider contribution guide."],"tags":["schema","validation","provider-development","computed","attributes","internal"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}