Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-9451 | ci: fix the nil pointer when error happens for role creation #64

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pkg/aws/aws_client/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/openshift-online/ocm-common/pkg/log"
"time"

"github.com/openshift-online/ocm-common/pkg/log"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/iam/types"
Expand All @@ -22,7 +23,7 @@ func (client *AWSClient) CreateRole(roleName string,
permissionBoundry string,
tags map[string]string,
path string,
) (types.Role, error) {
) (role types.Role, err error) {
var roleTags []types.Tag
for tagKey, tagValue := range tags {
roleTags = append(roleTags, types.Tag{
Expand All @@ -45,13 +46,14 @@ func (client *AWSClient) CreateRole(roleName string,
if len(tags) != 0 {
input.Tags = roleTags
}
var resp *iam.CreateRoleOutput
resp, err = client.IamClient.CreateRole(context.TODO(), input)
if err == nil && resp != nil {
role = *resp.Role
err = client.WaitForResourceExisting("role-"+*resp.Role.RoleName, 10) // add a prefix to meet the resourceExisting split rule

resp, err := client.IamClient.CreateRole(context.TODO(), input)
if err != nil {
return *resp.Role, err
}
err = client.WaitForResourceExisting("role-"+*resp.Role.RoleName, 10) // add a prefix to meet the resourceExisting split rule
return *resp.Role, err
return
}

func (client *AWSClient) CreateRoleAndAttachPolicy(roleName string,
Expand Down
Loading