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_dialogflow_cx_intent
(GoogleCloudPlatform#4948)
- Loading branch information
1 parent
bd3b67f
commit 92f74bc
Showing
5 changed files
with
370 additions
and
1 deletion.
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_intent.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>.+)/intents/(?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}}/intents/{{name}}") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil |
47 changes: 47 additions & 0 deletions
47
mmv1/templates/terraform/examples/dialogflowcx_intent_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,47 @@ | ||
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_intent" "<%= ctx[:primary_resource_id] %>" { | ||
parent = google_dialogflow_cx_agent.agent.id | ||
display_name = "Example" | ||
priority = 1 | ||
description = "Intent example" | ||
training_phrases { | ||
parts { | ||
text = "training" | ||
} | ||
|
||
parts { | ||
text = "phrase" | ||
} | ||
|
||
parts { | ||
text = "example" | ||
} | ||
|
||
repeat_count = 1 | ||
} | ||
|
||
parameters { | ||
id = "param1" | ||
entity_type = "projects/-/locations/-/agents/-/entityTypes/sys.date" | ||
} | ||
|
||
labels = { | ||
label1 = "value1", | ||
label2 = "value2" | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
mmv1/third_party/terraform/tests/resource_dialogflowcx_intent_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,157 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDialogflowCXIntent_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: testAccDialogflowCXIntent_basic(context), | ||
}, | ||
{ | ||
ResourceName: "google_dialogflow_cx_intent.my_intent", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccDialogflowCXIntent_full(context), | ||
}, | ||
{ | ||
ResourceName: "google_dialogflow_cx_intent.my_intent", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDialogflowCXIntent_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_intent" { | ||
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_intent" "my_intent" { | ||
parent = google_dialogflow_cx_agent.agent_intent.id | ||
display_name = "Example" | ||
priority = 1 | ||
description = "Intent example" | ||
training_phrases { | ||
parts { | ||
text = "training" | ||
} | ||
parts { | ||
text = "phrase" | ||
} | ||
parts { | ||
text = "example" | ||
} | ||
repeat_count = 1 | ||
} | ||
parameters { | ||
id = "param1" | ||
entity_type = "projects/-/locations/-/agents/-/entityTypes/sys.date" | ||
} | ||
labels = { | ||
label1 = "value1", | ||
label2 = "value2" | ||
} | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccDialogflowCXIntent_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_intent" { | ||
display_name = "tf-test-%{random_suffix}update" | ||
location = "global" | ||
default_language_code = "en" | ||
supported_language_codes = ["no"] | ||
time_zone = "Europe/London" | ||
description = "Description 2!" | ||
avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo-2.png" | ||
enable_stackdriver_logging = true | ||
enable_spell_correction = true | ||
speech_to_text_settings { | ||
enable_speech_adaptation = true | ||
} | ||
depends_on = [google_project_iam_member.agent_create] | ||
} | ||
resource "google_dialogflow_cx_intent" "my_intent" { | ||
parent = google_dialogflow_cx_agent.agent_intent.id | ||
display_name = "Example" | ||
priority = 1 | ||
description = "Intent example" | ||
training_phrases { | ||
parts { | ||
text = "training" | ||
} | ||
parts { | ||
text = "phrase" | ||
} | ||
parts { | ||
text = "example" | ||
} | ||
repeat_count = 1 | ||
} | ||
parameters { | ||
id = "param1" | ||
entity_type = "projects/-/locations/-/agents/-/entityTypes/sys.date" | ||
} | ||
labels = { | ||
label1 = "value1", | ||
label2 = "value2" | ||
} | ||
} | ||
`, context) | ||
} |