func()

in pkg/cmd/serviceaccount/phases/create/roleassignment.go [58:84]


func (p *roleAssignmentPhase) run(ctx context.Context, data workflow.RunData) error {
	createData := data.(CreateData)

	// create the role assignment using object id of the service principal
	ra, err := createData.AzureClient().CreateRoleAssignment(ctx, createData.AzureScope(), createData.AzureRole(), createData.ServicePrincipalObjectID())
	if err != nil {
		if cloud.IsRoleAssignmentExists(err) {
			mlog.WithValues(
				"scope", createData.AzureScope(),
				"role", createData.AzureRole(),
				"servicePrincipalObjectID", createData.ServicePrincipalObjectID(),
				"roleAssignmentID", ra.ID,
			).WithName(roleAssignmentPhaseName).Debug("role assignment has previously been created")
		} else {
			return errors.Wrap(err, "failed to create role assignment")
		}
	}

	mlog.WithValues(
		"scope", createData.AzureScope(),
		"role", createData.AzureRole(),
		"servicePrincipalObjectID", createData.ServicePrincipalObjectID(),
		"roleAssignmentID", ra.ID,
	).WithName(roleAssignmentPhaseName).Info("created role assignment")

	return nil
}