googleOrgPolicyPolicy
An organization policy gives you programmatic control over your organization's cloud resources. Using Organization Policies, you will be able to configure constraints across your entire resource hierarchy.
For more information, see:
Example Usage - enforce_policy
A test of an enforce orgpolicy policy for a project
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleProjectBasic = new google.project.Project(this, "basic", {
name: "id",
org_id: "123456789",
project_id: "id",
});
new google.orgPolicyPolicy.OrgPolicyPolicy(this, "primary", {
name: `projects/\${${googleProjectBasic.name}}/policies/iam.disableServiceAccountKeyUpload`,
parent: `projects/\${${googleProjectBasic.name}}`,
spec: [
{
rules: [
{
enforce: "FALSE",
},
],
},
],
});
Example Usage - folder_policy
A test of an orgpolicy policy for a folder
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleFolderBasic = new google.folder.Folder(this, "basic", {
display_name: "folder",
parent: "organizations/123456789",
});
new google.orgPolicyPolicy.OrgPolicyPolicy(this, "primary", {
name: `\${${googleFolderBasic.name}}/policies/gcp.resourceLocations`,
parent: googleFolderBasic.name,
spec: [
{
inherit_from_parent: true,
rules: [
{
deny_all: "TRUE",
},
],
},
],
});
Example Usage - organization_policy
A test of an orgpolicy policy for an organization
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.orgPolicyPolicy.OrgPolicyPolicy(this, "primary", {
name: "organizations/123456789/policies/gcp.detailedAuditLoggingMode",
parent: "organizations/123456789",
spec: [
{
reset: true,
},
],
});
Example Usage - project_policy
A test of an orgpolicy policy for a project
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleProjectBasic = new google.project.Project(this, "basic", {
name: "id",
org_id: "123456789",
project_id: "id",
});
new google.orgPolicyPolicy.OrgPolicyPolicy(this, "primary", {
name: `projects/\${${googleProjectBasic.name}}/policies/gcp.resourceLocations`,
parent: `projects/\${${googleProjectBasic.name}}`,
spec: [
{
rules: [
{
condition: [
{
description: "A sample condition for the policy",
expression:
"resource.matchLabels('labelKeys/123', 'labelValues/345')",
location: "sample-location.log",
title: "sample-condition",
},
],
values: [
{
allowed_values: ["projects/allowed-project"],
denied_values: ["projects/denied-project"],
},
],
},
{
allow_all: "TRUE",
},
],
},
],
});
Argument Reference
The following arguments are supported:
-
name
- (Required) Immutable. The resource name of the Policy. Must be one of the following forms, where constraint_name is the name of the constraint which this Policy configures: *projects/{projectNumber}/policies/{constraintName}
*folders/{folderId}/policies/{constraintName}
*organizations/{organizationId}/policies/{constraintName}
For example, "projects/123/policies/compute.disableSerialPortAccess". Note:projects/{projectId}/policies/{constraintName}
is also an acceptable name for API requests, but responses will return the name using the equivalent project number. -
parent
- (Required) The parent of the resource.
spec
- (Optional) Basic information about the Organization Policy.
The spec
block supports:
-
etag
- An opaque tag indicating the current version of thepolicy
, used for concurrency control. This field is ignored if used in acreatePolicy
request. When thepolicy
is returned from either agetPolicy
or alistPolicies
request, thisetag
indicates the version of the currentpolicy
to use when executing a read-modify-write loop. When thepolicy
is returned from agetEffectivePolicy
request, theetag
will be unset. -
inheritFromParent
- (Optional) Determines the inheritance behavior for thispolicy
. IfinheritFromParent
is true, PolicyRules set higher up in the hierarchy (up to the closest root) are inherited and present in the effective policy. If it is false, then no rules are inherited, and this Policy becomes the new root for evaluation. This field can be set only for Policies which configure list constraints. -
reset
- (Optional) Ignores policies set above this resource and restores theconstraintDefault
enforcement behavior of the specificconstraint
at this resource. This field can be set in policies for either list or boolean constraints. If set,rules
must be empty andinheritFromParent
must be set to false. -
rules
- (Optional) Up to 10 PolicyRules are allowed. In Policies for boolean constraints, the following requirements apply: - There must be one and only one PolicyRule where condition is unset. - BooleanPolicyRules with conditions must setenforced
to the opposite of the PolicyRule without a condition. - During policy evaluation, PolicyRules with conditions that are true for a target resource take precedence. -
updateTime
- Output only. The time stamp this was previously updated. This represents the last time a call tocreatePolicy
orupdatePolicy
was made for thatpolicy
.
The rules
block supports:
-
allowAll
- (Optional) Setting this to true means that all values are allowed. This field can be set only in Policies for list constraints. -
condition
- (Optional) A condition which determines whether this rule is used in the evaluation of the policy. When set, theexpression
field in the `Expr' must include from 1 to 10 subexpressions, joined by the "||" or "&&" operators. Each subexpression must be of the form "resource.matchTag('/tag_key_short_name, 'tag_value_short_name')". or "resource.matchTagId('tagKeys/key_id', 'tagValues/value_id')". where key_name and value_name are the resource names for Label Keys and Values. These names are available from the Tag Manager Service. An example expression is: "resource.matchTag('123456789/environment, 'prod')". or "resource.matchTagId('tagKeys/123', 'tagValues/456')". -
denyAll
- (Optional) Setting this to true means that all values are denied. This field can be set only in Policies for list constraints. -
enforce
- (Optional) Iftrue
, then thepolicy
is enforced. Iffalse
, then any configuration is acceptable. This field can be set only in Policies for boolean constraints. -
values
- (Optional) List of values to be used for this PolicyRule. This field can be set only in Policies for list constraints.
The condition
block supports:
-
description
- (Optional) Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. -
expression
- (Optional) Textual representation of an expression in Common Expression Language syntax. -
location
- (Optional) Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file. -
title
- (Optional) Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression.
The values
block supports:
-
allowedValues
- (Optional) List of values allowed at this resource. -
deniedValues
- (Optional) List of values denied at this resource.
Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with format{{parent}}/policies/{{name}}
Timeouts
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.
Import
Policy can be imported using any of these accepted formats: