-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Include definition for DialogflowCX Page resource * Apply suggestions from code review Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com> * Fixed Dialogflow Pages example Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com> Signed-off-by: Modular Magician <magic-modules@google.com> Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>
- Loading branch information
1 parent
15b137d
commit d0e438b
Showing
7 changed files
with
2,667 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
`google_dialogflow_cx_page` | ||
``` |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,150 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** Type: MMv1 *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// 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 TestAccDialogflowCXPage_dialogflowcxPageFullExample(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: testAccCheckDialogflowCXPageDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDialogflowCXPage_dialogflowcxPageFullExample(context), | ||
}, | ||
{ | ||
ResourceName: "google_dialogflow_cx_page.basic_page", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"parent"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDialogflowCXPage_dialogflowcxPageFullExample(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_page" "basic_page" { | ||
parent = google_dialogflow_cx_agent.agent.start_flow | ||
display_name = "MyPage" | ||
entry_fulfillment { | ||
messages { | ||
text { | ||
text = ["Welcome to page"] | ||
} | ||
} | ||
} | ||
form { | ||
parameters { | ||
display_name = "param1" | ||
entity_type = "projects/-/locations/-/agents/-/entityTypes/sys.date" | ||
fill_behavior { | ||
initial_prompt_fulfillment { | ||
messages { | ||
text { | ||
text = ["Please provide param1"] | ||
} | ||
} | ||
} | ||
} | ||
required = "true" | ||
redact = "true" | ||
} | ||
} | ||
transition_routes { | ||
condition = "$page.params.status = 'FINAL'" | ||
trigger_fulfillment { | ||
messages { | ||
text { | ||
text = ["information completed, navigating to page 2"] | ||
} | ||
} | ||
} | ||
target_page = google_dialogflow_cx_page.my_page2.id | ||
} | ||
} | ||
resource "google_dialogflow_cx_page" "my_page2" { | ||
parent = google_dialogflow_cx_agent.agent.start_flow | ||
display_name = "MyPage2" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccCheckDialogflowCXPageDestroyProducer(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_page" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := googleProviderConfig(t) | ||
|
||
url, err := replaceVarsForTest(config, rs, "{{DialogflowCXBasePath}}{{parent}}/pages/{{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("DialogflowCXPage still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
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,146 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDialogflowCXPage_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: testAccDialogflowCXPage_basic(context), | ||
}, | ||
{ | ||
ResourceName: "google_dialogflow_cx_page.my_page", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccDialogflowCXPage_full(context), | ||
}, | ||
{ | ||
ResourceName: "google_dialogflow_cx_page.my_page", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDialogflowCXPage_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_page" { | ||
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_page" "my_page" { | ||
parent = google_dialogflow_cx_agent.agent_page.start_flow | ||
display_name = "MyPage" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccDialogflowCXPage_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_page" { | ||
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_page" "my_page" { | ||
parent = google_dialogflow_cx_agent.agent_page.start_flow | ||
display_name = "MyPage" | ||
entry_fulfillment { | ||
messages { | ||
text { | ||
text = ["Welcome to page"] | ||
} | ||
} | ||
} | ||
form { | ||
parameters { | ||
display_name = "param1" | ||
entity_type = "projects/-/locations/-/agents/-/entityTypes/sys.date" | ||
fill_behavior { | ||
initial_prompt_fulfillment { | ||
messages { | ||
text { | ||
text = ["Please provide param1"] | ||
} | ||
} | ||
} | ||
} | ||
required = "true" | ||
redact = "true" | ||
} | ||
} | ||
transition_routes { | ||
condition = "$page.params.status = 'FINAL'" | ||
trigger_fulfillment { | ||
messages { | ||
text { | ||
text = ["information completed, navigating to page 2"] | ||
} | ||
} | ||
} | ||
target_page = google_dialogflow_cx_page.my_page2.id | ||
} | ||
} | ||
resource "google_dialogflow_cx_page" "my_page2" { | ||
parent = google_dialogflow_cx_agent.agent_page.start_flow | ||
display_name = "MyPage2" | ||
} | ||
`, context) | ||
} |
Oops, something went wrong.