{"record":{"id":"97c6ed8312d2d73f","repo":"kubernetes/kops","slug":"region-is-required-when-external","errorCode":null,"errorMessage":"--region is required (when --external)","messagePattern":"--region is required \\(when --external\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/delete_cluster.go","lineNumber":118,"sourceCode":"\tcmd.Flags().DurationVar(&options.interval, \"interval\", options.interval, \"Time in duration to wait between deletion attempts\")\n\n\treturn cmd\n}\n\nfunc RunDeleteCluster(ctx context.Context, f *util.Factory, out io.Writer, options *DeleteClusterOptions) error {\n\tclusterName := options.ClusterName\n\tif clusterName == \"\" {\n\t\treturn fmt.Errorf(\"--name is required (for safety)\")\n\t}\n\n\tvar cloud fi.Cloud\n\tvar cluster *kopsapi.Cluster\n\tvar err error\n\n\tif options.External {\n\t\tregion := options.Region\n\t\tif region == \"\" {\n\t\t\treturn fmt.Errorf(\"--region is required (when --external)\")\n\t\t}\n\n\t\ttags := map[string]string{\"KubernetesCluster\": clusterName}\n\t\tcloud, err = awsup.NewAWSCloud(region, tags)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error initializing AWS client: %v\", err)\n\t\t}\n\t} else {\n\t\tcluster, err = GetCluster(ctx, f, clusterName)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\twouldDeleteCloudResources := false\n\n\tif !options.Unregister {\n\t\tif cloud == nil {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/delete_cluster.go#L100-L136","documentation":"When deleting a cluster with --external (cluster not managed in the kOps state store / config not available), kOps discovers resources directly in AWS, which requires a region. If options.Region is empty it returns this error before any API call.","triggerScenarios":"Running `kops delete cluster --external` without also passing `--region` (and no KOPS_REGION env var), so the AWS cloud client cannot be constructed.","commonSituations":"Cleaning up a cluster whose state store was lost; deleting clusters created outside kOps where the region cannot be inferred from the cluster config.","solutions":["Pass `--region <aws-region>` together with `--external`.","Set the KOPS_REGION environment variable.","If the cluster is actually in the state store, drop --external so region is derived from the cluster spec."],"exampleFix":"// before\nkops delete cluster --external --name cluster.example.com\n// after\nkops delete cluster --external --name cluster.example.com --region us-east-1","handlingStrategy":"validation","validationCode":"if external {\n    region := os.Getenv(\"KOPS_REGION\")\n    if region == \"\" {\n        return fmt.Errorf(\"--external requires --region\")\n    }\n    args = append(args, \"--region\", region)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair --external with --region every time.","Set KOPS_REGION in the environment for AWS workflows.","Prefer state-store deletion (omit --external) when the cluster is kOps-managed."],"tags":["cli","aws","validation","missing-flag"],"backgroundTag":"missing-required-flag","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"}