| --- |
| subcategory: "Cloud Platform" |
| description: |- |
| Allows management of Organization policies for a Google Organization. |
| --- |
| |
| # google\_organization\_policy |
| |
| Allows management of Organization Policies for a Google Cloud Organization. |
| |
| ~> **Warning:** This resource has been superseded by `google_org_policy_policy`. `google_org_policy_policy` uses Organization Policy API V2 instead of Cloud Resource Manager API V1 and it supports additional features such as tags and conditions. |
| |
| To get more information about Organization Policies, see: |
| |
| * [API documentation](https://cloud.google.com/resource-manager/reference/rest/v1/organizations/setOrgPolicy) |
| * How-to Guides |
| * [Introduction to the Organization Policy Service](https://cloud.google.com/resource-manager/docs/organization-policy/overview) |
| |
| ## Example Usage |
| |
| To set policy with a [boolean constraint](https://cloud.google.com/resource-manager/docs/organization-policy/quickstart-boolean-constraints): |
| |
| ```hcl |
| resource "google_organization_policy" "serial_port_policy" { |
| org_id = "123456789" |
| constraint = "compute.disableSerialPortAccess" |
| |
| boolean_policy { |
| enforced = true |
| } |
| } |
| ``` |
| |
| |
| To set a policy with a [list constraint](https://cloud.google.com/resource-manager/docs/organization-policy/quickstart-list-constraints): |
| |
| ```hcl |
| resource "google_organization_policy" "services_policy" { |
| org_id = "123456789" |
| constraint = "serviceuser.services" |
| |
| list_policy { |
| allow { |
| all = true |
| } |
| } |
| } |
| ``` |
| |
| Or to deny some services, use the following instead: |
| |
| ```hcl |
| resource "google_organization_policy" "services_policy" { |
| org_id = "123456789" |
| constraint = "serviceuser.services" |
| |
| list_policy { |
| suggested_value = "compute.googleapis.com" |
| |
| deny { |
| values = ["cloudresourcemanager.googleapis.com"] |
| } |
| } |
| } |
| ``` |
| |
| To restore the default organization policy, use the following instead: |
| |
| ```hcl |
| resource "google_organization_policy" "services_policy" { |
| org_id = "123456789" |
| constraint = "serviceuser.services" |
| |
| restore_policy { |
| default = true |
| } |
| } |
| ``` |
| |
| ## Argument Reference |
| |
| The following arguments are supported: |
| |
| * `org_id` - (Required) The numeric ID of the organization to set the policy for. |
| |
| * `constraint` - (Required) The name of the Constraint the Policy is configuring, for example, `serviceuser.services`. Check out the [complete list of available constraints](https://cloud.google.com/resource-manager/docs/organization-policy/understanding-constraints#available_constraints). |
| |
| - - - |
| |
| * `version` - (Optional) Version of the Policy. Default version is 0. |
| |
| * `boolean_policy` - (Optional) A boolean policy is a constraint that is either enforced or not. Structure is [documented |
| below](#nested_boolean_policy). |
| |
| * `list_policy` - (Optional) A policy that can define specific values that are allowed or denied for the given constraint. It can also be used to allow or deny all values. Structure is [documented below](#nested_list_policy). |
| |
| * `restore_policy` - (Optional) A restore policy is a constraint to restore the default policy. Structure is [documented below](#nested_restore_policy). |
| |
| ~> **Note:** If none of [`boolean_policy`, `list_policy`, `restore_policy`] are defined the policy for a given constraint will |
| effectively be unset. This is represented in the UI as the constraint being 'Inherited'. |
| |
| - - - |
| |
| <a name="nested_boolean_policy"></a>The `boolean_policy` block supports: |
| |
| * `enforced` - (Required) If true, then the Policy is enforced. If false, then any configuration is acceptable. |
| |
| <a name="nested_list_policy"></a>The `list_policy` block supports: |
| |
| * `allow` or `deny` - (Optional) One or the other must be set. |
| |
| * `suggested_value` - (Optional) The Google Cloud Console will try to default to a configuration that matches the value specified in this field. |
| |
| * `inherit_from_parent` - (Optional) If set to true, the values from the effective Policy of the parent resource |
| are inherited, meaning the values set in this Policy are added to the values inherited up the hierarchy. |
| |
| The `allow` or `deny` blocks support: |
| |
| * `all` - (Optional) The policy allows or denies all values. |
| |
| * `values` - (Optional) The policy can define specific values that are allowed or denied. |
| |
| <a name="nested_restore_policy"></a>The `restore_policy` block supports: |
| |
| * `default` - (Required) May only be set to true. If set, then the default Policy is restored. |
| |
| ## Attributes Reference |
| |
| In addition to the arguments listed above, the following computed attributes are |
| exported: |
| |
| * `etag` - (Computed) The etag of the organization policy. `etag` is used for optimistic concurrency control as a way to help prevent simultaneous updates of a policy from overwriting each other. |
| |
| * `update_time` - (Computed) The timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds, representing when the variable was last updated. Example: "2016-10-09T12:33:37.578138407Z". |
| |
| ## Import |
| |
| Organization Policies can be imported using the `org_id` and the `constraint`, e.g. |
| |
| * `{{org_id}}/constraints/{{constraint}}` |
| |
| In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Organization Policies using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "{{org_id}}/constraints/{{constraint}}" |
| to = google_organization_policy.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Organization Policies can be imported using one of the formats above. For example: |
| |
| ``` |
| $ terraform import google_organization_policy.default {{org_id}}/constraints/{{constraint}} |
| ``` |
| |
| It is all right if the constraint contains a slash, as in the example above. |