func CheckIfPolicyIsAlreadyAttachedToTheRole()

in aws/iam.go [71:100]


func CheckIfPolicyIsAlreadyAttachedToTheRole(client IamClient, roleName *string, policyName *string) *types.AttachedPolicy {
	maxItems := int32(100)
	var marker *string

	for {
		ret, err := client.ListAttachedRolePolicies(context.TODO(), &iam.ListAttachedRolePoliciesInput{
			RoleName: roleName,
			MaxItems: &maxItems,
			Marker:   marker,
		})

		if err != nil {
			log.Fatalf("Failed to list attached role policies for %s. Encountered Error %s\n", *roleName, err)
		}

		for _, policy := range ret.AttachedPolicies {
			if *policy.PolicyName == *policyName {
				return &policy
			}
		}

		if ret.IsTruncated {
			marker = ret.Marker
		} else {
			break
		}
	}

	return nil
}