Skip to content

Commit

Permalink
Enabling management of default Dialogflow resources without terraform…
Browse files Browse the repository at this point in the history
… import: `is_default_x` fields (#9336) (#589)

* Enabling management of Default Start Flow + Default Welcome Intent + Default Negative Intent, without terraform import

Fixes hashicorp/terraform-provider-google#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 <[email protected]>
  • Loading branch information
modular-magician authored Nov 3, 2023
1 parent 66efbbe commit fd828c0
Show file tree
Hide file tree
Showing 16 changed files with 583 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dialogflowcx_flow_basic/backing_file.tf
Original file line number Diff line number Diff line change
@@ -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"
}
62 changes: 62 additions & 0 deletions dialogflowcx_flow_basic/main.tf
Original file line number Diff line number Diff line change
@@ -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?"]
}
}
}
}
}
7 changes: 7 additions & 0 deletions dialogflowcx_flow_basic/motd
Original file line number Diff line number Diff line change
@@ -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!

===
79 changes: 79 additions & 0 deletions dialogflowcx_flow_basic/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Dialogflowcx Flow Basic - Terraform

## Setup

<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="dialogflowcx_flow_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>

Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.

<walkthrough-project-billing-setup></walkthrough-project-billing-setup>

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
```
15 changes: 15 additions & 0 deletions dialogflowcx_flow_default_start_flow/backing_file.tf
Original file line number Diff line number Diff line change
@@ -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"
}
76 changes: 76 additions & 0 deletions dialogflowcx_flow_default_start_flow/main.tf
Original file line number Diff line number Diff line change
@@ -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!"]
}
}
}
}
}
7 changes: 7 additions & 0 deletions dialogflowcx_flow_default_start_flow/motd
Original file line number Diff line number Diff line change
@@ -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!

===
79 changes: 79 additions & 0 deletions dialogflowcx_flow_default_start_flow/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Dialogflowcx Flow Default Start Flow - Terraform

## Setup

<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="dialogflowcx_flow_default_start_flow" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>

Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.

<walkthrough-project-billing-setup></walkthrough-project-billing-setup>

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
```
15 changes: 15 additions & 0 deletions dialogflowcx_intent_default_negative_intent/backing_file.tf
Original file line number Diff line number Diff line change
@@ -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"
}
21 changes: 21 additions & 0 deletions dialogflowcx_intent_default_negative_intent/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions dialogflowcx_intent_default_negative_intent/motd
Original file line number Diff line number Diff line change
@@ -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!

===
Loading

0 comments on commit fd828c0

Please sign in to comment.