{"record":{"id":"e2b10d09a3593ff5","repo":"hashicorp/terraform","slug":"s-type-and-nestedtype-cannot-both-be-set","errorCode":null,"errorMessage":"%s: Type and NestedType cannot both be set","messagePattern":"(.+?): Type and NestedType cannot both be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configschema/internal_validate.go","lineNumber":165,"sourceCode":"\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:\n\t\t\t// no validations to perform\n\t\tcase NestingList, NestingSet:\n\t\t\tif a.NestedType.Nesting == NestingSet {\n\t\t\t\tety := a.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\terr = errors.Join(err, fmt.Errorf(\"%s%s: NestingSet attributes may not contain attributes of cty.DynamicPseudoType\", prefix, name))\n\t\t\t\t}\n\t\t\t\tif a.NestedType.ContainsWriteOnly() {\n\t\t\t\t\t// This is not permitted because any marks within sets will","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/configs/configschema/internal_validate.go#L147-L183","documentation":"Raised when an Attribute has both a flat Type and a NestedType set. The two are mutually exclusive representations: Type describes a primitive/collection value, NestedType describes a structural object. Setting both is ambiguous. The validator at internal_validate.go:163-164 detects Type != NilType together with NestedType != nil. Note the message omits the prefix (a minor formatting quirk: errors.Join is called without the prior err and without the prefix variable).","triggerScenarios":"An Attribute struct literal with both Type: cty.String and NestedType: &Object{...}. internalValidate reaches line 163 (Type is non-nil) and line 164 (NestedType is non-nil) and emits the error.","commonSituations":"Converting a flat attribute to a nested object and forgetting to clear Type; merging two schema fragments where one set Type and the other NestedType; copy-paste during refactoring.","solutions":["If the attribute should be structural, remove the Type field and keep NestedType.","If the attribute should be flat, remove the NestedType field and keep Type.","Add a linter rule that rejects Attributes where both Type and NestedType are set."],"exampleFix":"// before\n\"cfg\": {Type: cty.String, NestedType: &Object{Nesting: NestingSingle, Attributes: ...}, Optional: true}\n\n// after\n\"cfg\": {NestedType: &Object{Nesting: NestingSingle, Attributes: ...}, Optional: true}","handlingStrategy":"validation","validationCode":"func assertNotBothTypes(a *configschema.Attribute) error {\n    if a.Type != cty.NilType && a.NestedType != nil {\n        return fmt.Errorf(\"Type and NestedType cannot both be set\")\n    }\n    return nil\n}","typeGuard":"func hasSingleTypeRepresentation(a *configschema.Attribute) bool {\n    return !(a.Type != cty.NilType && a.NestedType != nil)\n}","tryCatchPattern":null,"preventionTips":["Pick one representation: flat Type or structural NestedType, never both.","When converting between the two, clear the other field in the same edit.","Lint to reject attributes where both Type and NestedType are populated."],"tags":["configschema","attribute","type","nestedtype","mutual-exclusion","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}