{"record":{"id":"9b9f9b48ce5c15a2","repo":"kubernetes/kops","slug":"error-detaching-iam-role-policy-q-q-v","errorCode":null,"errorMessage":"error detaching IAM role policy %q %q: %v","messagePattern":"error detaching IAM role policy %q %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/aws/aws.go","lineNumber":1966,"sourceCode":"\t\t\tRoleName:   aws.String(r.Name),\n\t\t\tPolicyName: aws.String(policyName),\n\t\t}\n\t\t_, err := c.IAM().DeleteRolePolicy(ctx, request)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error deleting IAM role policy %q %q: %v\", roleName, policyName, err)\n\t\t}\n\t}\n\n\t// Detach Managed Policies\n\tfor _, policy := range attachedPolicies {\n\t\tklog.V(2).Infof(\"Detaching IAM role policy %q %v\", roleName, policy)\n\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","sourceCodeStart":1948,"sourceCodeEnd":1984,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/aws/aws.go#L1948-L1984","documentation":"Fires when iam.DetachRolePolicy fails to detach a managed policy from the IAM role during teardown — often a dependency violation if the policy/role is still in use, or a permissions/throttling error.","triggerScenarios":"Thrown at pkg/resources/aws/aws.go:1966 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check iam:DetachRolePolicy permission","Wait for dependencies (profiles still using the role) to clear, then retry","Inspect the wrapped AWS error code for DeleteConflict and re-run after dependencies are removed"],"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"}