Skip to content

Commit

Permalink
Merge pull request #64 from xueli181114/OCM-9451
Browse files Browse the repository at this point in the history
OCM-9451 | ci: fix the nil pointer when error happens for role creation
  • Loading branch information
ciaranRoche authored Jul 9, 2024
2 parents 989f9a6 + bc10b67 commit 5504383
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 5504383

Please sign in to comment.