forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource :
google_dialogflowcx_entity_type
(GoogleCloudPlatform…
…#4924) * Including API definition for EntityType * Including acc tests for EntityTypes * Adding example for Dialogflow entity type * Refactoring with suggestions made in PR for versions * Updated Entity Type tests * Fix space in tests
- Loading branch information
1 parent
425e095
commit 476ac81
Showing
5 changed files
with
295 additions
and
0 deletions.
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
18 changes: 18 additions & 0 deletions
18
mmv1/templates/terraform/custom_import/dialogflowcx_entity_type.go.erb
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,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 |
30 changes: 30 additions & 0 deletions
30
mmv1/templates/terraform/examples/dialogflowcx_entity_type_full.tf.erb
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,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 | ||
} |
124 changes: 124 additions & 0 deletions
124
mmv1/third_party/terraform/tests/resource_dialogflowcx_entity_type_test.go
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,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) | ||
} |