kubernetes/kops · error
duplicate data source found: %s.%s
Error message
duplicate data source found: %s.%s
What it means
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.
Source
Thrown at upup/pkg/fi/cloudup/terraformWriter/writer.go:223
t.outputs[key].ValueArray = append(t.outputs[key].ValueArray, literal)
return nil
}
func (t *TerraformWriter) GetDataSourcesByType() (map[string]map[string]interface{}, error) {
dataSourcesByType := make(map[string]map[string]interface{})
for _, dataSource := range t.dataSources {
dataSources := dataSourcesByType[dataSource.DataType]
if dataSources == nil {
dataSources = make(map[string]interface{})
dataSourcesByType[dataSource.DataType] = dataSources
}
tfName := sanitizeName(dataSource.DataName)
if dataSources[tfName] != nil {
return nil, fmt.Errorf("duplicate data source found: %s.%s", dataSource.DataType, tfName)
}
dataSources[tfName] = dataSource.Item
}
return dataSourcesByType, nil
}
func (t *TerraformWriter) GetResourcesByType() (map[string]map[string]interface{}, error) {
resourcesByType := make(map[string]map[string]interface{})
for _, res := range t.resources {
resources := resourcesByType[res.ResourceType]
if resources == nil {
resources = make(map[string]interface{})
resourcesByType[res.ResourceType] = resources
}
View on GitHub (pinned to 4c8573c808)
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.
Defensive patterns
Strategy: validation
Validate before calling
seen := map[string]bool{}
key := sanitizeName(dataSource.DataName)
if seen[dataSource.DataType+"."+key] {
return fmt.Errorf("data source %s.%s would be registered twice", dataSource.DataType, key)
}
seen[dataSource.DataType+"."+key] = true Try / catch
dsByType, err := w.GetDataSourcesByType()
if err != nil {
return fmt.Errorf("building terraform data sources failed: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- duplicate variable: %q
- variable %q is both an array and a scalar
- duplicate resource found: %s.%s
- could not find one of launch configuration, mixed instances
- unexpected target type for deletion: %T
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/9fd06703dbf8aa8c.
Report an issue: GitHub.