{"record":{"id":"f1775a5f536cab69","repo":"hashicorp/terraform","slug":"s-s-nestinggroup-blocks-cannot-be-computed","errorCode":null,"errorMessage":"%s%s: NestingGroup blocks cannot be computed","messagePattern":"(.+?)(.+?): NestingGroup blocks cannot be computed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":86,"sourceCode":"\t\t// any nested blocks within a computed block must also be computed\n\t\tif b.Computed && !blockS.Computed {\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: all nested blocks within computed blocks must also be computed\", prefix, name))\n\t\t}\n\n\t\tswitch blockS.Nesting {\n\t\tcase NestingSingle:\n\t\t\tswitch {\n\t\t\tcase blockS.MinItems != blockS.MaxItems:\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems and MaxItems must match in NestingSingle mode\", prefix, name))\n\t\t\tcase blockS.MinItems < 0 || blockS.MinItems > 1:\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode\", prefix, name))\n\t\t\t}\n\t\tcase NestingGroup:\n\t\t\tif blockS.MinItems != 0 || blockS.MaxItems != 0 {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems and MaxItems cannot be used in NestingGroup mode\", prefix, name))\n\t\t\t}\n\t\t\tif blockS.Computed {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: NestingGroup blocks cannot be computed\", prefix, name))\n\t\t\t}\n\t\tcase NestingList, NestingSet:\n\t\t\tif blockS.MinItems > blockS.MaxItems && blockS.MaxItems != 0 {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: MinItems must be less than or equal to MaxItems in %s mode\", prefix, name, blockS.Nesting))\n\t\t\t}\n\t\t\tif blockS.Nesting == NestingSet {\n\t\t\t\tety := blockS.Block.ImpliedType()\n\t\t\t\tif ety.HasDynamicTypes() {\n\t\t\t\t\t// This is not permitted because the HCL (cty) set implementation\n\t\t\t\t\t// needs to know the exact type of set elements in order to\n\t\t\t\t\t// properly hash them, and so can't support mixed types.\n\t\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: NestingSet blocks may not contain attributes of cty.DynamicPseudoType\", prefix, name))\n\t\t\t\t}\n\t\t\t\tif blockS.Block.ContainsWriteOnly() {\n\t\t\t\t\t// This is not permitted because any marks within sets will\n\t\t\t\t\t// be hoisted up the outer set value, so only the set itself\n\t\t\t\t\t// can be WriteOnly.\n\t\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: NestingSet blocks may not contain WriteOnly attributes\", prefix, name))","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L68-L104","documentation":"Raised when a nested block declared with NestingGroup mode also has Computed=true. NestingGroup is intended to model an always-present feature group whose attributes take default values when the block is omitted; because the group is never null and never user-supplied en bloc, marking it Computed is meaningless and contradicts the semantic contract of the mode. The validator at internal_validate.go:86 rejects this combination so providers cannot construct a self-contradictory schema. Use NestingSingle or an attribute with NestedType if the value truly comes from the provider.","triggerScenarios":"A provider schema defines a NestedBlock with Nesting: NestingGroup and simultaneously sets Computed: true on the same NestedBlock struct (the embedded Block.Computed field). InternalValidate walks BlockTypes, hits the NestingGroup case at line 81, and emits this error when blockS.Computed is true at line 85.","commonSituations":"Migrating a block from NestingSingle/NestingList to NestingGroup while leaving an old Computed=true flag set; copying a schema struct verbatim and changing only the Nesting field; modeling a remote API response that is always present but forgetting NestingGroup already guarantees non-null presence.","solutions":["Remove Computed: true from the NestingGroup NestedBlock; the mode already guarantees the block is non-null with defaulted attributes.","If the value must be provider-computed, switch Nesting to NestingSingle (single computed object) or replace the block with an Attribute whose NestedType is an Object.","Search the schema definition for the offending block name and confirm only the intended flags remain after the migration."],"exampleFix":"// before\nBlockTypes: map[string]*NestedBlock{\n    \"settings\": {Nesting: NestingGroup, Block: Block{Computed: true, Attributes: ...}},\n}\n\n// after\nBlockTypes: map[string]*NestedBlock{\n    \"settings\": {Nesting: NestingGroup, Block: Block{Attributes: ...}},\n}","handlingStrategy":"validation","validationCode":"// before registering the schema, assert NestingGroup blocks are not Computed\nfunc validateGroupBlocks(b *configschema.Block) error {\n    for name, nb := range b.BlockTypes {\n        if nb == nil { continue }\n        if nb.Nesting == configschema.NestingGroup && nb.Computed {\n            return fmt.Errorf(\"%s: NestingGroup cannot be Computed\", name)\n        }\n        if err := validateGroupBlocks(&nb.Block); err != nil { return err }\n    }\n    return nil\n}","typeGuard":"func isComputedGroup(nb *configschema.NestedBlock) bool {\n    return nb != nil && nb.Nesting == configschema.NestingGroup && nb.Computed\n}","tryCatchPattern":null,"preventionTips":["Call Block.InternalValidate() in provider TestProvider and unit tests so invalid schemas fail at test time, not runtime.","When migrating a block's Nesting mode, always re-audit every other field on the NestedBlock (Computed, MinItems, MaxItems) for compatibility with the new mode.","Keep a schema-construction helper per nesting mode so incompatible flag combinations cannot be expressed."],"tags":["configschema","nesting-group","computed","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}