{"record":{"id":"3c9d538e90a8e96e","repo":"kubernetes/kops","slug":"duplicate-resource-found-s-s","errorCode":null,"errorMessage":"duplicate resource found: %s.%s","messagePattern":"duplicate resource found: (.+?)\\.(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/terraformWriter/writer.go","lineNumber":245,"sourceCode":"\t}\n\n\treturn dataSourcesByType, nil\n}\n\nfunc (t *TerraformWriter) GetResourcesByType() (map[string]map[string]interface{}, error) {\n\tresourcesByType := make(map[string]map[string]interface{})\n\n\tfor _, res := range t.resources {\n\t\tresources := resourcesByType[res.ResourceType]\n\t\tif resources == nil {\n\t\t\tresources = make(map[string]interface{})\n\t\t\tresourcesByType[res.ResourceType] = resources\n\t\t}\n\n\t\ttfName := sanitizeName(res.ResourceName)\n\n\t\tif resources[tfName] != nil {\n\t\t\treturn nil, fmt.Errorf(\"duplicate resource found: %s.%s\", res.ResourceType, tfName)\n\t\t}\n\n\t\tresources[tfName] = res.Item\n\t}\n\n\treturn resourcesByType, nil\n}\n\nfunc (t *TerraformWriter) GetOutputs() (map[string]OutputValue, error) {\n\tvalues := map[string]OutputValue{}\n\tfor _, v := range t.outputs {\n\t\ttfName := sanitizeName(v.Key)\n\t\tif _, found := values[tfName]; found {\n\t\t\treturn nil, fmt.Errorf(\"duplicate variable found: %s\", tfName)\n\t\t}\n\t\tdeduped, err := dedupLiterals(v.ValueArray)\n\t\tif err != nil {\n\t\t\treturn nil, err","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/terraformWriter/writer.go#L227-L263","documentation":"GetResourcesByType groups rendered TerraformResource items by resource type, keyed by sanitized resource name. Terraform requires unique resource names within a type, so a second resource with the same type and name is rejected with this error during HCL2 finishing. This prevents emitting a Terraform config with duplicate resource blocks.","triggerScenarios":"Two cluster objects render resources with the same (ResourceType, ResourceName) pair — e.g. two security groups or IAM roles producing identical sanitized names, or names that collide after sanitizeName.","commonSituations":"Duplicate resources in the cluster spec (e.g. two instance groups with names that sanitize identically); a kOps builder bug registering the same resource twice; name collisions after sanitization strips distinguishing characters.","solutions":["Rename the conflicting kOps objects (e.g. instance groups) so their Terraform names differ.","Check the cluster spec for duplicated resources causing double registration.","If names collide only after sanitization, shorten/adjust names to stay unique post-sanitize.","Update kOps and/or file an upstream issue with the duplicate `<type>.<name>` from the message."],"exampleFix":"// before\nname: nodes.a\nname: nodes.a   # duplicate -> aws_security_group.nodes-a\n// after\nname: nodes-a\nname: nodes-b","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\ntfName := sanitizeName(res.ResourceName)\nif seen[res.ResourceType+\".\"+tfName] {\n    return fmt.Errorf(\"resource %s.%s would be registered twice\", res.ResourceType, tfName)\n}\nseen[res.ResourceType+\".\"+tfName] = true","typeGuard":null,"tryCatchPattern":"resByType, err := w.GetResourcesByType()\nif err != nil {\n    return fmt.Errorf(\"building terraform resources failed: %w\", err)\n}","preventionTips":["Give kOps objects unique names so sanitized Terraform names stay unique.","Deduplicate resource registrations in builders.","Verify no duplicate resources exist in the cluster spec.","Report the duplicate `<type>.<name>` from the message when it occurs on stock specs."],"tags":["terraform","resources","kops","internal"],"backgroundTag":"duplicate-terraform-name","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}