From fd828c093b2050bb9a927ce6774cf261a29d5306 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 3 Nov 2023 08:49:13 -0700 Subject: [PATCH] Enabling management of default Dialogflow resources without terraform import: `is_default_x` fields (#9336) (#589) * Enabling management of Default Start Flow + Default Welcome Intent + Default Negative Intent, without terraform import Fixes https://github.com/hashicorp/terraform-provider-google/issues/16308 * Basic tests for default flow + intents * Tests asserting resource IDs * Making Flow + Intent import respect is_default_X; fixing description on examples * Bah, making isFallback output-only might break users that'd imported the Default Negative Intent :( * Update mmv1/templates/terraform/pre_create/dialogflowcx_set_location_skip_default_obj.go.erb * Adding callout notes about multiple is_default_x resources * More words around the pre-create + pre-delete code * Adding more tests around Default Start Flow * Adding more tests around Default Welcome Intent and Default Negative Intent --------- [upstream:58d0735cfa46a3668a0c5af3181ce6443ab22d91] Signed-off-by: Modular Magician --- dialogflowcx_flow_basic/backing_file.tf | 15 ++++ dialogflowcx_flow_basic/main.tf | 62 +++++++++++++++ dialogflowcx_flow_basic/motd | 7 ++ dialogflowcx_flow_basic/tutorial.md | 79 +++++++++++++++++++ .../backing_file.tf | 15 ++++ dialogflowcx_flow_default_start_flow/main.tf | 76 ++++++++++++++++++ dialogflowcx_flow_default_start_flow/motd | 7 ++ .../tutorial.md | 79 +++++++++++++++++++ .../backing_file.tf | 15 ++++ .../main.tf | 21 +++++ .../motd | 7 ++ .../tutorial.md | 79 +++++++++++++++++++ .../backing_file.tf | 15 ++++ .../main.tf | 20 +++++ .../motd | 7 ++ .../tutorial.md | 79 +++++++++++++++++++ 16 files changed, 583 insertions(+) create mode 100644 dialogflowcx_flow_basic/backing_file.tf create mode 100644 dialogflowcx_flow_basic/main.tf create mode 100644 dialogflowcx_flow_basic/motd create mode 100644 dialogflowcx_flow_basic/tutorial.md create mode 100644 dialogflowcx_flow_default_start_flow/backing_file.tf create mode 100644 dialogflowcx_flow_default_start_flow/main.tf create mode 100644 dialogflowcx_flow_default_start_flow/motd create mode 100644 dialogflowcx_flow_default_start_flow/tutorial.md create mode 100644 dialogflowcx_intent_default_negative_intent/backing_file.tf create mode 100644 dialogflowcx_intent_default_negative_intent/main.tf create mode 100644 dialogflowcx_intent_default_negative_intent/motd create mode 100644 dialogflowcx_intent_default_negative_intent/tutorial.md create mode 100644 dialogflowcx_intent_default_welcome_intent/backing_file.tf create mode 100644 dialogflowcx_intent_default_welcome_intent/main.tf create mode 100644 dialogflowcx_intent_default_welcome_intent/motd create mode 100644 dialogflowcx_intent_default_welcome_intent/tutorial.md diff --git a/dialogflowcx_flow_basic/backing_file.tf b/dialogflowcx_flow_basic/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/dialogflowcx_flow_basic/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/dialogflowcx_flow_basic/main.tf b/dialogflowcx_flow_basic/main.tf new file mode 100644 index 00000000..91ae5607 --- /dev/null +++ b/dialogflowcx_flow_basic/main.tf @@ -0,0 +1,62 @@ +resource "google_dialogflow_cx_agent" "agent" { + display_name = "dialogflowcx-agent-${local.name_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?"] + } + } + } + } +} diff --git a/dialogflowcx_flow_basic/motd b/dialogflowcx_flow_basic/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/dialogflowcx_flow_basic/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/dialogflowcx_flow_basic/tutorial.md b/dialogflowcx_flow_basic/tutorial.md new file mode 100644 index 00000000..9c1c6d43 --- /dev/null +++ b/dialogflowcx_flow_basic/tutorial.md @@ -0,0 +1,79 @@ +# Dialogflowcx Flow Basic - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/dialogflowcx_flow_default_start_flow/backing_file.tf b/dialogflowcx_flow_default_start_flow/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/dialogflowcx_flow_default_start_flow/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/dialogflowcx_flow_default_start_flow/main.tf b/dialogflowcx_flow_default_start_flow/main.tf new file mode 100644 index 00000000..4280361e --- /dev/null +++ b/dialogflowcx_flow_default_start_flow/main.tf @@ -0,0 +1,76 @@ +resource "google_dialogflow_cx_agent" "agent" { + display_name = "dialogflowcx-agent-${local.name_suffix}" + location = "global" + default_language_code = "en" + time_zone = "America/New_York" +} + +resource "google_dialogflow_cx_intent" "default_welcome_intent" { + parent = google_dialogflow_cx_agent.agent.id + is_default_welcome_intent = true + display_name = "Default Welcome Intent" + priority = 1 + training_phrases { + parts { + text = "Hello" + } + repeat_count = 1 + } +} + + +resource "google_dialogflow_cx_flow" "default_start_flow" { + parent = google_dialogflow_cx_agent.agent.id + is_default_start_flow = true + display_name = "Default Start Flow" + description = "A start flow created along with the agent" + + nlu_settings { + classification_threshold = 0.3 + model_type = "MODEL_TYPE_STANDARD" + } + + transition_routes { + intent = google_dialogflow_cx_intent.default_welcome_intent.id + trigger_fulfillment { + messages { + text { + text = ["Response to default welcome intent."] + } + } + } + } + + event_handlers { + event = "custom-event" + trigger_fulfillment { + messages { + text { + text = ["This is a default flow."] + } + } + } + } + + event_handlers { + event = "sys.no-match-default" + trigger_fulfillment { + messages { + text { + text = ["We've updated the default flow no-match response!"] + } + } + } + } + + event_handlers { + event = "sys.no-input-default" + trigger_fulfillment { + messages { + text { + text = ["We've updated the default flow no-input response!"] + } + } + } + } +} diff --git a/dialogflowcx_flow_default_start_flow/motd b/dialogflowcx_flow_default_start_flow/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/dialogflowcx_flow_default_start_flow/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/dialogflowcx_flow_default_start_flow/tutorial.md b/dialogflowcx_flow_default_start_flow/tutorial.md new file mode 100644 index 00000000..cbf533ca --- /dev/null +++ b/dialogflowcx_flow_default_start_flow/tutorial.md @@ -0,0 +1,79 @@ +# Dialogflowcx Flow Default Start Flow - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/dialogflowcx_intent_default_negative_intent/backing_file.tf b/dialogflowcx_intent_default_negative_intent/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/dialogflowcx_intent_default_negative_intent/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/dialogflowcx_intent_default_negative_intent/main.tf b/dialogflowcx_intent_default_negative_intent/main.tf new file mode 100644 index 00000000..b35c6d15 --- /dev/null +++ b/dialogflowcx_intent_default_negative_intent/main.tf @@ -0,0 +1,21 @@ +resource "google_dialogflow_cx_agent" "agent" { + display_name = "dialogflowcx-agent-${local.name_suffix}" + location = "global" + default_language_code = "en" + time_zone = "America/New_York" +} + + +resource "google_dialogflow_cx_intent" "default_negative_intent" { + parent = google_dialogflow_cx_agent.agent.id + is_default_negative_intent = true + display_name = "Default Negative Intent" + priority = 1 + is_fallback = true + training_phrases { + parts { + text = "Never match this phrase" + } + repeat_count = 1 + } +} diff --git a/dialogflowcx_intent_default_negative_intent/motd b/dialogflowcx_intent_default_negative_intent/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/dialogflowcx_intent_default_negative_intent/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/dialogflowcx_intent_default_negative_intent/tutorial.md b/dialogflowcx_intent_default_negative_intent/tutorial.md new file mode 100644 index 00000000..589b174d --- /dev/null +++ b/dialogflowcx_intent_default_negative_intent/tutorial.md @@ -0,0 +1,79 @@ +# Dialogflowcx Intent Default Negative Intent - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +``` diff --git a/dialogflowcx_intent_default_welcome_intent/backing_file.tf b/dialogflowcx_intent_default_welcome_intent/backing_file.tf new file mode 100644 index 00000000..c60b1199 --- /dev/null +++ b/dialogflowcx_intent_default_welcome_intent/backing_file.tf @@ -0,0 +1,15 @@ +# This file has some scaffolding to make sure that names are unique and that +# a region and zone are selected when you try to create your Terraform resources. + +locals { + name_suffix = "${random_pet.suffix.id}" +} + +resource "random_pet" "suffix" { + length = 2 +} + +provider "google" { + region = "us-central1" + zone = "us-central1-c" +} diff --git a/dialogflowcx_intent_default_welcome_intent/main.tf b/dialogflowcx_intent_default_welcome_intent/main.tf new file mode 100644 index 00000000..aacb2d6d --- /dev/null +++ b/dialogflowcx_intent_default_welcome_intent/main.tf @@ -0,0 +1,20 @@ +resource "google_dialogflow_cx_agent" "agent" { + display_name = "dialogflowcx-agent-${local.name_suffix}" + location = "global" + default_language_code = "en" + time_zone = "America/New_York" +} + + +resource "google_dialogflow_cx_intent" "default_welcome_intent" { + parent = google_dialogflow_cx_agent.agent.id + is_default_welcome_intent = true + display_name = "Default Welcome Intent" + priority = 1 + training_phrases { + parts { + text = "Hello" + } + repeat_count = 1 + } +} diff --git a/dialogflowcx_intent_default_welcome_intent/motd b/dialogflowcx_intent_default_welcome_intent/motd new file mode 100644 index 00000000..45a906e8 --- /dev/null +++ b/dialogflowcx_intent_default_welcome_intent/motd @@ -0,0 +1,7 @@ +=== + +These examples use real resources that will be billed to the +Google Cloud Platform project you use - so make sure that you +run "terraform destroy" before quitting! + +=== diff --git a/dialogflowcx_intent_default_welcome_intent/tutorial.md b/dialogflowcx_intent_default_welcome_intent/tutorial.md new file mode 100644 index 00000000..60f9b103 --- /dev/null +++ b/dialogflowcx_intent_default_welcome_intent/tutorial.md @@ -0,0 +1,79 @@ +# Dialogflowcx Intent Default Welcome Intent - Terraform + +## Setup + + + +Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform. + + + +Terraform provisions real GCP resources, so anything you create in this session will be billed against this project. + +## Terraforming! + +Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command +to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up +the project name from the environment variable. + +```bash +export GOOGLE_CLOUD_PROJECT={{project-id}} +``` + +After that, let's get Terraform started. Run the following to pull in the providers. + +```bash +terraform init +``` + +With the providers downloaded and a project set, you're ready to use Terraform. Go ahead! + +```bash +terraform apply +``` + +Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan. + +```bash +yes +``` + + +## Post-Apply + +### Editing your config + +Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed. + +```bash +terraform plan +``` + +So let's make a change! Try editing a number, or appending a value to the name in the editor. Then, +run a 'plan' again. + +```bash +terraform plan +``` + +Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes +at the 'yes' prompt. + +```bash +terraform apply +``` + +```bash +yes +``` + +## Cleanup + +Run the following to remove the resources Terraform provisioned: + +```bash +terraform destroy +``` +```bash +yes +```