Skip to content

Commit 539e291

Browse files
shang-jasonSirGitsalot
authored andcommitted
Adding ToolVersion to Dialogflow CX (#15945)
1 parent ae04b51 commit 539e291

File tree

6 files changed

+878
-0
lines changed

6 files changed

+878
-0
lines changed

mmv1/products/dialogflowcx/ToolVersion.yaml

Lines changed: 450 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
config := meta.(*transport_tpg.Config)
2+
3+
// current import_formats can't import fields with forward slashes in their value and parent contains slashes
4+
if err := tpgresource.ParseImportId([]string{
5+
"(?P<parent>.+)/versions/(?P<name>[^/]+)",
6+
"(?P<parent>.+)/(?P<name>[^/]+)",
7+
}, d, config); err != nil {
8+
return nil, err
9+
}
10+
11+
// Replace import id for the resource id
12+
id, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}parent{{"}}"}}/versions/{{"{{"}}name{{"}}"}}")
13+
if err != nil {
14+
return nil, fmt.Errorf("Error constructing id: %s", err)
15+
}
16+
d.SetId(id)
17+
18+
return []*schema.ResourceData{d}, nil
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
resource "google_dialogflow_cx_agent" "agent" {
2+
provider = google-beta
3+
display_name = "{{index $.Vars "agent_name"}}"
4+
location = "us-central1"
5+
default_language_code = "en"
6+
time_zone = "America/New_York"
7+
description = "Example description."
8+
delete_chat_engine_on_destroy = true
9+
}
10+
11+
resource "google_integration_connectors_connection" "integration_connector" {
12+
provider = google-beta
13+
name = "{{index $.Vars "connection_name"}}"
14+
location = "us-central1"
15+
connector_version = "projects/${google_dialogflow_cx_agent.agent.project}/locations/global/providers/gcp/connectors/bigquery/versions/1"
16+
description = "tf created description"
17+
config_variable {
18+
key = "dataset_id"
19+
string_value = google_bigquery_dataset.bq_dataset.dataset_id
20+
}
21+
config_variable {
22+
key = "project_id"
23+
string_value = google_dialogflow_cx_agent.agent.project
24+
}
25+
config_variable {
26+
key = "support_native_data_type"
27+
boolean_value = false
28+
}
29+
config_variable {
30+
key = "proxy_enabled"
31+
boolean_value = false
32+
}
33+
34+
service_account = "${data.google_project.test_project.number}-compute@developer.gserviceaccount.com"
35+
36+
auth_config {
37+
auth_type = "AUTH_TYPE_UNSPECIFIED"
38+
}
39+
lifecycle {
40+
ignore_changes = [
41+
auth_config,
42+
]
43+
}
44+
}
45+
46+
resource "google_bigquery_dataset" "bq_dataset" {
47+
provider = google-beta
48+
dataset_id = "{{index $.Vars "dataset_id"}}"
49+
friendly_name = "test"
50+
description = "This is a test description"
51+
location = "us-central1"
52+
delete_contents_on_destroy = true
53+
}
54+
55+
resource "google_bigquery_table" "bq_table" {
56+
provider = google-beta
57+
deletion_protection = false
58+
dataset_id = google_bigquery_dataset.bq_dataset.dataset_id
59+
table_id = "{{index $.Vars "table_id"}}"
60+
}
61+
62+
63+
resource "google_bigquery_dataset_iam_member" "connector_sa_dataset_perms" {
64+
provider = google-beta
65+
project = data.google_project.test_project.project_id
66+
dataset_id = google_bigquery_dataset.bq_dataset.dataset_id
67+
role = "roles/bigquery.dataEditor"
68+
member = "serviceAccount:${data.google_project.test_project.number}-compute@developer.gserviceaccount.com"
69+
}
70+
71+
resource "google_dialogflow_cx_tool" "tool" {
72+
provider = google-beta
73+
parent = google_dialogflow_cx_agent.agent.id
74+
display_name = "{{index $.Vars "tool_name"}}"
75+
description = "Example Description"
76+
77+
connector_spec {
78+
name = "projects/${google_dialogflow_cx_agent.agent.project}/locations/us-central1/connections/${google_integration_connectors_connection.integration_connector.name}"
79+
actions {
80+
connection_action_id = "ExecuteCustomQuery"
81+
input_fields = ["test1"]
82+
output_fields = ["test1"]
83+
}
84+
actions {
85+
entity_operation {
86+
entity_id = google_bigquery_table.bq_table.table_id
87+
operation = "LIST"
88+
}
89+
}
90+
}
91+
}
92+
93+
resource "google_dialogflow_cx_tool_version" "{{$.PrimaryResourceId}}" {
94+
parent = google_dialogflow_cx_tool.tool.id
95+
provider = google-beta
96+
display_name = "Example Connector Tool Version"
97+
tool {
98+
display_name = "{{index $.Vars "tool_name"}}"
99+
description = "Example Description"
100+
101+
connector_spec {
102+
name = "projects/${google_dialogflow_cx_agent.agent.project}/locations/us-central1/connections/${google_integration_connectors_connection.integration_connector.name}"
103+
actions {
104+
connection_action_id = "ExecuteCustomQuery"
105+
input_fields = ["test1"]
106+
output_fields = ["test1"]
107+
}
108+
actions {
109+
entity_operation {
110+
entity_id = google_bigquery_table.bq_table.table_id
111+
operation = "LIST"
112+
}
113+
}
114+
}
115+
}
116+
}
117+
118+
data "google_project" "test_project" {
119+
provider = google-beta
120+
}
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 = "{{index $.Vars "agent_name"}}"
3+
location = "global"
4+
default_language_code = "en"
5+
time_zone = "America/New_York"
6+
description = "Example description."
7+
delete_chat_engine_on_destroy = true
8+
depends_on = [
9+
google_discovery_engine_data_store.my_datastore
10+
]
11+
}
12+
13+
resource "google_dialogflow_cx_tool" "tool" {
14+
parent = google_dialogflow_cx_agent.agent.id
15+
display_name = "{{index $.Vars "tool_name"}}"
16+
description = "Example Description"
17+
data_store_spec {
18+
data_store_connections {
19+
data_store_type = "UNSTRUCTURED"
20+
data_store = "projects/${data.google_project.project.number}/locations/global/collections/default_collection/dataStores/${google_discovery_engine_data_store.my_datastore.data_store_id}"
21+
document_processing_mode = "DOCUMENTS"
22+
}
23+
fallback_prompt {}
24+
}
25+
depends_on = [
26+
google_discovery_engine_data_store.my_datastore,
27+
google_dialogflow_cx_agent.agent
28+
]
29+
}
30+
31+
resource "google_discovery_engine_data_store" "my_datastore" {
32+
location = "global"
33+
data_store_id = "{{index $.Vars "data_store"}}"
34+
display_name = "datastore for Tool test"
35+
industry_vertical = "GENERIC"
36+
content_config = "NO_CONTENT"
37+
solution_types = ["SOLUTION_TYPE_CHAT"]
38+
}
39+
40+
resource "google_dialogflow_cx_tool_version" "{{$.PrimaryResourceId}}" {
41+
parent = google_dialogflow_cx_tool.tool.id
42+
display_name = "Example Data Store Tool Version"
43+
tool {
44+
display_name = "{{index $.Vars "tool_name"}}"
45+
description = "Example Description"
46+
data_store_spec {
47+
data_store_connections {
48+
data_store_type = "UNSTRUCTURED"
49+
data_store = "projects/${data.google_project.project.number}/locations/global/collections/default_collection/dataStores/${google_discovery_engine_data_store.my_datastore.data_store_id}"
50+
document_processing_mode = "DOCUMENTS"
51+
}
52+
fallback_prompt {}
53+
}
54+
}
55+
depends_on = [
56+
google_discovery_engine_data_store.my_datastore,
57+
google_dialogflow_cx_agent.agent
58+
]
59+
}
60+
61+
data "google_project" "project" {
62+
}
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 = "{{index $.Vars "agent_name"}}"
3+
location = "global"
4+
default_language_code = "en"
5+
time_zone = "America/New_York"
6+
description = "Example description."
7+
}
8+
9+
resource "google_dialogflow_cx_tool" "tool" {
10+
parent = google_dialogflow_cx_agent.agent.id
11+
display_name = "{{index $.Vars "tool_name"}}"
12+
description = "Example Description"
13+
function_spec {
14+
input_schema = <<EOF
15+
{
16+
"type": "object",
17+
"properties": {
18+
"message_to_echo": {
19+
"type": "string",
20+
"description": "The message that should be echoed back."
21+
}
22+
},
23+
"required": [
24+
"message_to_echo"
25+
]
26+
}
27+
EOF
28+
output_schema = <<EOF
29+
{
30+
"type": "object",
31+
"properties": {
32+
"echoed_message": {
33+
"type": "string",
34+
"description": "The message that is echoed back."
35+
}
36+
}
37+
}
38+
EOF
39+
}
40+
}
41+
42+
resource "google_dialogflow_cx_tool_version" "{{$.PrimaryResourceId}}" {
43+
parent = google_dialogflow_cx_tool.tool.id
44+
display_name = "Example Function Tool Version"
45+
tool {
46+
display_name = "{{index $.Vars "tool_name"}}"
47+
description = "Example Description"
48+
function_spec {
49+
input_schema = <<EOF
50+
{
51+
"type": "object",
52+
"properties": {
53+
"message_to_echo": {
54+
"type": "string",
55+
"description": "The message that should be echoed back."
56+
}
57+
},
58+
"required": [
59+
"message_to_echo"
60+
]
61+
}
62+
EOF
63+
output_schema = <<EOF
64+
{
65+
"type": "object",
66+
"properties": {
67+
"echoed_message": {
68+
"type": "string",
69+
"description": "The message that is echoed back."
70+
}
71+
}
72+
}
73+
EOF
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)