-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First commit * Update README * Add todo * Fix required_version
- Loading branch information
Showing
7 changed files
with
250 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Google Cloud Data Catalog Tag Module | ||
|
||
This module allows managing [Data Catalog Tag](https://cloud.google.com/data-catalog/docs/tags-and-tag-templates) on GCP resources such as BigQuery Datasets, Tables or columns. | ||
|
||
## TODO | ||
|
||
- Add support for entries different than Bigquery resources. | ||
|
||
## Examples | ||
|
||
### Dataset Tag | ||
|
||
```hcl | ||
module "data-catalog-tag" { | ||
source = "./fabric/modules/data-catalog-tag" | ||
tags = { | ||
"landing/countries" = { | ||
project_id = "project-data-product" | ||
parent = "projects/project-data-product/datasets/landing" | ||
location = "europe-west-1" | ||
template = "projects/project-datagov/locations/europe-west1/tagTemplates/demo" | ||
fields = { | ||
source = "DB-1" | ||
} | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=1 | ||
``` | ||
|
||
### Table Tag | ||
|
||
```hcl | ||
module "data-catalog-tag" { | ||
source = "./fabric/modules/data-catalog-tag" | ||
tags = { | ||
"landing/countries" = { | ||
project_id = "project-data-product" | ||
parent = "projects/project-data-product/datasets/landing/tables/countries" | ||
location = "europe-west-1" | ||
template = "projects/project-datagov/locations/europe-west1/tagTemplates/demo" | ||
fields = { | ||
source = "DB-1 Table-A" | ||
} | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=1 | ||
``` | ||
|
||
### Column Tag | ||
|
||
```hcl | ||
module "data-catalog-tag" { | ||
source = "./fabric/modules/data-catalog-tag" | ||
tags = { | ||
"landing/countries" = { | ||
project_id = "project-data-product" | ||
parent = "projects/project-data-product/datasets/landing/tables/countries" | ||
column = "country" | ||
location = "europe-west-1" | ||
template = "projects/project-datagov/locations/europe-west1/tagTemplates/demo" | ||
fields = { | ||
source = "DB-1 Table-A Column-B" | ||
} | ||
} | ||
} | ||
} | ||
# tftest modules=1 resources=1 | ||
``` | ||
|
||
### Factory | ||
|
||
Similarly to other modules, a rules factory (see [Resource Factories](../../blueprints/factories/)) is also included here to allow tags management via descriptive configuration files. | ||
|
||
Factory configuration is via one optional attributes in the `factory_config_path` variable specifying the path where tags files are stored. | ||
|
||
Factory tags are merged with rules declared in code, with the latter taking precedence where both use the same key. | ||
|
||
This is an example of a simple factory: | ||
|
||
```hcl | ||
module "data-catalog-tag" { | ||
source = "./fabric/modules/data-catalog-tag" | ||
tags = { | ||
"landing/countries" = { | ||
project_id = "project-data-product" | ||
parent = "projects/project-data-product/datasets/landing/tables/countries" | ||
column = "country" | ||
location = "europe-west-1" | ||
template = "projects/project-datagov/locations/europe-west1/tagTemplates/demo" | ||
fields = { | ||
source = "DB-1 Table-A Column-B" | ||
} | ||
} | ||
} | ||
factories_config = { | ||
tags = "data" | ||
} | ||
} | ||
# tftest modules=1 resources=2 files=demo_tag | ||
``` | ||
|
||
```yaml | ||
# tftest-file id=demo_tag path=data/tag_1.yaml | ||
|
||
project_id: project-data-product | ||
parent: projects/project-data-product/datasets/exposure | ||
template: projects/project-datagov/locations/europe-west1/tagTemplates/test | ||
fields: | ||
owner_email: [email protected] | ||
``` | ||
<!-- BEGIN TFDOC --> | ||
## Variables | ||
| name | description | type | required | default | | ||
|---|---|:---:|:---:|:---:| | ||
| [factories_config](variables.tf#L17) | Paths to data files and folders that enable factory functionality. | <code title="object({ tags = optional(string) })">object({…})</code> | | <code>{}</code> | | ||
| [tags](variables.tf#L26) | Tags definitions in the form {TAG => TAG_DEFINITION}. | <code title="map(object({ project_id = string parent = string column = optional(string) location = string template = string fields = map(string) }))">map(object({…}))</code> | | <code>{}</code> | | ||
## Outputs | ||
| name | description | sensitive | | ||
|---|---|:---:| | ||
| [data_catalog_tag_ids](outputs.tf#L17) | Data catalog tag ids. | | | ||
<!-- END TFDOC --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
locals { | ||
_factory_tag_template = { | ||
for f in try(fileset(var.factories_config.tags, "*.yaml"), []) : | ||
trimsuffix(f, ".yaml") => yamldecode(file("${var.factories_config.tags}/${f}")) | ||
} | ||
|
||
factory_tag_template = merge(local._factory_tag_template, var.tags) | ||
} | ||
|
||
resource "google_data_catalog_tag" "engine" { | ||
for_each = local.factory_tag_template | ||
parent = "projects/${each.value.project_id}/locations/${each.value.project_id}/entryGroups/@bigquery/entries/${trim(base64encode(each.value.parent), "=")}" | ||
column = try(each.value.column, null) | ||
template = each.value.template | ||
dynamic "fields" { | ||
for_each = each.value.fields | ||
content { | ||
field_name = fields.key | ||
string_value = fields.value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
output "data_catalog_tag_ids" { | ||
description = "Data catalog tag ids." | ||
value = { for k, v in google_data_catalog_tag.engine : k => v.id } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "factories_config" { | ||
description = "Paths to data files and folders that enable factory functionality." | ||
type = object({ | ||
tags = optional(string) | ||
}) | ||
nullable = false | ||
default = {} | ||
} | ||
|
||
variable "tags" { | ||
description = "Tags definitions in the form {TAG => TAG_DEFINITION}." | ||
type = map(object({ | ||
project_id = string | ||
parent = string | ||
column = optional(string) | ||
location = string | ||
template = string | ||
fields = map(string) | ||
})) | ||
default = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
terraform { | ||
required_version = ">= 1.7.0" | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = ">= 5.11.0, < 6.0.0" # tftest | ||
} | ||
google-beta = { | ||
source = "hashicorp/google-beta" | ||
version = ">= 5.11.0, < 6.0.0" # tftest | ||
} | ||
} | ||
} |