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 Entry #3532

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
374 changes: 374 additions & 0 deletions products/datacatalog/api.yaml

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions products/datacatalog/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright 2020 Google Inc.
# 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.

--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
EntryGroup: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ["{{name}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: "data_catalog_entry_group_basic"
primary_resource_id: "basic_entry_group"
primary_resource_name: "fmt.Sprintf(\"tf_test_my_group%s\", context[\"random_suffix\"])"
vars:
entry_group_id: "my_group"
- !ruby/object:Provider::Terraform::Examples
name: "data_catalog_entry_group_full"
primary_resource_id: "basic_entry_group"
primary_resource_name: "fmt.Sprintf(\"tf_test_my_group%s\", context[\"random_suffix\"])"
vars:
entry_group_id: "my_group"
properties:
entryGroupId: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
regex: '^[A-z_][A-z0-9_]{0,63}$'
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_entry_group.go.erb
Entry: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ["{{name}}"]
supports_indirect_user_project_override: true
examples:
- !ruby/object:Provider::Terraform::Examples
name: "data_catalog_entry_basic"
primary_resource_id: "basic_entry"
vars:
entry_id: "my_entry"
entry_group_id: "my_group"
- !ruby/object:Provider::Terraform::Examples
name: "data_catalog_entry_fileset"
primary_resource_id: "basic_entry"
vars:
entry_id: "my_entry"
entry_group_id: "my_group"
- !ruby/object:Provider::Terraform::Examples
name: "data_catalog_entry_full"
primary_resource_id: "basic_entry"
vars:
entry_id: "my_entry"
entry_group_id: "my_group"
properties:
linkedResource: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
schema: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/json_schema.erb'
custom_flatten: 'templates/terraform/custom_flatten/json_schema.erb'
state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }'
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.ValidateJsonString'
userSpecifiedSystem: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
regex: '^[A-z_][A-z0-9_]{0,63}$'
userSpecifiedType: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
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
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
# This is usually to add licensing info, autogeneration notices, etc.
compile:
<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%>
4 changes: 2 additions & 2 deletions products/healthcare/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
creationTime: !ruby/object:Overrides::Terraform::PropertyOverride
exclude: true
parserConfig.schema: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/healthcare_hl7_v2_store_schema.erb'
custom_flatten: 'templates/terraform/custom_flatten/healthcare_hl7_v2_store_schema.erb'
custom_expand: 'templates/terraform/custom_expand/json_schema.erb'
custom_flatten: 'templates/terraform/custom_flatten/json_schema.erb'
state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }'
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.ValidateJsonString'
Expand Down
17 changes: 17 additions & 0 deletions templates/terraform/custom_import/data_catalog_entry.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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/.+/entryGroups/.+)/entries/(.+)")

parts := egRegex.FindStringSubmatch(name)
if len(parts) != 3 {
return nil, fmt.Errorf("entry name does not fit the format %s", egRegex)
}
d.Set("entry_group", parts[1])
d.Set("entry_id", parts[2])
return []*schema.ResourceData{d}, nil
18 changes: 18 additions & 0 deletions templates/terraform/custom_import/data_catalog_entry_group.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/(.+)/entryGroups/(.+)")

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("entry_group_id", parts[3])
return []*schema.ResourceData{d}, nil
11 changes: 11 additions & 0 deletions templates/terraform/examples/data_catalog_entry_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "google_data_catalog_entry" "<%= ctx[:primary_resource_id] %>" {
entry_group = google_data_catalog_entry_group.entry_group.id
entry_id = "<%= ctx[:vars]['entry_id'] %>"

user_specified_type = "my_custom_type"
user_specified_system = "SomethingExternal"
}

resource "google_data_catalog_entry_group" "entry_group" {
entry_group_id = "<%= ctx[:vars]['entry_group_id'] %>"
}
14 changes: 14 additions & 0 deletions templates/terraform/examples/data_catalog_entry_fileset.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "google_data_catalog_entry" "<%= ctx[:primary_resource_id] %>" {
entry_group = google_data_catalog_entry_group.entry_group.id
entry_id = "<%= ctx[:vars]['entry_id'] %>"

type = "FILESET"

gcs_fileset_spec {
file_patterns = ["gs://fake_bucket/dir/*"]
}
}

resource "google_data_catalog_entry_group" "entry_group" {
entry_group_id = "<%= ctx[:vars]['entry_group_id'] %>"
}
54 changes: 54 additions & 0 deletions templates/terraform/examples/data_catalog_entry_full.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
resource "google_data_catalog_entry" "<%= ctx[:primary_resource_id] %>" {
entry_group = google_data_catalog_entry_group.entry_group.id
entry_id = "<%= ctx[:vars]['entry_id'] %>"

user_specified_type = "my_user_specified_type"
user_specified_system = "Something_custom"
linked_resource = "my/linked/resource"

display_name = "my custom type entry"
description = "a custom type entry for a user specified system"

schema = <<EOF
{
"columns": [
{
"column": "first_name",
"description": "First name",
"mode": "REQUIRED",
"type": "STRING"
},
{
"column": "last_name",
"description": "Last name",
"mode": "REQUIRED",
"type": "STRING"
},
{
"column": "address",
"description": "Address",
"mode": "REPEATED",
"subcolumns": [
{
"column": "city",
"description": "City",
"mode": "NULLABLE",
"type": "STRING"
},
{
"column": "state",
"description": "State",
"mode": "NULLABLE",
"type": "STRING"
}
],
"type": "RECORD"
}
]
}
EOF
}

resource "google_data_catalog_entry_group" "entry_group" {
entry_group_id = "<%= ctx[:vars]['entry_group_id'] %>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "google_data_catalog_entry_group" "<%= ctx[:primary_resource_id] %>" {
entry_group_id = "<%= ctx[:vars]['entry_group_id'] %>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "google_data_catalog_entry_group" "<%= ctx[:primary_resource_id] %>" {
entry_group_id = "<%= ctx[:vars]['entry_group_id'] %>"

display_name = "terraform entry group"
description = "entry group created by Terraform"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "google_data_catalog_tag_template" "<%= ctx[:primary_resource_id] %>" {
tag_template_id = "<%= ctx[:vars]['tag_template_id'] %>"
region = "us-central1"
display_name = "Demo Tag Template"

fields {
field_id = "source"
display_name = "Source of data asset"
type {
primitive_type = "STRING"
}
is_required = true
}

fields {
field_id = "num_rows"
display_name = "Number of rows in the data asset"
type {
primitive_type = "DOUBLE"
}
}

fields {
field_id = "pii_type"
display_name = "PII type"
type {
enum_type {
allowed_values {
display_name = "EMAIL"
}
allowed_values {
display_name = "SOCIAL SECURITY NUMBER"
}
allowed_values {
display_name = "NONE"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataCatalogEntryGroup_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDataCatalogEntryGroupDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataCatalogEntryGroup_dataCatalogEntryGroupBasicExample(context),
},
{
ResourceName: "google_data_catalog_entry_group.basic_entry_group",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDataCatalogEntryGroup_dataCatalogEntryGroupFullExample(context),
},
{
ResourceName: "google_data_catalog_entry_group.basic_entry_group",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDataCatalogEntryGroup_dataCatalogEntryGroupBasicExample(context),
},
{
ResourceName: "google_data_catalog_entry_group.basic_entry_group",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
47 changes: 47 additions & 0 deletions third_party/terraform/tests/resource_data_catalog_entry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataCatalogEntry_update(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDataCatalogEntryDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataCatalogEntry_dataCatalogEntryBasicExample(context),
},
{
ResourceName: "google_data_catalog_entry.basic_entry",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDataCatalogEntry_dataCatalogEntryFullExample(context),
},
{
ResourceName: "google_data_catalog_entry.basic_entry",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDataCatalogEntry_dataCatalogEntryBasicExample(context),
},
{
ResourceName: "google_data_catalog_entry.basic_entry",
ImportState: true,
ImportStateVerify: true,
},
},
})
}