Skip to content

Commit fd828c0

Browse files
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 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 <magic-modules@google.com>
1 parent 66efbbe commit fd828c0

File tree

16 files changed

+583
-0
lines changed

16 files changed

+583
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}

dialogflowcx_flow_basic/main.tf

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
resource "google_dialogflow_cx_agent" "agent" {
2+
display_name = "dialogflowcx-agent-${local.name_suffix}"
3+
location = "global"
4+
default_language_code = "en"
5+
supported_language_codes = ["fr", "de", "es"]
6+
time_zone = "America/New_York"
7+
description = "Example description."
8+
avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png"
9+
enable_stackdriver_logging = true
10+
enable_spell_correction = true
11+
speech_to_text_settings {
12+
enable_speech_adaptation = true
13+
}
14+
}
15+
16+
17+
resource "google_dialogflow_cx_flow" "basic_flow" {
18+
parent = google_dialogflow_cx_agent.agent.id
19+
display_name = "MyFlow"
20+
description = "Test Flow"
21+
22+
nlu_settings {
23+
classification_threshold = 0.3
24+
model_type = "MODEL_TYPE_STANDARD"
25+
}
26+
27+
event_handlers {
28+
event = "custom-event"
29+
trigger_fulfillment {
30+
return_partial_responses = false
31+
messages {
32+
text {
33+
text = ["I didn't get that. Can you say it again?"]
34+
}
35+
}
36+
}
37+
}
38+
39+
event_handlers {
40+
event = "sys.no-match-default"
41+
trigger_fulfillment {
42+
return_partial_responses = false
43+
messages {
44+
text {
45+
text = ["Sorry, could you say that again?"]
46+
}
47+
}
48+
}
49+
}
50+
51+
event_handlers {
52+
event = "sys.no-input-default"
53+
trigger_fulfillment {
54+
return_partial_responses = false
55+
messages {
56+
text {
57+
text = ["One more time?"]
58+
}
59+
}
60+
}
61+
}
62+
}

dialogflowcx_flow_basic/motd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Dialogflowcx Flow Basic - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="dialogflowcx_flow_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
resource "google_dialogflow_cx_agent" "agent" {
2+
display_name = "dialogflowcx-agent-${local.name_suffix}"
3+
location = "global"
4+
default_language_code = "en"
5+
time_zone = "America/New_York"
6+
}
7+
8+
resource "google_dialogflow_cx_intent" "default_welcome_intent" {
9+
parent = google_dialogflow_cx_agent.agent.id
10+
is_default_welcome_intent = true
11+
display_name = "Default Welcome Intent"
12+
priority = 1
13+
training_phrases {
14+
parts {
15+
text = "Hello"
16+
}
17+
repeat_count = 1
18+
}
19+
}
20+
21+
22+
resource "google_dialogflow_cx_flow" "default_start_flow" {
23+
parent = google_dialogflow_cx_agent.agent.id
24+
is_default_start_flow = true
25+
display_name = "Default Start Flow"
26+
description = "A start flow created along with the agent"
27+
28+
nlu_settings {
29+
classification_threshold = 0.3
30+
model_type = "MODEL_TYPE_STANDARD"
31+
}
32+
33+
transition_routes {
34+
intent = google_dialogflow_cx_intent.default_welcome_intent.id
35+
trigger_fulfillment {
36+
messages {
37+
text {
38+
text = ["Response to default welcome intent."]
39+
}
40+
}
41+
}
42+
}
43+
44+
event_handlers {
45+
event = "custom-event"
46+
trigger_fulfillment {
47+
messages {
48+
text {
49+
text = ["This is a default flow."]
50+
}
51+
}
52+
}
53+
}
54+
55+
event_handlers {
56+
event = "sys.no-match-default"
57+
trigger_fulfillment {
58+
messages {
59+
text {
60+
text = ["We've updated the default flow no-match response!"]
61+
}
62+
}
63+
}
64+
}
65+
66+
event_handlers {
67+
event = "sys.no-input-default"
68+
trigger_fulfillment {
69+
messages {
70+
text {
71+
text = ["We've updated the default flow no-input response!"]
72+
}
73+
}
74+
}
75+
}
76+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Dialogflowcx Flow Default Start Flow - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="dialogflowcx_flow_default_start_flow" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "google_dialogflow_cx_agent" "agent" {
2+
display_name = "dialogflowcx-agent-${local.name_suffix}"
3+
location = "global"
4+
default_language_code = "en"
5+
time_zone = "America/New_York"
6+
}
7+
8+
9+
resource "google_dialogflow_cx_intent" "default_negative_intent" {
10+
parent = google_dialogflow_cx_agent.agent.id
11+
is_default_negative_intent = true
12+
display_name = "Default Negative Intent"
13+
priority = 1
14+
is_fallback = true
15+
training_phrases {
16+
parts {
17+
text = "Never match this phrase"
18+
}
19+
repeat_count = 1
20+
}
21+
}

0 commit comments

Comments
 (0)