{"record":{"id":"ba7f69d191562cd1","repo":"kubernetes/kops","slug":"error-terminating-instances-v","errorCode":null,"errorMessage":"error terminating instances: %v","messagePattern":"error terminating instances: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/aws/aws.go","lineNumber":355,"sourceCode":"\t\t}\n\n\t\tklog.Infof(\"Terminating %d EC2 instances\", len(ids))\n\t\trequest := &ec2.TerminateInstancesInput{\n\t\t\tInstanceIds:    ids,\n\t\t\tSkipOsShutdown: aws.Bool(true),\n\t\t}\n\t\tif hasXenHyervisor {\n\t\t\t// SkipOsShutdown is not supported on Xen instance types.\n\t\t\trequest.SkipOsShutdown = aws.Bool(false)\n\t\t}\n\t\tids = []string{}\n\t\thasXenHyervisor = false\n\t\t_, err := c.EC2().TerminateInstances(ctx, request)\n\t\tif err != nil {\n\t\t\tif awsup.AWSErrorCode(err) == \"InvalidInstanceID.NotFound\" {\n\t\t\t\tklog.V(2).Infof(\"Got InvalidInstanceID.NotFound error terminating instances; will treat as already terminated\")\n\t\t\t} else {\n\t\t\t\treturn fmt.Errorf(\"error terminating instances: %v\", err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc ListInstances(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Resource, error) {\n\tctx := context.TODO()\n\tc := cloud.(awsup.AWSCloud)\n\n\tklog.V(2).Infof(\"Querying EC2 instances\")\n\tfilters := BuildEC2Filters(cloud)\n\tfilters = append(filters, awsup.NewEC2Filter(\"vpc-id\", vpcID))\n\tfilters = append(filters, awsup.NewEC2Filter(\"instance-state-name\", string(ec2types.InstanceStateNameRunning)))\n\trequest := &ec2.DescribeInstancesInput{\n\t\tFilters: filters,\n\t}\n","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/aws/aws.go#L337-L373","documentation":"DeleteInstances calls EC2 TerminateInstances in batches; if the call fails with any code other than InvalidInstanceID.NotFound (which is treated as already-terminated), the error is wrapped as 'error terminating instances: %v'. This happens while tearing down cluster resources during `kops delete cluster` or instance group deletes.","triggerScenarios":"EC2 API returns UnauthorizedOperation, InvalidInstanceID.Malformed, throttling (RequestLimitExceeded), or transient 5xx; also network failures between kops and EC2.","commonSituations":"IAM credentials lacking ec2:TerminateInstances on the instance/region, instances in a state that forbids termination (e.g. protected via termination protection or already gone with a different error), or API rate limits during large deletes.","solutions":["Check the wrapped underlying cause (%v) for the AWS error code and message","Verify IAM permissions include ec2:TerminateInstances for the region/account","Retry on throttling errors; kops delete can simply be re-run (idempotent)","Check AWS health dashboard and region connectivity for outages"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := deleteInstances(ctx, c, ids)\nif err != nil {\n\tif awsup.AWSErrorCode(err) != \"\" && isThrottlingCode(awsup.AWSErrorCode(err)) {\n\t\ttime.Sleep(backoff)\n\t\terr = deleteInstances(ctx, c, ids) // retry idempotent delete\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"terminate failed: %w\", err)\n\t}\n}","preventionTips":["Ensure IAM policy grants ec2:TerminateInstances in the target region","Re-run kops delete; termination is idempotent and NotFound is tolerated","Watch EC2 throttling limits when running large parallel deletes"],"tags":["aws","ec2","api-error","deletion"],"backgroundTag":"aws-api-error","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"}