Skip to content

Commit

Permalink
New Resource : google_dialogflow_cx_page (#4971) (#9683)
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
modular-magician and melinath authored Jul 30, 2021
1 parent 15b137d commit d0e438b
Show file tree
Hide file tree
Showing 7 changed files with 2,667 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/4971.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_dialogflow_cx_page`
```
5 changes: 3 additions & 2 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 209
// Generated resources: 210
// Generated IAM resources: 90
// Total generated resources: 299
// Total generated resources: 300
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -965,6 +965,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_dialogflow_cx_intent": resourceDialogflowCXIntent(),
"google_dialogflow_cx_flow": resourceDialogflowCXFlow(),
"google_dialogflow_cx_version": resourceDialogflowCXVersion(),
"google_dialogflow_cx_page": resourceDialogflowCXPage(),
"google_dns_managed_zone": resourceDNSManagedZone(),
"google_dns_policy": resourceDNSPolicy(),
"google_dns_record_set": resourceDNSResourceDnsRecordSet(),
Expand Down
1,906 changes: 1,906 additions & 0 deletions google/resource_dialogflow_cx_page.go

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions google/resource_dialogflow_cx_page_generated_test.go
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
}
}
146 changes: 146 additions & 0 deletions google/resource_dialogflowcx_page_test.go
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)
}
Loading

0 comments on commit d0e438b

Please sign in to comment.