Skip to main content

custom_constraints

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

Overview

Namecustom_constraints
TypeResource
Idgoogle.orgpolicy.custom_constraints

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
namestringImmutable. Name of the constraint. This is unique within the organization. Format of the name should be * organizations/{organization_id}/customConstraints/{custom_constraint_id} Example: organizations/123/customConstraints/custom.createOnlyE2TypeVms The max length is 70 characters and the minimum length is 1. Note that the prefix organizations/{organization_id}/customConstraints/ is not counted.
actionTypestringAllow or deny type.
conditionstringA Common Expression Language (CEL) condition which is used in the evaluation of the constraint. For example: resource.instanceName.matches("[production|test]_.*_(\d)+") or, resource.management.auto_upgrade == true The max length of the condition is 1000 characters.
descriptionstringDetailed information about this custom policy constraint. The max length of the description is 2000 characters.
displayNamestringOne line display name for the UI. The max length of the display_name is 200 characters.
methodTypesarrayAll the operations being applied for this constraint.
resourceTypesarrayImmutable. The resource instance type on which this policy applies. Format will be of the form : / Example: * compute.googleapis.com/Instance.
updateTimestring (google-datetime)Output only. The last time this custom constraint was updated. This represents the last time that the CreateCustomConstraint or UpdateCustomConstraint methods were called.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
organizations_custom_constraints_getselectorganizationsId, customConstraintsIdGets a custom or managed constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the custom or managed constraint does not exist.
organizations_custom_constraints_listselectorganizationsIdpageSize, pageTokenRetrieves all of the custom constraints that exist on a particular organization resource.
organizations_custom_constraints_createinsertorganizationsIdCreates a custom constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the organization does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the constraint already exists on the given organization.
organizations_custom_constraints_patchupdateorganizationsId, customConstraintsIdUpdates a custom constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Note: the supplied policy will perform a full overwrite of all fields.
organizations_custom_constraints_deletedeleteorganizationsId, customConstraintsIdDeletes a custom constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist.

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
customConstraintsIdstring
organizationsIdstring
pageSizeinteger (int32)
pageTokenstring

SELECT examples

Gets a custom or managed constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the custom or managed constraint does not exist.

SELECT
name,
actionType,
condition,
description,
displayName,
methodTypes,
resourceTypes,
updateTime
FROM google.orgpolicy.custom_constraints
WHERE organizationsId = '{{ organizationsId }}' -- required
AND customConstraintsId = '{{ customConstraintsId }}' -- required;

INSERT examples

Creates a custom constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the organization does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the constraint already exists on the given organization.

INSERT INTO google.orgpolicy.custom_constraints (
data__name,
data__resourceTypes,
data__methodTypes,
data__condition,
data__actionType,
data__displayName,
data__description,
organizationsId
)
SELECT
'{{ name }}',
'{{ resourceTypes }}',
'{{ methodTypes }}',
'{{ condition }}',
'{{ actionType }}',
'{{ displayName }}',
'{{ description }}',
'{{ organizationsId }}'
RETURNING
name,
actionType,
condition,
description,
displayName,
methodTypes,
resourceTypes,
updateTime
;

UPDATE examples

Updates a custom constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Note: the supplied policy will perform a full overwrite of all fields.

UPDATE google.orgpolicy.custom_constraints
SET
data__name = '{{ name }}',
data__resourceTypes = '{{ resourceTypes }}',
data__methodTypes = '{{ methodTypes }}',
data__condition = '{{ condition }}',
data__actionType = '{{ actionType }}',
data__displayName = '{{ displayName }}',
data__description = '{{ description }}'
WHERE
organizationsId = '{{ organizationsId }}' --required
AND customConstraintsId = '{{ customConstraintsId }}' --required
RETURNING
name,
actionType,
condition,
description,
displayName,
methodTypes,
resourceTypes,
updateTime;

DELETE examples

Deletes a custom constraint. Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist.

DELETE FROM google.orgpolicy.custom_constraints
WHERE organizationsId = '{{ organizationsId }}' --required
AND customConstraintsId = '{{ customConstraintsId }}' --required;