{"record":{"id":"af47531be02ac9bc","repo":"kubernetes/kops","slug":"invalid-azure-zone-q","errorCode":null,"errorMessage":"invalid Azure zone: %q ","messagePattern":"invalid Azure zone: %q ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/azure/azure_utils.go","lineNumber":29,"sourceCode":"distributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\npackage azure\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\n// ZoneToLocation extracts the location from a zone of the\n// form <location>-<available-zone-number>..\nfunc ZoneToLocation(zone string) (string, error) {\n\tl := strings.Split(zone, \"-\")\n\tif len(l) != 2 {\n\t\treturn \"\", fmt.Errorf(\"invalid Azure zone: %q \", zone)\n\t}\n\treturn l[0], nil\n}\n\n// ZoneToAvailabilityZoneNumber extracts the availability zone number from a zone of the\n// form <location>-<available-zone-number>..\nfunc ZoneToAvailabilityZoneNumber(zone string) (string, error) {\n\tl := strings.Split(zone, \"-\")\n\tif len(l) != 2 {\n\t\treturn \"\", fmt.Errorf(\"invalid Azure zone: %q \", zone)\n\t}\n\treturn l[1], nil\n}\n\n// SubnetID contains the resource ID/names required to construct a subnet ID.\ntype SubnetID struct {\n\tSubscriptionID     string\n\tResourceGroupName  string","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/azure/azure_utils.go#L11-L47","documentation":"ZoneToLocation extracts the Azure location from a kOps zone string of the form <location>-<zone-number> (e.g. eastus-1). If splitting on \"-\" does not yield exactly two parts, the zone string does not match the Azure zone format and this error is returned. Callers use it to derive the region for Azure resource placement.","triggerScenarios":"Calling ZoneToLocation with a zone lacking exactly one dash-separated suffix: e.g. \"eastus\" (no zone number), \"us-east\" (multiple dashes), \"eastus-1-extra\", or an empty string.","commonSituations":"Setting kubernetesCluster zones to a region name like \"eastus\" instead of an availability zone \"eastus-1\"; copy-pasting AWS-style zones (us-east-1a has 3 parts, but note \"-\" split of \"us-east-1a\" gives 3 parts → fails); cluster spec edited by hand with invalid topology values.","solutions":["Use zones in the format <location>-<number>, e.g. \"eastus-1\", \"westeurope-2\".","Remove any extra \"-\" segments from the zone value in the cluster spec.","Check `az account list-locations` for valid location names, then append -1/-2/-3 for availability zones.","Run `kops edit cluster` to correct the zones field and `kops update cluster` to apply.","For Azure regions without availability zones, ensure the chosen region supports zones before using the -N suffix."],"exampleFix":"// before\nzones: [\"eastus\"]\n// after\nzones: [\"eastus-1\"]","handlingStrategy":"validation","validationCode":"// Go: validate zone format before calling ZoneToLocation\nfunc validAzureZone(zone string) bool {\n    parts := strings.Split(zone, \"-\")\n    if len(parts) != 2 || parts[0] == \"\" || parts[1] == \"\" {\n        return false\n    }\n    _, err := strconv.Atoi(parts[1])\n    return err == nil\n}\nif !validAzureZone(zone) {\n    return fmt.Errorf(\"zone %q must be <location>-<number>, e.g. eastus-1\", zone)\n}","typeGuard":"func isAzureZone(s string) bool {\n    l := strings.Split(s, \"-\")\n    return len(l) == 2\n}","tryCatchPattern":"loc, err := azure.ZoneToLocation(zone)\nif err != nil {\n    log.Printf(\"zone %q invalid; expected <location>-<number> (e.g. eastus-1): %v\", zone, err)\n    return err\n}","preventionTips":["Always specify Azure zones as <location>-<number>, e.g. eastus-1.","Never paste AWS zone strings (like us-east-1a) into an Azure cluster spec.","Check region availability-zone support before adding the -N suffix.","Lint cluster specs for the zones field before kops update.","Use constants/enums for known-good zone values in automation."],"tags":["azure","zones","validation","parsing"],"backgroundTag":"invalid-zone-format","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"}