-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data catalog Tag module #2060
Merged
Merged
Data catalog Tag module #2060
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e2da2c8
First commit
lcaggio d265838
Update README
lcaggio 6314d16
Add todo
lcaggio ddc5970
Fix required_version
lcaggio 2684345
Merge branch 'master' into lcaggio/datcat-tag
lcaggio 10085a2
Merge branch 'master' into lcaggio/datcat-tag
lcaggio aa5abe9
Merge branch 'master' into lcaggio/datcat-tag
lcaggio File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: 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 --> |
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), "=")}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?