Skip to content

Commit

Permalink
OCM-9451 | ci: fix the nil pointer when error happens for role creation
Browse files Browse the repository at this point in the history
Fix the comment

Fix comment
  • Loading branch information
xueli181114 committed Jul 9, 2024
1 parent 989f9a6 commit bc10b67
Showing 1 changed file with 9 additions and 7 deletions.
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

0 comments on commit bc10b67

Please sign in to comment.