From bc10b67bb5ac00abd3c1b6479fb498956d3c9319 Mon Sep 17 00:00:00 2001 From: Xue Li Date: Tue, 9 Jul 2024 16:55:37 +0800 Subject: [PATCH] OCM-9451 | ci: fix the nil pointer when error happens for role creation Fix the comment Fix comment --- pkg/aws/aws_client/role.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/aws/aws_client/role.go b/pkg/aws/aws_client/role.go index 9d085ef..3a10619 100644 --- a/pkg/aws/aws_client/role.go +++ b/pkg/aws/aws_client/role.go @@ -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" @@ -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{ @@ -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,