Skip to content

Commit

Permalink
Merge pull request #83 from yuwang-RH/sharevpchcp0102
Browse files Browse the repository at this point in the history
OCM-13258 | ci: Add new function to create shared roles to support hosted-cp shared-vpc job
  • Loading branch information
yuwang-RH authored Jan 3, 2025
2 parents 2935429 + 9d72082 commit 8928059
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/aws/aws_client/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,28 @@ func (client *AWSClient) CreateRoleForSharedVPC(roleName, installerRoleArn strin
return client.CreateRole(roleName, string(assumeRolePolicyDocument), "", make(map[string]string), "/")
}

// A more common function to create roles for shared VPC. The old CreateRoleForSharedVPC function was used for classic
// shared-vpc cluster only. This function can be used for both classic and hosted-cp shared-vpc cluster. Keep CreateRoleForSharedVPC
// for the compatibility of the eale reference
func (client *AWSClient) CreateRoleForSharedVPCHCP(roleName string, assumeRolesArns []string) (types.Role, error) {
statement := map[string]interface{}{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": map[string]interface{}{
"AWS": assumeRolesArns,
},
"Action": "sts:AssumeRole",
}

assumeRolePolicyDocument, err := completeRolePolicyDocument(statement)
if err != nil {
log.LogError("Failed to convert Role Policy Document into JSON: %s", err.Error())
return types.Role{}, err
}

return client.CreateRole(roleName, string(assumeRolePolicyDocument), "", make(map[string]string), "/")
}

func (client *AWSClient) CreatePolicyForSharedVPC(policyName string) (string, error) {
statement := map[string]interface{}{
"Sid": "Statement1",
Expand Down

0 comments on commit 8928059

Please sign in to comment.