{"record":{"id":"518f0bb5c4264a4c","repo":"kubernetes/kops","slug":"error-listing-vpcs-v-518f0b","errorCode":null,"errorMessage":"error listing VPCs: %v","messagePattern":"error listing VPCs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_cloud.go","lineNumber":1674,"sourceCode":"\tinstance := reservation.Instances[0]\n\treturn &instance, nil\n}\n\n// DescribeVPC is a helper that queries for the specified vpc by id\nfunc (c *awsCloudImplementation) DescribeVPC(vpcID string) (*ec2types.Vpc, error) {\n\treturn describeVPC(c, vpcID)\n}\n\nfunc describeVPC(c AWSCloud, vpcID string) (*ec2types.Vpc, error) {\n\tklog.V(2).Infof(\"Calling DescribeVPC for VPC %q\", vpcID)\n\tctx := context.TODO()\n\trequest := &ec2.DescribeVpcsInput{\n\t\tVpcIds: []string{vpcID},\n\t}\n\n\tresponse, err := c.EC2().DescribeVpcs(ctx, request)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing VPCs: %v\", err)\n\t}\n\tif response == nil || len(response.Vpcs) == 0 {\n\t\treturn nil, nil\n\t}\n\tif len(response.Vpcs) != 1 {\n\t\treturn nil, fmt.Errorf(\"found multiple VPCs for %q\", vpcID)\n\t}\n\n\tvpc := response.Vpcs[0]\n\treturn &vpc, nil\n}\n\n// ResolveImage finds an AMI image based on the given name.\n// The name can be one of:\n// `ami-...` in which case it is presumed to be an id\n// owner/name in which case we find the image with the specified name, owned by owner\n// name in which case we find the image with the specified name, with the current owner\nfunc (c *awsCloudImplementation) ResolveImage(name string) (*ec2types.Image, error) {","sourceCodeStart":1656,"sourceCodeEnd":1692,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L1656-L1692","documentation":"Returned by kops' FindVPC (upup/pkg/fi/cloudup/awsup/aws_cloud.go:1674) when the AWS SDK call ec2.DescribeVpcs fails while looking up a specific VPC by ID. It wraps the underlying AWS error, so the root cause (auth, networking, or a nonexistent/invalid VPC ID) is in the %v suffix.","triggerScenarios":"DescribeVpcs is called with a VpcIds filter of [vpcID] and AWS returns an error: invalid credentials, invalid VPC ID format, VPC deleted, region mismatch, or API throttling/network failure.","commonSituations":"Typo in cluster spec vpcID; cluster config references a VPC in a different region than the client; AWS session credentials expired or missing; VPC deleted by another process after being referenced in the kops cluster spec.","solutions":["Run `aws ec2 describe-vpcs --vpc-ids <id>` with the same credentials/region to reproduce the underlying error and check the wrapped message","Verify the VPC ID in the kops cluster spec exists in the target region (`kops get cluster -oyaml` and compare with AWS console)","Fix AWS credentials/environment (AWS_PROFILE, AWS_REGION, instance role) before retrying","Confirm the VPC was not deleted; recreate it or update the cluster spec"],"exampleFix":"// before\ncluster.Spec.NetworkID = \"vpc-0123456789abcdef\"\n// after\n// confirm the ID exists first:\n// aws ec2 describe-vpcs --vpc-ids vpc-0123456789abcdef --region us-east-1\ncluster.Spec.NetworkID = \"vpc-0abc123de4567890f\"","handlingStrategy":"validation","validationCode":"// Pre-flight: ensure the VPC exists and is reachable before calling kops\nout, err := ec2Client.DescribeVpcs(ctx, &ec2.DescribeVpcsInput{VpcIds: []string{vpcID}})\nif err != nil { return fmt.Errorf(\"preflight VPC check failed: %w\", err) }\nif len(out.Vpcs) == 0 { return fmt.Errorf(\"VPC %s does not exist in this region\", vpcID) }","typeGuard":"func vpcExists(out *ec2.DescribeVpcsOutput, id string) bool {\n\treturn out != nil && len(out.Vpcs) == 1 && aws.ToString(out.Vpcs[0].VpcId) == id\n}","tryCatchPattern":"vpc, err := cloud.FindVPC(ctx, vpcID)\nif err != nil {\n\tif strings.Contains(err.Error(), \"InvalidVpcID.NotFound\") {\n\t\t// fall back to default VPC or abort with a clear message\n\t}\n\treturn err\n}","preventionTips":["Always run `aws ec2 describe-vpcs --vpc-ids <id>` in the target region before wiring the ID into a cluster spec","Pin AWS_REGION/AWS_PROFILE so client region and VPC region never diverge","Re-verify VPC IDs after any IaC change that could delete/recreate them"],"tags":["aws","ec2","vpc","api-error"],"backgroundTag":"aws-api-call-failed","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"}