Data catalog Tag module (#2060)
* First commit * Update README * Add todo * Fix required_version
This commit is contained in:
@@ -79,6 +79,7 @@ These modules are used in the examples included in this repository. If you are u
|
||||
- [Bigtable instance](./bigtable-instance)
|
||||
- [Cloud SQL instance](./cloudsql-instance)
|
||||
- [Data Catalog Policy Tag](./data-catalog-policy-tag)
|
||||
- [Data Catalog Tag](./data-catalog-tag)
|
||||
- [Data Catalog Tag Template](./data-catalog-tag-template)
|
||||
- [Dataform Repository](./dataform-repository/)
|
||||
- [Datafusion](./datafusion)
|
||||
|
||||
126
modules/data-catalog-tag/README.md
Normal file
126
modules/data-catalog-tag/README.md
Normal file
@@ -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: example@example.com
|
||||
```
|
||||
<!-- 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 -->
|
||||
38
modules/data-catalog-tag/main.tf
Normal file
38
modules/data-catalog-tag/main.tf
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
20
modules/data-catalog-tag/outputs.tf
Normal file
20
modules/data-catalog-tag/outputs.tf
Normal file
@@ -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 }
|
||||
}
|
||||
37
modules/data-catalog-tag/variables.tf
Normal file
37
modules/data-catalog-tag/variables.tf
Normal file
@@ -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 = {}
|
||||
}
|
||||
27
modules/data-catalog-tag/versions.tf
Normal file
27
modules/data-catalog-tag/versions.tf
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user