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

New Resource : google_dialogflowcx_entity_type #4924

Merged
merged 11 commits into from
Aug 4, 2021
Merged
102 changes: 102 additions & 0 deletions mmv1/products/dialogflowcx/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -871,3 +871,105 @@ objects:
description: |
The target flow to transition to.
Format: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>.
- !ruby/object:Api::Resource
name: 'EntityType'
base_url: "{{parent}}/entityTypes"
jcanizalez marked this conversation as resolved.
Show resolved Hide resolved
update_verb: :PATCH
update_mask: true
description: |
Entities are extracted from user input and represent parameters that are meaningful to your application.
For example, a date range, a proper name such as a geographic location or landmark, and so on. Entities represent actionable data for your application.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/dialogflow/cx/docs'
api: 'https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents.entityTypes'
parameters:
- !ruby/object:Api::Type::String
name: parent
url_param_only: true
input: true
description: |
The agent to create a entity type for.
Format: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>.
- !ruby/object:Api::Type::String
name: 'languageCode'
description: |
The language of the following fields in entityType:
EntityType.entities.value
EntityType.entities.synonyms
EntityType.excluded_phrases.value
If not specified, the agent's default language is used. Many languages are supported. Note: languages must be enabled in the agent before they can be used.
input: true
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: 'name'
output: true
description: |
The unique identifier of the entity type.
Format: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/entityTypes/<Entity Type ID>.
- !ruby/object:Api::Type::String
name: 'displayName'
required: true
description: |
The human-readable name of the entity type, unique within the agent.
- !ruby/object:Api::Type::Enum
name: 'kind'
required: true
description: |
Indicates whether the entity type can be automatically expanded.
* KIND_MAP: Map entity types allow mapping of a group of synonyms to a canonical value.
* KIND_LIST: List entity types contain a set of entries that do not map to canonical values. However, list entity types can contain references to other entity types (with or without aliases).
* KIND_REGEXP: Regexp entity types allow to specify regular expressions in entries values.
values:
- :KIND_MAP
- :KIND_LIST
- :KIND_REGEXP
- !ruby/object:Api::Type::Enum
name: 'autoExpansionMode'
description: |
Represents kinds of entities.
* AUTO_EXPANSION_MODE_UNSPECIFIED: Auto expansion disabled for the entity.
* AUTO_EXPANSION_MODE_DEFAULT: Allows an agent to recognize values that have not been explicitly listed in the entity.
values:
- :AUTO_EXPANSION_MODE_DEFAULT
- :AUTO_EXPANSION_MODE_UNSPECIFIED
- !ruby/object:Api::Type::Array
name: 'entities'
required: true
description: |
The collection of entity entries associated with the entity type.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'value'
description: |
The primary value associated with this entity entry. For example, if the entity type is vegetable, the value could be scallions.
For KIND_MAP entity types: A canonical value to be used in place of synonyms.
For KIND_LIST entity types: A string that can contain references to other entity types (with or without aliases).
- !ruby/object:Api::Type::Array
name: 'synonyms'
item_type: Api::Type::String
description: |
A collection of value synonyms. For example, if the entity type is vegetable, and value is scallions, a synonym could be green onions.
For KIND_LIST entity types: This collection must contain exactly one synonym equal to value.
- !ruby/object:Api::Type::Array
name: 'excludedPhrases'
description: |
Collection of exceptional words and phrases that shouldn't be matched. For example, if you have a size entity type with entry giant(an adjective), you might consider adding giants(a noun) as an exclusion.
If the kind of entity type is KIND_MAP, then the phrases specified by entities and excluded phrases should be mutually exclusive.
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: 'value'
description: |
The word or phrase to be excluded.
- !ruby/object:Api::Type::Boolean
name: 'enableFuzzyExtraction'
description: |
Enables fuzzy entity extraction during classification.
- !ruby/object:Api::Type::Boolean
name: 'redact'
description: |
Indicates whether parameters of the entity type should be redacted in log. If redaction is enabled, page parameters and intent parameters referring to the entity type will be replaced by parameter name when logging.
21 changes: 21 additions & 0 deletions mmv1/products/dialogflowcx/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ overrides: !ruby/object:Overrides::ResourceOverrides
displayName: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.StringLenBetween(0, 64)'
EntityType: !ruby/object:Overrides::Terraform::ResourceOverride
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 40
update_minutes: 40
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/dialogflowcx_entity_type.go.erb
examples:
- !ruby/object:Provider::Terraform::Examples
name: "dialogflowcx_entity_type_full"
primary_resource_id: "basic_entity_type"
vars:
agent_name: "dialogflowcx-agent"
skip_sweeper: true
id_format: "{{parent}}/entityTypes/{{name}}"
import_format: ["{{parent}}/entityTypes/{{name}}"]
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
displayName: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.StringLenBetween(0, 64)'
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
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 and parent contains slashes
if err := parseImportId([]string{
"(?P<parent>.+)/entityTypes/(?P<name>[^/]+)",
"(?P<parent>.+)/(?P<name>[^/]+)",
}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "{{parent}}/entityTypes/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return []*schema.ResourceData{d}, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource "google_dialogflow_cx_agent" "agent" {
display_name = "<%= ctx[:vars]["agent_name"] %>"
location = "global"
default_language_code = "en"
supported_language_codes = ["fr","de","es"]
time_zone = "America/New_York"
description = "Example description."
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
enable_stackdriver_logging = true
enable_spell_correction = true
speech_to_text_settings {
enable_speech_adaptation = true
}
}


resource "google_dialogflow_cx_entity_type" "<%= ctx[:primary_resource_id] %>" {
parent = google_dialogflow_cx_agent.agent.id
display_name = "MyEntity"
kind = "KIND_MAP"
entities {
value = "value1"
synonyms = ["synonym1","synonym2"]
}
entities {
value = "value2"
synonyms = ["synonym3","synonym4"]
}
enable_fuzzy_extraction = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package google

import (
"testing"

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

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

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

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDialogflowCXEntityType_basic(context),
},
{
ResourceName: "google_dialogflow_cx_entity_type.my_entity",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDialogflowCXEntityType_full(context),
},
{
ResourceName: "google_dialogflow_cx_entity_type.my_entity",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccDialogflowCXEntityType_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_service_account" "dialogflowcx_service_account" {
account_id = "tf-test-dialogflow-%{random_suffix}"
}

resource "google_project_iam_member" "agent_create" {
role = "roles/dialogflow.admin"
member = "serviceAccount:${google_service_account.dialogflowcx_service_account.email}"
}

resource "google_dialogflow_cx_agent" "agent_entity" {
display_name = "tf-test-%{random_suffix}"
location = "global"
default_language_code = "en"
supported_language_codes = ["fr","de","es"]
time_zone = "America/New_York"
description = "Description 1."
avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo.png"
depends_on = [google_project_iam_member.agent_create]
}

resource "google_dialogflow_cx_entity_type" "my_entity" {
parent = google_dialogflow_cx_agent.agent_entity.id
display_name = "MyEntity"
kind = "KIND_MAP"
entities {
value = "value1"
synonyms = ["synonym1","synonym2"]
}
entities {
value = "value2"
synonyms = ["synonym3","synonym4"]
}
enable_fuzzy_extraction = false
}
`, context)
}

func testAccDialogflowCXEntityType_full(context map[string]interface{}) string {
return Nprintf(`
resource "google_service_account" "dialogflowcx_service_account" {
account_id = "tf-test-dialogflow-%{random_suffix}"
}

resource "google_project_iam_member" "agent_create" {
role = "roles/dialogflow.admin"
member = "serviceAccount:${google_service_account.dialogflowcx_service_account.email}"
}

resource "google_dialogflow_cx_agent" "agent_entity" {
display_name = "tf-test-%{random_suffix}"
location = "global"
default_language_code = "en"
supported_language_codes = ["fr","de","es"]
time_zone = "America/New_York"
description = "Description 1."
avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo.png"
depends_on = [google_project_iam_member.agent_create]
}

resource "google_dialogflow_cx_entity_type" "my_entity" {
parent = google_dialogflow_cx_agent.agent_entity.id
display_name = "MyEntity"
kind = "KIND_MAP"
entities {
value = "value1"
synonyms = ["synonym1","synonym2","synonym11","synonym22"]
}
entities {
value = "value2"
synonyms = ["synonym3","synonym4"]
}
enable_fuzzy_extraction = false
redact = true
auto_expansion_mode = "AUTO_EXPANSION_MODE_DEFAULT"
excluded_phrases {
value = "excluded1"
}

}
`, context)
}