Skip to content
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 template #3555

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 109 additions & 103 deletions products/datacatalog/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,106 +273,112 @@ objects:
Total number of shards.
output: true

# Blocked on b/155304495
# - !ruby/object:Api::Resource
# name: TagTemplate
# base_url: projects/{{project}}/locations/{{region}}/tagTemplates
# self_link: "{{name}}"
# create_url: projects/{{project}}/locations/{{region}}/tagTemplates?tagTemplateId={{tag_template_id}}
# update_verb: :PATCH
# update_mask: true
# description: |
# A tag template defines a tag, which can have one or more typed fields.
# The template is used to create and attach the tag to GCP resources.
# references: !ruby/object:Api::Resource::ReferenceLinks
# guides:
# 'Official Documentation': https://cloud.google.com/data-catalog/docs
# api: https://cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.tagTemplates
# parameters:
# - !ruby/object:Api::Type::String
# name: region
# url_param_only: true
# input: true
# description: |
# Template location region.
# - !ruby/object:Api::Type::String
# name: tagTemplateId
# required: true
# url_param_only: true
# input: true
# description: |
# The id of the tag template to create.
# properties:
# - !ruby/object:Api::Type::String
# name: name
# description: |
# The resource name of the tag template in URL format. Example: projects/{project_id}/locations/{location}/tagTemplates/{tagTemplateId}
# output: true
# - !ruby/object:Api::Type::String
# name: displayName
# description: |
# The display name for this template.
# - !ruby/object:Api::Type::Map
# name: fields
# description: |
# Map of tag template field IDs to the settings for the field. This map is an exhaustive list of the allowed fields. This map must contain at least one field and at most 500 fields.
# required: true
# key_name: field_id
# value_type: !ruby/object:Api::Type::NestedObject
# name: field
# properties:
# - !ruby/object:Api::Type::String
# name: name
# description: |
# The resource name of the tag template field in URL format. Example: projects/{project_id}/locations/{location}/tagTemplates/{tagTemplateId}/fields/{field}
# output: true
# - !ruby/object:Api::Type::String
# name: displayName
# description: |
# The display name for this field.
# - !ruby/object:Api::Type::NestedObject
# name: type
# description: |
# The type of value this tag field can contain.
# required: true
# properties:
# - !ruby/object:Api::Type::Enum
# name: primitiveType
# description: |
# Represents primitive types - string, bool etc.
# values:
# - :DOUBLE
# - :STRING
# - :BOOL
# - :TIMESTAMP
# - !ruby/object:Api::Type::NestedObject
# name: enumType
# description: |
# Represents an enum type.
# properties:
# - !ruby/object:Api::Type::Array
# name: allowedValues
# description: |
# The set of allowed values for this enum. The display names of the
# values must be case-insensitively unique within this set. Currently,
# enum values can only be added to the list of allowed values. Deletion
# and renaming of enum values are not supported.
# Can have up to 500 allowed values.
# required: true
# item_type: !ruby/object:Api::Type::NestedObject
# properties:
# - !ruby/object:Api::Type::String
# name: displayName
# description: |
# The display name of the enum value.
# required: true
# - !ruby/object:Api::Type::Boolean
# name: isRequired
# description: |
# Whether this is a required field. Defaults to false.
# - !ruby/object:Api::Type::Integer
# name: order
# description: |
# The order of this field with respect to other fields in this tag template.
# A higher value indicates a more important field. The value can be negative.
# Multiple fields can have the same order, and field orders within a tag do not have to be sequential.
- !ruby/object:Api::Resource
name: TagTemplate
base_url: projects/{{project}}/locations/{{region}}/tagTemplates
self_link: "{{name}}"
create_url: projects/{{project}}/locations/{{region}}/tagTemplates?tagTemplateId={{tag_template_id}}
delete_url: "{{name}}?force={{force_delete}}"
update_verb: :PATCH
update_mask: true
description: |
A tag template defines a tag, which can have one or more typed fields.
The template is used to create and attach the tag to GCP resources.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation': https://cloud.google.com/data-catalog/docs
api: https://cloud.google.com/data-catalog/docs/reference/rest/v1/projects.locations.tagTemplates
parameters:
- !ruby/object:Api::Type::String
name: region
url_param_only: true
input: true
description: |
Template location region.
- !ruby/object:Api::Type::String
name: tagTemplateId
required: true
url_param_only: true
input: true
description: |
The id of the tag template to create.
- !ruby/object:Api::Type::Boolean
name: forceDelete
url_param_only: true
description: |
This confirms the deletion of any possible tags using this template. Must be set to true in order to delete the tag template.
properties:
- !ruby/object:Api::Type::String
name: name
description: |
The resource name of the tag template in URL format. Example: projects/{project_id}/locations/{location}/tagTemplates/{tagTemplateId}
output: true
- !ruby/object:Api::Type::String
name: displayName
description: |
The display name for this template.
- !ruby/object:Api::Type::Map
name: fields
description: |
Map of tag template field IDs to the settings for the field. This map is an exhaustive list of the allowed fields. This map must contain at least one field and at most 500 fields.
required: true
input: true # TODO(danawillow): update logic
key_name: field_id
value_type: !ruby/object:Api::Type::NestedObject
name: field
properties:
- !ruby/object:Api::Type::String
name: name
description: |
The resource name of the tag template field in URL format. Example: projects/{project_id}/locations/{location}/tagTemplates/{tagTemplateId}/fields/{field}
output: true
- !ruby/object:Api::Type::String
name: displayName
description: |
The display name for this field.
- !ruby/object:Api::Type::NestedObject
name: type
description: |
The type of value this tag field can contain.
required: true
properties:
- !ruby/object:Api::Type::Enum
name: primitiveType
description: |
Represents primitive types - string, bool etc.
values:
- :DOUBLE
- :STRING
- :BOOL
- :TIMESTAMP
- !ruby/object:Api::Type::NestedObject
name: enumType
description: |
Represents an enum type.
properties:
- !ruby/object:Api::Type::Array
name: allowedValues
description: |
The set of allowed values for this enum. The display names of the
values must be case-insensitively unique within this set. Currently,
enum values can only be added to the list of allowed values. Deletion
and renaming of enum values are not supported.
Can have up to 500 allowed values.
required: true
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: displayName
description: |
The display name of the enum value.
required: true
- !ruby/object:Api::Type::Boolean
name: isRequired
description: |
Whether this is a required field. Defaults to false.
- !ruby/object:Api::Type::Integer
name: order
description: |
The order of this field with respect to other fields in this tag template.
A higher value indicates a more important field. The value can be negative.
Multiple fields can have the same order, and field orders within a tag do not have to be sequential.
56 changes: 33 additions & 23 deletions products/datacatalog/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,39 @@ overrides: !ruby/object:Overrides::ResourceOverrides
regex: '^[A-z_][A-z0-9_]{0,63}$'
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/data_catalog_entry.go.erb
# TagTemplate: !ruby/object:Overrides::Terraform::ResourceOverride
# examples:
# - !ruby/object:Provider::Terraform::Examples
# name: "data_catalog_tag_template_basic"
# primary_resource_id: "basic_tag_template"
# vars:
# tag_template_id: "my-template"
# properties:
# fields: !ruby/object:Overrides::Terraform::PropertyOverride
# description: |
# Set of tag template field IDs and the settings for the field. This set is an exhaustive list of the allowed fields. This set must contain at least one field and at most 500 fields.
# fields.type.enumType: !ruby/object:Overrides::Terraform::PropertyOverride
# description: |
# {{description}} Exactly one of `primitive_type` or `enum_type` must be set
# fields.type.enumType.allowedValues: !ruby/object:Overrides::Terraform::PropertyOverride
# is_set: true
# fields.type.primitiveType: !ruby/object:Overrides::Terraform::PropertyOverride
# description: |
# {{description}} Exactly one of `primitive_type` or `enum_type` must be set
# region: !ruby/object:Overrides::Terraform::PropertyOverride
# ignore_read: true
# required: false
# default_from_api: true
TagTemplate: !ruby/object:Overrides::Terraform::ResourceOverride
examples:
- !ruby/object:Provider::Terraform::Examples
name: "data_catalog_tag_template_basic"
primary_resource_id: "basic_tag_template"
vars:
tag_template_id: "my_template"
force_delete: "false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for the docs, correct? do we want to put false in there yet before it's supported by the API? I don't have a strong opinion either way, just wanted to check thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, same rationale here as the bigtable one where I prefer to recommend the safer option for users and make them explicitly have to switch over to the one that lets them delete the resource when they decide to do so.

test_vars_overrides:
force_delete: "true"
oics_vars_overrides:
force_delete: "true"
properties:
tagTemplateId: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
regex: '^[a-z_][a-z0-9_]{0,63}$'
fields: !ruby/object:Overrides::Terraform::PropertyOverride
description: |
Set of tag template field IDs and the settings for the field. This set is an exhaustive list of the allowed fields. This set must contain at least one field and at most 500 fields.
fields.type.enumType: !ruby/object:Overrides::Terraform::PropertyOverride
description: |
{{description}} Exactly one of `primitive_type` or `enum_type` must be set
fields.type.enumType.allowedValues: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true
fields.type.primitiveType: !ruby/object:Overrides::Terraform::PropertyOverride
description: |
{{description}} Exactly one of `primitive_type` or `enum_type` must be set
region: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
required: false
default_from_api: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/data_catalog_tag_template.go.erb
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
18 changes: 18 additions & 0 deletions templates/terraform/custom_import/data_catalog_tag_template.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
config := meta.(*Config)

// current import_formats can't import fields with forward slashes in their value
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
return nil, err
}

name := d.Get("name").(string)
egRegex := regexp.MustCompile("projects/(.+)/locations/(.+)/tagTemplates/(.+)")

parts := egRegex.FindStringSubmatch(name)
if len(parts) != 4 {
return nil, fmt.Errorf("entry group name does not fit the format %s", egRegex)
}
d.Set("project", parts[1])
d.Set("region", parts[2])
d.Set("tag_template_id", parts[3])
return []*schema.ResourceData{d}, nil
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ resource "google_data_catalog_tag_template" "<%= ctx[:primary_resource_id] %>" {
}
}
}

force_delete = "<%= ctx[:vars]['force_delete'] %>"
}