{"record":{"id":"357a062370069f29","repo":"kubernetes/kops","slug":"error-deleting-iam-role-q-v","errorCode":null,"errorMessage":"error deleting IAM role %q: %v","messagePattern":"error deleting IAM role %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/aws/aws.go","lineNumber":1978,"sourceCode":"\t\trequest := &iam.DetachRolePolicyInput{\n\t\t\tRoleName:  aws.String(r.Name),\n\t\t\tPolicyArn: policy.PolicyArn,\n\t\t}\n\t\t_, err := c.IAM().DetachRolePolicy(ctx, request)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error detaching IAM role policy %q %q: %v\", roleName, *policy.PolicyArn, err)\n\t\t}\n\t}\n\n\t// Delete Role\n\t{\n\t\tklog.V(2).Infof(\"Deleting IAM role %q\", r.Name)\n\t\trequest := &iam.DeleteRoleInput{\n\t\t\tRoleName: aws.String(r.Name),\n\t\t}\n\t\t_, err := c.IAM().DeleteRole(ctx, request)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error deleting IAM role %q: %v\", r.Name, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc ListIAMRoles(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Resource, error) {\n\tctx := context.TODO()\n\tc := cloud.(awsup.AWSCloud)\n\n\tvar resourceTrackers []*resources.Resource\n\t// Find roles owned by the cluster\n\t{\n\t\townershipTag := \"kubernetes.io/cluster/\" + clusterName\n\t\trequest := &iam.ListRolesInput{}\n\t\tpaginator := iam.NewListRolesPaginator(c.IAM(), request)\n\t\tfor paginator.HasMorePages() {\n\t\t\tpage, err := paginator.NextPage(ctx)","sourceCodeStart":1960,"sourceCodeEnd":1996,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/aws/aws.go#L1960-L1996","documentation":"Fires when iam.DeleteRole fails after all inline policies were deleted and managed policies detached — the final role deletion API call errored, typically due to remaining dependencies or insufficient permissions.","triggerScenarios":"Thrown at pkg/resources/aws/aws.go:1978 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure all instance profiles and policies referencing the role are removed first, then retry","Check iam:DeleteRole permission","Inspect the wrapped error for NoSuchEntity (already deleted) or DeleteConflict (dependencies)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}