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_dialogflow_cx_intent #9537

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
3 changes: 3 additions & 0 deletions .changelog/4948.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_dialogflow_cx_intent`
```
2 changes: 1 addition & 1 deletion google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ var DefaultBasePaths = map[string]string{
DatastoreBasePathKey: "https://datastore.googleapis.com/v1/",
DeploymentManagerBasePathKey: "https://www.googleapis.com/deploymentmanager/v2/",
DialogflowBasePathKey: "https://dialogflow.googleapis.com/v2/",
DialogflowCXBasePathKey: "https://{{location}}-dialogflow.googleapis.com/v3/",
DialogflowCXBasePathKey: "https://dialogflow.googleapis.com/v3/",
DNSBasePathKey: "https://dns.googleapis.com/dns/v1/",
FilestoreBasePathKey: "https://file.googleapis.com/v1/",
FirestoreBasePathKey: "https://firestore.googleapis.com/v1/",
Expand Down
5 changes: 3 additions & 2 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 201
// Generated resources: 202
// Generated IAM resources: 90
// Total generated resources: 291
// Total generated resources: 292
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -946,6 +946,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_dialogflow_entity_type": resourceDialogflowEntityType(),
"google_dialogflow_fulfillment": resourceDialogflowFulfillment(),
"google_dialogflow_cx_agent": resourceDialogflowCXAgent(),
"google_dialogflow_cx_intent": resourceDialogflowCXIntent(),
"google_dns_managed_zone": resourceDNSManagedZone(),
"google_dns_policy": resourceDNSPolicy(),
"google_dns_record_set": resourceDNSResourceDnsRecordSet(),
Expand Down
807 changes: 807 additions & 0 deletions google/resource_dialogflow_cx_intent.go

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions google/resource_dialogflow_cx_intent_generated_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package google

import (
"fmt"
"strings"
"testing"

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

func TestAccDialogflowCXIntent_dialogflowcxIntentFullExample(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: testAccCheckDialogflowCXIntentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDialogflowCXIntent_dialogflowcxIntentFullExample(context),
},
{
ResourceName: "google_dialogflow_cx_intent.basic_intent",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"parent"},
},
},
})
}

func testAccDialogflowCXIntent_dialogflowcxIntentFullExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_dialogflow_cx_agent" "agent" {
display_name = "tf-test-dialogflowcx-agent%{random_suffix}"
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" "basic_intent" {
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"
}
}
`, context)
}

func testAccCheckDialogflowCXIntentDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_dialogflow_cx_intent" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := googleProviderConfig(t)

url, err := replaceVarsForTest(config, rs, "{{DialogflowCXBasePath}}{{parent}}/intents/{{name}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
if err == nil {
return fmt.Errorf("DialogflowCXIntent still exists at %s", url)
}
}

return nil
}
}
157 changes: 157 additions & 0 deletions google/resource_dialogflowcx_intent_test.go
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)
}
Loading