{"record":{"id":"f7bd4f0201f9ea83","repo":"kubernetes/kops","slug":"subnet-s-not-found-in-vpc-s","errorCode":null,"errorMessage":"subnet %s not found in VPC %s","messagePattern":"subnet (.+?) not found in VPC (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/new_cluster.go","lineNumber":925,"sourceCode":"\tawsCloud, err := awsup.NewAWSCloud(region, cloudTags)\n\tif err != nil {\n\t\treturn res, fmt.Errorf(\"error loading cloud: %v\", err)\n\t}\n\tvpcInfo, err := awsCloud.FindVPCInfo(VPCID)\n\tif err != nil {\n\t\treturn res, fmt.Errorf(\"error describing VPC: %v\", err)\n\t}\n\tif vpcInfo == nil {\n\t\treturn res, fmt.Errorf(\"VPC %q not found\", VPCID)\n\t}\n\tsubnetByID := make(map[string]*fi.SubnetInfo)\n\tfor _, subnetInfo := range vpcInfo.Subnets {\n\t\tsubnetByID[subnetInfo.ID] = subnetInfo\n\t}\n\tfor _, subnetID := range subnetIDs {\n\t\tsubnet, ok := subnetByID[subnetID]\n\t\tif !ok {\n\t\t\treturn res, fmt.Errorf(\"subnet %s not found in VPC %s\", subnetID, VPCID)\n\t\t}\n\t\tif res[subnet.Zone] != \"\" {\n\t\t\treturn res, fmt.Errorf(\"subnet %s and %s have the same zone\", subnetID, res[subnet.Zone])\n\t\t}\n\t\tres[subnet.Zone] = subnetID\n\t}\n\treturn res, nil\n}\n\nfunc getOpenstackZoneToSubnetProviderID(cluster *api.Cluster, zones []string, subnetIDs []string) (map[string]string, error) {\n\tres := make(map[string]string)\n\tosCloud, err := openstack.NewOpenstackCloud(cluster, \"new-cluster-zone-to-subnet\")\n\tif err != nil {\n\t\treturn res, fmt.Errorf(\"error loading cloud: %v\", err)\n\t}\n\tosCloud.UseZones(zones)\n\n\tnetworkInfo, err := osCloud.FindVPCInfo(cluster.Spec.Networking.NetworkID)","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/new_cluster.go#L907-L943","documentation":"After building a subnetByID map from the VPC's subnets, kOps looks up each user-supplied --subnets ID. If a subnet ID is not present in the specified VPC, \"subnet %s not found in VPC %s\" is returned. This guarantees that the subnets used for the cluster actually belong to the VPC the cluster will use.","triggerScenarios":"`kops create cluster --cloud aws --vpc vpc-A --subnets subnet-X ...` where subnet-X lives in VPC-B, a different region, a different account, or the ID is mistyped.","commonSituations":"Mixing subnets from default VPC and a custom VPC; cross-account subnet usage without sharing; typos in subnet IDs; subnets in a different region than the VPC.","solutions":["List the VPC's subnets: `aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-A --region <region>` and use only those IDs.","Fix --subnets and --vpc so they are consistent (all subnets belong to --vpc).","For cross-account shared subnets, ensure sharing is actually configured and the caller can describe them."],"exampleFix":"// before\n--vpc vpc-A --subnets subnet-fromVpcB\n// after\n--vpc vpc-A --subnets subnet-inVpcA-1,subnet-inVpcA-2","handlingStrategy":"validation","validationCode":"out, _ := exec.Command(\"aws\", \"ec2\", \"describe-subnets\", \"--filters\",\n    \"Name=vpc-id,Values=\"+vpcID, \"--region\", region, \"--query\",\n    \"Subnets[].SubnetId\", \"--output\", \"json\").Output()\nfor _, s := range requestedSubnets {\n    if !strings.Contains(string(out), s) {\n        return fmt.Errorf(\"subnet %s is not in VPC %s\", s, vpcID)\n    }\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"not found in VPC\") {\n    // re-run discovery of subnets belonging to the VPC and rebuild --subnets\n}","preventionTips":["Discover subnet IDs by vpc-id filter at runtime rather than pasting from console.","Keep --vpc and --subnets sourced from the same Terraform/export step.","Note subnet region must equal VPC region."],"tags":["aws","subnet","vpc","not-found","cluster-creation"],"backgroundTag":"resource-not-found","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"}