Skip to content

Commit

Permalink
bigquery datamasking (#6425) (#12725)
Browse files Browse the repository at this point in the history
* data masking

* data masking - examples

* import

* cr comments

* cr comments - update test

* align with connection resource

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Oct 5, 2022
1 parent a4725e5 commit c603d35
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .changelog/6425.txt
@@ -0,0 +1,12 @@
```release-note:new-resource
google_bigquery_datapolicy_data_policy
```
```release-note:new-resource
google_bigquery_datapolicy_data_policy_iam_binding
```
```release-note:new-resource
google_bigquery_datapolicy_data_policy_iam_member
```
```release-note:new-resource
google_bigquery_datapolicy_data_policy_iam_policy
```
1 change: 1 addition & 0 deletions google/resource_bigquery_datapolicy_data_policy_test.go
@@ -0,0 +1 @@
package google
141 changes: 141 additions & 0 deletions website/docs/r/bigquery_datapolicy_data_policy.html.markdown
@@ -0,0 +1,141 @@
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "BigQuery Data Policy"
page_title: "Google: google_bigquery_datapolicy_data_policy"
description: |-
A BigQuery Data Policy
---

# google\_bigquery\_datapolicy\_data\_policy

A BigQuery Data Policy

~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.

To get more information about DataPolicy, see:

* [API documentation](https://cloud.google.com/bigquery/docs/reference/bigquerydatapolicy/rest/v1beta1/projects.locations.dataPolicies/create)
* How-to Guides
* [Official Documentation](https://cloud.google.com/bigquery/docs/column-data-masking-intro)

<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=bigquery_datapolicy_data_policy_basic&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Bigquery Datapolicy Data Policy Basic


```hcl
resource "google_bigquery_datapolicy_data_policy" "data_policy" {
provider = google-beta
location = "us-central1"
data_policy_id = "data_policy"
policy_tag = google_data_catalog_policy_tag.policy_tag.name
data_policy_type = "COLUMN_LEVEL_SECURITY_POLICY"
}
resource "google_data_catalog_policy_tag" "policy_tag" {
provider = google-beta
taxonomy = google_data_catalog_taxonomy.taxonomy.id
display_name = "Low security"
description = "A policy tag normally associated with low security items"
}
resource "google_data_catalog_taxonomy" "taxonomy" {
provider = google-beta
region = "us-central1"
display_name = "taxonomy"
description = "A collection of policy tags"
activated_policy_types = ["FINE_GRAINED_ACCESS_CONTROL"]
}
```

## Argument Reference

The following arguments are supported:


* `data_policy_id` -
(Required)
User-assigned (human readable) ID of the data policy that needs to be unique within a project. Used as {dataPolicyId} in part of the resource name.

* `location` -
(Required)
The name of the location of the data policy.

* `policy_tag` -
(Required)
Policy tag resource name, in the format of projects/{project_number}/locations/{locationId}/taxonomies/{taxonomyId}/policyTags/{policyTag_id}.

* `data_policy_type` -
(Required)
The enrollment level of the service.
Possible values are `COLUMN_LEVEL_SECURITY_POLICY` and `DATA_MASKING_POLICY`.


- - -


* `data_masking_policy` -
(Optional)
The data masking policy that specifies the data masking rule to use.
Structure is [documented below](#nested_data_masking_policy).

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.


<a name="nested_data_masking_policy"></a>The `data_masking_policy` block supports:

* `predefined_expression` -
(Required)
The available masking rules. Learn more here: https://cloud.google.com/bigquery/docs/column-data-masking-intro#masking_options.
Possible values are `SHA256`, `ALWAYS_NULL`, and `DEFAULT_MASKING_VALUE`.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

* `id` - an identifier for the resource with format `projects/{{project}}/locations/{{location}}/dataPolicies/{{data_policy_id}}`

* `name` -
Resource name of this data policy, in the format of projects/{project_number}/locations/{locationId}/dataPolicies/{dataPolicyId}.


## Timeouts

This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 20 minutes.
- `update` - Default is 20 minutes.
- `delete` - Default is 20 minutes.

## Import


DataPolicy can be imported using any of these accepted formats:

```
$ terraform import google_bigquery_datapolicy_data_policy.default projects/{{project}}/locations/{{location}}/dataPolicies/{{data_policy_id}}
$ terraform import google_bigquery_datapolicy_data_policy.default {{project}}/{{location}}/{{data_policy_id}}
$ terraform import google_bigquery_datapolicy_data_policy.default {{location}}/{{data_policy_id}}
```

## User Project Overrides

This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).
156 changes: 156 additions & 0 deletions website/docs/r/bigquery_datapolicy_data_policy_iam.html.markdown
@@ -0,0 +1,156 @@
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "BigQuery Data Policy"
page_title: "Google: google_bigquery_datapolicy_data_policy_iam"
description: |-
Collection of resources to manage IAM policy for BigQuery Data Policy DataPolicy
---

# IAM policy for BigQuery Data Policy DataPolicy
Three different resources help you manage your IAM policy for BigQuery Data Policy DataPolicy. Each of these resources serves a different use case:

* `google_bigquery_datapolicy_data_policy_iam_policy`: Authoritative. Sets the IAM policy for the datapolicy and replaces any existing policy already attached.
* `google_bigquery_datapolicy_data_policy_iam_binding`: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the datapolicy are preserved.
* `google_bigquery_datapolicy_data_policy_iam_member`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the datapolicy are preserved.

~> **Note:** `google_bigquery_datapolicy_data_policy_iam_policy` **cannot** be used in conjunction with `google_bigquery_datapolicy_data_policy_iam_binding` and `google_bigquery_datapolicy_data_policy_iam_member` or they will fight over what your policy should be.

~> **Note:** `google_bigquery_datapolicy_data_policy_iam_binding` resources **can be** used in conjunction with `google_bigquery_datapolicy_data_policy_iam_member` resources **only if** they do not grant privilege to the same role.


~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.


## google\_bigquery\_datapolicy\_data\_policy\_iam\_policy

```hcl
data "google_iam_policy" "admin" {
provider = google-beta
binding {
role = "roles/viewer"
members = [
"user:jane@example.com",
]
}
}
resource "google_bigquery_datapolicy_data_policy_iam_policy" "policy" {
provider = google-beta
project = google_bigquery_datapolicy_data_policy.data_policy.project
location = google_bigquery_datapolicy_data_policy.data_policy.location
data_policy_id = google_bigquery_datapolicy_data_policy.data_policy.data_policy_id
policy_data = data.google_iam_policy.admin.policy_data
}
```

## google\_bigquery\_datapolicy\_data\_policy\_iam\_binding

```hcl
resource "google_bigquery_datapolicy_data_policy_iam_binding" "binding" {
provider = google-beta
project = google_bigquery_datapolicy_data_policy.data_policy.project
location = google_bigquery_datapolicy_data_policy.data_policy.location
data_policy_id = google_bigquery_datapolicy_data_policy.data_policy.data_policy_id
role = "roles/viewer"
members = [
"user:jane@example.com",
]
}
```

## google\_bigquery\_datapolicy\_data\_policy\_iam\_member

```hcl
resource "google_bigquery_datapolicy_data_policy_iam_member" "member" {
provider = google-beta
project = google_bigquery_datapolicy_data_policy.data_policy.project
location = google_bigquery_datapolicy_data_policy.data_policy.location
data_policy_id = google_bigquery_datapolicy_data_policy.data_policy.data_policy_id
role = "roles/viewer"
member = "user:jane@example.com"
}
```

## Argument Reference

The following arguments are supported:

* `location` - (Required) The name of the location of the data policy.
Used to find the parent resource to bind the IAM policy to

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the project will be parsed from the identifier of the parent resource. If no project is provided in the parent identifier and no project is specified, the provider project is used.

* `member/members` - (Required) Identities that will be granted the privilege in `role`.
Each entry can have one of the following values:
* **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account.
* **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account.
* **user:{emailid}**: An email address that represents a specific Google account. For example, alice@gmail.com or joe@example.com.
* **serviceAccount:{emailid}**: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com.
* **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com.
* **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com.
* **projectOwner:projectid**: Owners of the given project. For example, "projectOwner:my-example-project"
* **projectEditor:projectid**: Editors of the given project. For example, "projectEditor:my-example-project"
* **projectViewer:projectid**: Viewers of the given project. For example, "projectViewer:my-example-project"

* `role` - (Required) The role that should be applied. Only one
`google_bigquery_datapolicy_data_policy_iam_binding` can be used per role. Note that custom roles must be of the format
`[projects|organizations]/{parent-name}/roles/{role-name}`.

* `policy_data` - (Required only by `google_bigquery_datapolicy_data_policy_iam_policy`) The policy data generated by
a `google_iam_policy` data source.

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are
exported:

* `etag` - (Computed) The etag of the IAM policy.

## Import

For all import syntaxes, the "resource in question" can take any of the following forms:

* projects/{{project}}/locations/{{location}}/dataPolicies/{{data_policy_id}}
* {{project}}/{{location}}/{{data_policy_id}}
* {{location}}/{{data_policy_id}}
* {{data_policy_id}}

Any variables not passed in the import command will be taken from the provider configuration.

BigQuery Data Policy datapolicy IAM resources can be imported using the resource identifiers, role, and member.

IAM member imports use space-delimited identifiers: the resource in question, the role, and the member identity, e.g.
```
$ terraform import google_bigquery_datapolicy_data_policy_iam_member.editor "projects/{{project}}/locations/{{location}}/dataPolicies/{{data_policy_id}} roles/viewer user:jane@example.com"
```

IAM binding imports use space-delimited identifiers: the resource in question and the role, e.g.
```
$ terraform import google_bigquery_datapolicy_data_policy_iam_binding.editor "projects/{{project}}/locations/{{location}}/dataPolicies/{{data_policy_id}} roles/viewer"
```

IAM policy imports use the identifier of the resource in question, e.g.
```
$ terraform import google_bigquery_datapolicy_data_policy_iam_policy.editor projects/{{project}}/locations/{{location}}/dataPolicies/{{data_policy_id}}
```

-> **Custom Roles**: If you're importing a IAM resource with a custom role, make sure to use the
full name of the custom role, e.g. `[projects/my-project|organizations/my-org]/roles/my-custom-role`.

## User Project Overrides

This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).

0 comments on commit c603d35

Please sign in to comment.