Skip to main content

roles

Creates, updates, deletes, gets or lists a roles resource.

Overview

Nameroles
TypeResource
Idgoogle.iam.roles

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
namestringThe name of the role. When Role is used in CreateRole, the role name must not be set. When Role is used in output and other input such as UpdateRole, the role name is the complete path. For example, roles/logging.viewer for predefined roles, organizations/{ORGANIZATION_ID}/roles/myRole for organization-level custom roles, and projects/{PROJECT_ID}/roles/myRole for project-level custom roles.
deletedbooleanThe current deleted state of the role. This field is read only. It will be ignored in calls to CreateRole and UpdateRole.
descriptionstringOptional. A human-readable description for the role.
etagstring (byte)Used to perform a consistent read-modify-write.
includedPermissionsarrayThe names of the permissions this role grants when bound in an IAM policy.
stagestringThe current launch stage of the role. If the ALPHA launch stage has been selected for a role, the stage field will not be included in the returned definition for the role.
titlestringOptional. A human-readable title for the role. Typically this is limited to 100 UTF-8 bytes.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_project_rolesselectprojectsId, rolesIdGets the definition of a Role.
get_org_rolesselectorganizationsId, rolesIdGets the definition of a Role.
list_project_rolesselectprojectsIdpageSize, pageToken, view, showDeletedLists every predefined Role that IAM supports, or every custom role that is defined for an organization or project.
getselectrolesIdGets the definition of a Role.
list_org_rolesselectorganizationsIdpageSize, pageToken, view, showDeletedLists every predefined Role that IAM supports, or every custom role that is defined for an organization or project.
listselectparent, pageSize, pageToken, view, showDeletedLists every predefined Role that IAM supports, or every custom role that is defined for an organization or project.
create_project_rolesinsertprojectsIdCreates a new custom Role.
create_org_rolesinsertorganizationsIdCreates a new custom Role.
patch_project_rolesupdateprojectsId, rolesIdupdateMaskUpdates the definition of a custom Role.
patch_org_rolesupdateorganizationsId, rolesIdupdateMaskUpdates the definition of a custom Role.
delete_project_rolesdeleteprojectsId, rolesIdetagDeletes a custom Role. When you delete a custom role, the following changes occur immediately: * You cannot bind a principal to the custom role in an IAM Policy. * Existing bindings to the custom role are not changed, but they have no effect. * By default, the response from ListRoles does not include the custom role. A deleted custom role still counts toward the custom role limit until it is permanently deleted. You have 7 days to undelete the custom role. After 7 days, the following changes occur: * The custom role is permanently deleted and cannot be recovered. * If an IAM policy contains a binding to the custom role, the binding is permanently removed. * The custom role no longer counts toward your custom role limit.
delete_org_rolesdeleteorganizationsId, rolesIdetagDeletes a custom Role. When you delete a custom role, the following changes occur immediately: * You cannot bind a principal to the custom role in an IAM Policy. * Existing bindings to the custom role are not changed, but they have no effect. * By default, the response from ListRoles does not include the custom role. A deleted custom role still counts toward the custom role limit until it is permanently deleted. You have 7 days to undelete the custom role. After 7 days, the following changes occur: * The custom role is permanently deleted and cannot be recovered. * If an IAM policy contains a binding to the custom role, the binding is permanently removed. * The custom role no longer counts toward your custom role limit.
undelete_project_rolesexecprojectsId, rolesIdUndeletes a custom Role.
query_grantable_rolesexecLists roles that can be granted on a Google Cloud resource. A role is grantable if the IAM policy for the resource can contain bindings to the role.
undelete_org_rolesexecorganizationsId, rolesIdUndeletes a custom Role.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
organizationsIdstring
projectsIdstring
rolesIdstring
etagstring (byte)
pageSizeinteger (int32)
pageTokenstring
parentstring
showDeletedboolean
updateMaskstring (google-fieldmask)
viewstring

SELECT examples

Gets the definition of a Role.

SELECT
name,
deleted,
description,
etag,
includedPermissions,
stage,
title
FROM google.iam.roles
WHERE projectsId = '{{ projectsId }}' -- required
AND rolesId = '{{ rolesId }}' -- required;

INSERT examples

Creates a new custom Role.

INSERT INTO google.iam.roles (
data__roleId,
data__role,
projectsId
)
SELECT
'{{ roleId }}',
'{{ role }}',
'{{ projectsId }}'
RETURNING
name,
deleted,
description,
etag,
includedPermissions,
stage,
title
;

UPDATE examples

Updates the definition of a custom Role.

UPDATE google.iam.roles
SET
data__name = '{{ name }}',
data__title = '{{ title }}',
data__description = '{{ description }}',
data__includedPermissions = '{{ includedPermissions }}',
data__stage = '{{ stage }}',
data__etag = '{{ etag }}',
data__deleted = {{ deleted }}
WHERE
projectsId = '{{ projectsId }}' --required
AND rolesId = '{{ rolesId }}' --required
AND updateMask = '{{ updateMask}}'
RETURNING
name,
deleted,
description,
etag,
includedPermissions,
stage,
title;

DELETE examples

Deletes a custom Role. When you delete a custom role, the following changes occur immediately: * You cannot bind a principal to the custom role in an IAM Policy. * Existing bindings to the custom role are not changed, but they have no effect. * By default, the response from ListRoles does not include the custom role. A deleted custom role still counts toward the custom role limit until it is permanently deleted. You have 7 days to undelete the custom role. After 7 days, the following changes occur: * The custom role is permanently deleted and cannot be recovered. * If an IAM policy contains a binding to the custom role, the binding is permanently removed. * The custom role no longer counts toward your custom role limit.

DELETE FROM google.iam.roles
WHERE projectsId = '{{ projectsId }}' --required
AND rolesId = '{{ rolesId }}' --required
AND etag = '{{ etag }}';

Lifecycle Methods

Undeletes a custom Role.

EXEC google.iam.roles.undelete_project_roles 
@projectsId='{{ projectsId }}' --required,
@rolesId='{{ rolesId }}' --required
@@json=
'{
"etag": "{{ etag }}"
}';