{"record":{"id":"9fd06703dbf8aa8c","repo":"kubernetes/kops","slug":"duplicate-data-source-found-s-s","errorCode":null,"errorMessage":"duplicate data source found: %s.%s","messagePattern":"duplicate data source found: (.+?)\\.(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/terraformWriter/writer.go","lineNumber":223,"sourceCode":"\tt.outputs[key].ValueArray = append(t.outputs[key].ValueArray, literal)\n\n\treturn nil\n}\n\nfunc (t *TerraformWriter) GetDataSourcesByType() (map[string]map[string]interface{}, error) {\n\tdataSourcesByType := make(map[string]map[string]interface{})\n\n\tfor _, dataSource := range t.dataSources {\n\t\tdataSources := dataSourcesByType[dataSource.DataType]\n\t\tif dataSources == nil {\n\t\t\tdataSources = make(map[string]interface{})\n\t\t\tdataSourcesByType[dataSource.DataType] = dataSources\n\t\t}\n\n\t\ttfName := sanitizeName(dataSource.DataName)\n\n\t\tif dataSources[tfName] != nil {\n\t\t\treturn nil, fmt.Errorf(\"duplicate data source found: %s.%s\", dataSource.DataType, tfName)\n\t\t}\n\n\t\tdataSources[tfName] = dataSource.Item\n\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","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/terraformWriter/writer.go#L205-L241","documentation":"GetDataSourcesByType builds a map of Terraform data sources grouped by type, keyed by sanitized data-source name. Terraform requires unique names within a data source type, so when two TerraformDataSource entries share the same type and sanitized name, this error is returned instead of emitting invalid config. It is called during HCL2 finishing of a Terraform target.","triggerScenarios":"Two resources rendered TerraformDataSource items with identical (DataType, DataName) — e.g. the same data source (like an AMI or VPC lookup) registered twice under the same name, or two different names that sanitize to the same string.","commonSituations":"A cluster spec feature enabled twice causing the same data-source lookup to be added twice; internal kOps bug where two renderers pick the same data name; long/odd resource names colliding after sanitizeName truncation/normalization.","solutions":["Find which code path adds the duplicate data source and ensure it dedupes before registering (report upstream if stock).","Check the cluster spec for duplicated features (e.g. two identical external addons or IAM entries) causing double lookups.","Rename the data source in the builder so sanitized names differ.","Update kOps — duplicates found on default specs are usually fixed upstream."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nkey := sanitizeName(dataSource.DataName)\nif seen[dataSource.DataType+\".\"+key] {\n    return fmt.Errorf(\"data source %s.%s would be registered twice\", dataSource.DataType, key)\n}\nseen[dataSource.DataType+\".\"+key] = true","typeGuard":null,"tryCatchPattern":"dsByType, err := w.GetDataSourcesByType()\nif err != nil {\n    return fmt.Errorf(\"building terraform data sources failed: %w\", err)\n}","preventionTips":["Dedupe data-source registrations in builders before adding.","Avoid duplicated features in the cluster spec that trigger repeated lookups.","Check names that collide after sanitizeName and differentiate them.","Update kOps and report the duplicate `<type>.<name>` upstream."],"tags":["terraform","data-sources","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"}