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

Dialogflow EntityType Resource #3487

Merged
merged 1 commit into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
68 changes: 67 additions & 1 deletion products/dialogflow/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,70 @@ objects:
name: 'parentFollowupIntentName'
description: |
The unique identifier of the followup intent's parent.
Format: projects/<Project ID>/agent/intents/<Intent ID>.
Format: projects/<Project ID>/agent/intents/<Intent ID>.
- !ruby/object:Api::Resource
name: 'EntityType'
base_url: "projects/{{project}}/agent/entityTypes/"
self_link: "{{name}}"
update_verb: :PATCH
description: |
Represents an entity type. Entity types serve as a tool for extracting parameter values from natural language queries.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/dialogflow/docs/'
api: 'https://cloud.google.com/dialogflow/docs/reference/rest/v2/projects.agent.entityTypes'
properties:
- !ruby/object:Api::Type::String
name: 'name'
output: true
description: |
The unique identifier of the entity type.
Format: projects/<Project ID>/agent/entityTypes/<Entity type ID>.
- !ruby/object:Api::Type::String
name: 'displayName'
required: true
description: |
The name of this entity type to be displayed on the console.
- !ruby/object:Api::Type::Enum
name: 'kind'
required: true
description: |
Indicates the kind of entity type.
* KIND_MAP: Map entity types allow mapping of a group of synonyms to a reference value.
* KIND_LIST: List entity types contain a set of entries that do not map to reference 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::Boolean
name: 'enableFuzzyExtraction'
description: |
Enables fuzzy entity extraction during classification.
- !ruby/object:Api::Type::Array
name: 'entities'
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'
required: true
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 reference 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'
required: true
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.
15 changes: 15 additions & 0 deletions products/dialogflow/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/self_link_as_name_set_project.go.erb
post_create: 'templates/terraform/post_create/set_computed_name.erb'
EntityType: !ruby/object:Overrides::Terraform::ResourceOverride
examples:
- !ruby/object:Provider::Terraform::Examples
name: "dialogflow_entity_type_basic"
primary_resource_id: "basic_entity_type"
skip_test: true
vars:
intent_name: "basic-entity-type"
# Skip sweeper gen since this is a child resource.
skip_sweeper: true
id_format: "{{name}}"
import_format: ["{{name}}"]
custom_code: !ruby/object:Provider::Terraform::CustomCode
custom_import: templates/terraform/custom_import/self_link_as_name_set_project.go.erb
post_create: 'templates/terraform/post_create/set_computed_name.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
19 changes: 19 additions & 0 deletions templates/terraform/examples/dialogflow_entity_type_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "google_dialogflow_agent" "basic_agent" {
display_name = "example_agent"
default_language_code = "en"
time_zone = "America/New_York"
}

resource "google_dialogflow_entity_type" "<%= ctx[:primary_resource_id] %>" {
depends_on = [google_dialogflow_agent.basic_agent]
display_name = "<%= ctx[:vars]["entity_type_name"] %>"
kind = "KIND_MAP"
entities {
value = "value1"
synonyms = ["synonym1","synonym2"]
}
entities {
value = "value2"
synonyms = ["synonym3","synonym4"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<% autogen_exception -%>
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
func TestAccDialogflowEntityType_update(t *testing.T) {
t.Parallel()

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDialogflowEntityType_full1(context),
},
{
ResourceName: "google_dialogflow_entity_type.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDialogflowEntityType_full2(context),
},
{
ResourceName: "google_dialogflow_entity_type.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccDialogflowEntityType_full1(context map[string]interface{}) string {
return Nprintf(`
resource "google_project" "agent_project" {
name = "tf-test-dialogflow-%{random_suffix}"
project_id = "tf-test-dialogflow-%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}

resource "google_project_service" "agent_project" {
project = google_project.agent_project.project_id
service = "dialogflow.googleapis.com"
disable_dependent_services = false
}

resource "google_service_account" "dialogflow_service_account" {
account_id = "tf-test-dialogflow-%{random_suffix}"
}

resource "google_project_iam_member" "agent_create" {
project = google_project_service.agent_project.project
role = "roles/dialogflow.admin"
member = "serviceAccount:${google_service_account.dialogflow_service_account.email}"
}

resource "google_dialogflow_agent" "agent" {
project = google_project.agent_project.project_id
display_name = "tf-test-agent-%{random_suffix}"
default_language_code = "en"
time_zone = "America/New_York"
depends_on = [google_project_iam_member.agent_create]
}

resource "google_dialogflow_entity_type" "foobar" {
depends_on = [google_dialogflow_agent.agent]
project = google_project.agent_project.project_id
display_name = "tf-test-entity-%{random_suffix}"
kind = "KIND_MAP"
enable_fuzzy_extraction = true
entities {
value = "value1"
synonyms = ["synonym1","synonym2"]
}
entities {
value = "value2"
synonyms = ["synonym3","synonym4"]
}
}
`, context)
}

func testAccDialogflowEntityType_full2(context map[string]interface{}) string {
return Nprintf(`
resource "google_project" "agent_project" {
name = "tf-test-dialogflow-%{random_suffix}"
project_id = "tf-test-dialogflow-%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_account}"
}

resource "google_project_service" "agent_project" {
project = google_project.agent_project.project_id
service = "dialogflow.googleapis.com"
disable_dependent_services = false
}

resource "google_service_account" "dialogflow_service_account" {
account_id = "tf-test-dialogflow-%{random_suffix}"
}

resource "google_project_iam_member" "agent_create" {
project = google_project_service.agent_project.project
role = "roles/dialogflow.admin"
member = "serviceAccount:${google_service_account.dialogflow_service_account.email}"
}

resource "google_dialogflow_agent" "agent" {
project = google_project.agent_project.project_id
display_name = "tf-test-agent-%{random_suffix}"
default_language_code = "en"
time_zone = "America/New_York"
depends_on = [google_project_iam_member.agent_create]
}

resource "google_dialogflow_entity_type" "foobar" {
depends_on = [google_dialogflow_agent.agent]
project = google_project.agent_project.project_id
display_name = "tf-test-entity2-%{random_suffix}"
kind = "KIND_LIST"
enable_fuzzy_extraction = false
entities {
value = "value1"
synonyms = ["value1"]
}
}
`, context)
}