{"record":{"id":"8d0d958d6dee4727","repo":"hashicorp/terraform","slug":"s-s-computed-cannot-be-used-when-minitems-0","errorCode":null,"errorMessage":"%s%s: Computed cannot be used when MinItems > 0","messagePattern":"(.+?)(.+?): Computed cannot be used when MinItems > 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":108,"sourceCode":"\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))\n\t\t\t\t}\n\t\t\t}\n\t\t\tif blockS.MinItems > 0 && blockS.Computed {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: Computed cannot be used when MinItems > 0\", prefix, name))\n\t\t\t}\n\t\tcase NestingMap:\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 must both be 0 in NestingMap mode\", prefix, name))\n\t\t\t}\n\t\t\tif blockS.MinItems > 0 && blockS.Computed {\n\t\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: Computed cannot be used when MinItems > 0\", prefix, name))\n\t\t\t}\n\t\tdefault:\n\t\t\tmultiErr = errors.Join(multiErr, fmt.Errorf(\"%s%s: invalid nesting mode %s\", prefix, name, blockS.Nesting))\n\t\t}\n\n\t\tsubPrefix := prefix + name + \".\"\n\t\tmultiErr = errors.Join(multiErr, blockS.Block.internalValidate(subPrefix))\n\t}\n\n\treturn multiErr\n}","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L90-L126","documentation":"Raised for NestingList or NestingSet blocks when MinItems > 0 and Computed=true simultaneously. A non-zero minimum forces the user to supply that many blocks in config, which contradicts 'Computed' (provider-supplied). The validator at internal_validate.go:107 treats this as an unsatisfiable contract.","triggerScenarios":"A NestedBlock with Nesting=NestingList or NestingSet, MinItems >= 1, and Computed=true on the embedded Block. The shared NestingList/NestingSet case at line 88 reaches line 107 and the condition (MinItems > 0 && Computed) is true.","commonSituations":"Marking a required block Computed to signal provider-defaults while forgetting that MinItems already enforces presence; merging two schema fragments where one set MinItems and the other set Computed; copying a Computed block and bumping MinItems to 'require at least one'.","solutions":["Drop Computed=true and keep MinItems > 0 if the user must supply the block.","Drop MinItems to 0 (and keep Computed=true) if the provider may synthesize the collection.","If you need both provider-computed and user-supplied entries, split into two blocks or use Optional+Computed on individual attributes instead of the block."],"exampleFix":"// before\n&NestedBlock{Nesting: NestingList, MinItems: 1, Block: Block{Computed: true, Attributes: ...}}\n\n// after\n&NestedBlock{Nesting: NestingList, MinItems: 1, Block: Block{Attributes: ...}}","handlingStrategy":"validation","validationCode":"func assertNoComputedRequiredList(nb *configschema.NestedBlock) error {\n    if (nb.Nesting == configschema.NestingList || nb.Nesting == configschema.NestingSet) &&\n        nb.MinItems > 0 && nb.Computed {\n        return fmt.Errorf(\"Computed cannot be used when MinItems > 0\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["MinItems > 0 means user-must-supply; Computed means provider-supplies — pick one.","For provider-overridable collections, set MinItems=0 and keep Computed (or use Optional+Computed attributes).","Validate schemas in unit tests to catch contradictory flags."],"tags":["configschema","nesting-list","nesting-set","computed","minitems","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}