Skip to content

Commit

Permalink
New Resource : google_dialogflow_cx_flow (#4963) (#3422)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jul 12, 2021
1 parent cbe48c1 commit 4f1a7d1
Show file tree
Hide file tree
Showing 7 changed files with 1,965 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/4963.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_dialogflow_cx_flow`
```
5 changes: 3 additions & 2 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 236
// Generated resources: 237
// Generated IAM resources: 117
// Total generated resources: 353
// Total generated resources: 354
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1095,6 +1095,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_dialogflow_fulfillment": resourceDialogflowFulfillment(),
"google_dialogflow_cx_agent": resourceDialogflowCXAgent(),
"google_dialogflow_cx_intent": resourceDialogflowCXIntent(),
"google_dialogflow_cx_flow": resourceDialogflowCXFlow(),
"google_dns_managed_zone": resourceDNSManagedZone(),
"google_dns_policy": resourceDNSPolicy(),
"google_dns_record_set": resourceDNSResourceDnsRecordSet(),
Expand Down
1,307 changes: 1,307 additions & 0 deletions google-beta/resource_dialogflow_cx_flow.go

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions google-beta/resource_dialogflow_cx_flow_generated_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// ----------------------------------------------------------------------------
//
// *** 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 TestAccDialogflowCXFlow_dialogflowcxFlowFullExample(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: testAccCheckDialogflowCXFlowDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDialogflowCXFlow_dialogflowcxFlowFullExample(context),
},
{
ResourceName: "google_dialogflow_cx_flow.basic_flow",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"parent"},
},
},
})
}

func testAccDialogflowCXFlow_dialogflowcxFlowFullExample(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_flow" "basic_flow" {
parent = google_dialogflow_cx_agent.agent.id
display_name = "MyFlow"
description = "Test Flow"
nlu_settings {
classification_threshold = 0.3
model_type = "MODEL_TYPE_STANDARD"
}
event_handlers {
event = "custom-event"
trigger_fulfillment {
return_partial_responses = false
messages {
text {
text = ["I didn't get that. Can you say it again?"]
}
}
}
}
event_handlers {
event = "sys.no-match-default"
trigger_fulfillment {
return_partial_responses = false
messages {
text {
text = ["Sorry, could you say that again?"]
}
}
}
}
event_handlers {
event = "sys.no-input-default"
trigger_fulfillment {
return_partial_responses = false
messages {
text {
text = ["One more time?"]
}
}
}
}
}
`, context)
}

func testAccCheckDialogflowCXFlowDestroyProducer(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_flow" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := googleProviderConfig(t)

url, err := replaceVarsForTest(config, rs, "{{DialogflowCXBasePath}}{{parent}}/flows/{{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("DialogflowCXFlow still exists at %s", url)
}
}

return nil
}
}
149 changes: 149 additions & 0 deletions google-beta/resource_dialogflowcx_flow_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package google

import (
"testing"

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

func TestAccDialogflowCXFlow_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: testAccDialogflowCXFlow_basic(context),
},
{
ResourceName: "google_dialogflow_cx_flow.my_flow",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDialogflowCXFlow_full(context),
},
{
ResourceName: "google_dialogflow_cx_flow.my_flow",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccDialogflowCXFlow_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_flow" "my_flow" {
parent = google_dialogflow_cx_agent.agent_entity.id
display_name = "MyFlow"
nlu_settings {
classification_threshold = 0.3
model_type = "MODEL_TYPE_STANDARD"
}
}
`, context)
}

func testAccDialogflowCXFlow_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}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_flow" "my_flow" {
parent = google_dialogflow_cx_agent.agent_entity.id
display_name = "MyFlow"
nlu_settings {
classification_threshold = 0.3
model_type = "MODEL_TYPE_STANDARD"
}
event_handlers {
event = "custom-event"
trigger_fulfillment {
return_partial_responses = false
messages {
text {
text = ["I didn't get that. Can you say it again?"]
}
}
}
}
event_handlers {
event = "sys.no-match-default"
trigger_fulfillment {
return_partial_responses = false
messages {
text {
text = ["Sorry, could you say that again?"]
}
}
}
}
event_handlers {
event = "sys.no-input-default"
trigger_fulfillment {
return_partial_responses = false
messages {
text {
text = ["One more time?"]
}
}
}
}
}
`, context)
}
Loading

0 comments on commit 4f1a7d1

Please sign in to comment.