{"record":{"id":"5606f334a986d3f5","repo":"kubernetes/kops","slug":"subnet-q-must-specify-a-zone-or-the-id-of-an-exis","errorCode":null,"errorMessage":"subnet %q must specify a zone or the ID of an existing subnet","messagePattern":"subnet %q must specify a zone or the ID of an existing subnet","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_utils.go","lineNumber":99,"sourceCode":"\t}\n\n\tif os.Getenv(\"SKIP_REGION_CHECK\") != \"\" {\n\t\tklog.Infof(\"AWS region does not appear to be valid, but skipping because SKIP_REGION_CHECK is set\")\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"Region is not a recognized EC2 region: %q (check you have specified valid zones?)\", region)\n}\n\n// FindRegion determines the region from the zones specified in the cluster\nfunc FindRegion(cluster *kops.Cluster) (string, error) {\n\tregion := \"\"\n\n\tfor _, subnet := range cluster.Spec.Networking.Subnets {\n\t\tif subnet.Zone == \"\" {\n\t\t\t// The zone of a subnet specified by ID is looked up from the cloud later.\n\t\t\tif subnet.ID == \"\" {\n\t\t\t\treturn \"\", fmt.Errorf(\"subnet %q must specify a zone or the ID of an existing subnet\", subnet.Name)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tif len(subnet.Zone) <= 2 {\n\t\t\treturn \"\", fmt.Errorf(\"invalid AWS zone: %q in subnet %q\", subnet.Zone, subnet.Name)\n\t\t}\n\n\t\tzoneRegion := subnet.Zone[:len(subnet.Zone)-1]\n\t\tif region != \"\" && zoneRegion != region {\n\t\t\treturn \"\", fmt.Errorf(\"error Clusters cannot span multiple regions (found zone %q, but region is %q)\", subnet.Zone, region)\n\t\t}\n\n\t\tregion = zoneRegion\n\t}\n\n\tif region == \"\" {\n\t\treturn \"\", fmt.Errorf(\"could not determine cluster region: no subnet specifies a zone\")","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_utils.go#L81-L117","documentation":"FindRegion derives the cluster region from the subnets' zones; each subnet must either declare a zone or reference an existing subnet by ID (from which the zone is later looked up in the cloud). This error is thrown when a subnet has neither a zone nor an ID, so no region can be inferred from it. It enforces that every subnet entry in the cluster spec is usable for region discovery.","triggerScenarios":"Iterating cluster.Spec.Networking.Subnets in FindRegion and encountering a subnet where Zone == \"\" and ID == \"\" — the subnet only has a Name field filled in.","commonSituations":"Hand-edited kops cluster specs where someone added a subnet with just a name; templating tools emitting empty zone fields; subnets defined for other clouds (e.g. GCE/Azure style) copied into an AWS cluster spec.","solutions":["Set either the zone (e.g. us-east-1a) or the ID of an existing subnet (subnet-xxxxxxxx) on every subnet in cluster.Spec.Networking.Subnets","Run `kops edit cluster` to fix the subnet entries","Validate the spec with `kops validate` / dry-run before re-running create/update"],"exampleFix":"// before\nsubnets:\n- name: us-east-1a\n// after\nsubnets:\n- name: us-east-1a\n  zone: us-east-1a","handlingStrategy":"validation","validationCode":"// check every subnet has zone or id before kops create\nfor _, s := range cluster.Spec.Networking.Subnets {\n    if s.Zone == \"\" && s.ID == \"\" {\n        return fmt.Errorf(\"subnet %q needs a zone or id\", s.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set zone: on new subnets unless intentionally referencing existing subnet IDs","Schema-validate cluster manifests before `kops create cluster -f`","Review generated specs from templating tools for empty zone fields"],"tags":["aws","subnet","cluster-spec","validation"],"backgroundTag":"incomplete-subnet-spec","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}