{"record":{"id":"b53e3fe61bb59116","repo":"kubernetes/kops","slug":"found-multiple-vpcs-for-q","errorCode":null,"errorMessage":"found multiple VPCs for %q","messagePattern":"found multiple VPCs for %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_cloud.go","lineNumber":1680,"sourceCode":"\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) {\n\treturn resolveImage(context.TODO(), c.ssm, c.ec2, name)\n}\n\nfunc resolveSSMParameter(ctx context.Context, ssmClient awsinterfaces.SSMAPI, name string) (string, error) {\n\tklog.V(2).Infof(\"Resolving SSM parameter %q\", name)\n\trequest := &ssm.GetParameterInput{","sourceCodeStart":1662,"sourceCodeEnd":1698,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L1662-L1698","documentation":"Returned by FindVPC when DescribeVpcs filtered by a single VPC ID returns more than one VPC (aws_cloud.go:1680). A VPC ID should match exactly one VPC, so this indicates a violated invariant rather than a user-input problem per se.","triggerScenarios":"The EC2 DescribeVpcs call with VpcIds=[vpcID] returns len(response.Vpcs) != 1 after the empty check — essentially only possible with a duplicate-ID response or a client/proxy anomaly.","commonSituations":"Rare in practice; seen with misbehaving EC2-compatible endpoints (custom API endpoints, LocalStack, Outposts-like setups) or stale mocked responses where the ID filter is not honored.","solutions":["Verify the VPC ID is well-formed and unique via `aws ec2 describe-vpcs --vpc-ids <id>` against real AWS","If using a custom EC2 endpoint (e.g. LocalStack), clear stale state or disable the custom endpoint","Retry the operation; if it persists, report it — on real AWS a VPC ID is unique and this is an API-contract violation"],"exampleFix":"// before\nexport AWS_EC2_ENDPOINT=http://localhost:4566\n// after\nunset AWS_EC2_ENDPOINT  # use the real EC2 endpoint","handlingStrategy":"type-guard","validationCode":"// Validate uniqueness client-side with the same filter kops uses\nout, err := ec2Client.DescribeVpcs(ctx, &ec2.DescribeVpcsInput{VpcIds: []string{vpcID}})\nif err == nil && len(out.Vpcs) > 1 { return fmt.Errorf(\"ambiguous VPC result for %s\", vpcID) }","typeGuard":"func exactlyOneVPC(out *ec2.DescribeVpcsOutput) (*ec2types.Vpc, bool) {\n\tif out == nil || len(out.Vpcs) != 1 { return nil, false }\n\treturn &out.Vpcs[0], true\n}","tryCatchPattern":"vpc, err := cloud.FindVPC(ctx, vpcID)\nif err != nil {\n\tif strings.Contains(err.Error(), \"found multiple VPCs\") {\n\t\t// treat as endpoint anomaly: drop custom endpoints / retry once\n\t}\n\treturn err\n}","preventionTips":["Avoid custom EC2-compatible endpoints (LocalStack etc.) in production runs","Confirm the VPC ID format (vpc- + 8 or 17 hex chars) before use","If this recurs on real AWS, capture the response and open a support/bug report — it violates the EC2 contract"],"tags":["aws","ec2","vpc","invariant-violation"],"backgroundTag":"duplicate-resource-lookup","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"}