{"record":{"id":"ae2e73121a726995","repo":"kubernetes/kops","slug":"found-multiple-internetgateways-matching-tags","errorCode":null,"errorMessage":"found multiple InternetGateways matching tags","messagePattern":"found multiple InternetGateways matching tags","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/internetgateway.go","lineNumber":62,"sourceCode":"}\n\nvar _ fi.CompareWithID = (*InternetGateway)(nil)\n\nfunc (e *InternetGateway) CompareWithID() *string {\n\treturn e.ID\n}\n\nfunc findInternetGateway(ctx context.Context, cloud awsup.AWSCloud, request *ec2.DescribeInternetGatewaysInput) (*ec2types.InternetGateway, error) {\n\tresponse, err := cloud.EC2().DescribeInternetGateways(ctx, request)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing InternetGateways: %v\", err)\n\t}\n\tif response == nil || len(response.InternetGateways) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tif len(response.InternetGateways) != 1 {\n\t\treturn nil, fmt.Errorf(\"found multiple InternetGateways matching tags\")\n\t}\n\tigw := response.InternetGateways[0]\n\treturn &igw, nil\n}\n\nfunc (e *InternetGateway) Find(c *fi.CloudupContext) (*InternetGateway, error) {\n\tctx := c.Context()\n\tcloud := awsup.GetCloud(c)\n\n\trequest := &ec2.DescribeInternetGatewaysInput{}\n\n\tshared := fi.ValueOf(e.Shared)\n\tif shared {\n\t\tif fi.ValueOf(e.VPC.ID) == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"VPC ID is required when InternetGateway is shared\")\n\t\t}\n\n\t\trequest.Filters = []ec2types.Filter{awsup.NewEC2Filter(\"attachment.vpc-id\", *e.VPC.ID)}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/internetgateway.go#L44-L80","documentation":"findInternetGateway requires exactly one Internet Gateway to match the supplied filters/tags. When the DescribeInternetGateways response contains more than one match, kOps cannot determine which gateway the task refers to and aborts with this error.","triggerScenarios":"DescribeInternetGateways with tag filters (Find path) or attachment.vpc-id filter (shared path) returns len(response.InternetGateways) > 1.","commonSituations":"Multiple IGWs attached to the same shared VPC (e.g. one leftover from a previous setup plus another tagged one), duplicated kops tags applied to several gateways, manual copying of tags to another IGW.","solutions":["Detach or delete the redundant Internet Gateway(s) so exactly one matches the filters.","Remove the duplicate kops tags from gateways that should not be selected.","Use a more specific filter — set e.ID or the exact shared IGW ID instead of tag-only lookup.","Audit the VPC with `aws ec2 describe-internet-gateways --filters Name=attachment.vpc-id,Values=<vpc-id>`."],"exampleFix":"// before: two IGWs tagged kubernetes.io/cluster/<cluster> on the VPC\n// after: remove tag from the unused one\naws ec2 delete-tags --resources igw-0EXTRA123 --tags Key=kubernetes.io/cluster/<cluster>","handlingStrategy":"validation","validationCode":"aws ec2 describe-internet-gateways \\\n  --filters Name=tag:kubernetes.io/cluster/<cluster>,Values=owned \\\n  --query 'length(InternetGateways)'   # must print exactly 1 before running kops","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"found multiple InternetGateways matching tags\") {\n    // enumerate and remove the duplicate gateways before retrying\n    return fmt.Errorf(\"resolve duplicate IGWs in VPC: %w\", err)\n}","preventionTips":["Never duplicate kops cluster tags onto multiple gateways in one VPC.","Clean up leftover gateways from aborted cluster deletes.","Prefer specifying an explicit IGW ID over tag-only discovery for shared VPCs.","Audit VPC attachments periodically."],"tags":["aws","ec2","internet-gateway","ambiguity"],"backgroundTag":"ambiguous-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"}