From 4f1a7d12b09e532c6ffaed30cd3d3ba0ee5f47f2 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 12 Jul 2021 15:27:26 -0500 Subject: [PATCH] New Resource : google_dialogflow_cx_flow (#4963) (#3422) Signed-off-by: Modular Magician --- .changelog/4963.txt | 3 + google-beta/provider.go | 5 +- google-beta/resource_dialogflow_cx_flow.go | 1307 +++++++++++++++++ ...ource_dialogflow_cx_flow_generated_test.go | 149 ++ .../resource_dialogflowcx_flow_test.go | 149 ++ .../docs/r/dialogflow_cx_flow.html.markdown | 350 +++++ website/google.erb | 4 + 7 files changed, 1965 insertions(+), 2 deletions(-) create mode 100644 .changelog/4963.txt create mode 100644 google-beta/resource_dialogflow_cx_flow.go create mode 100644 google-beta/resource_dialogflow_cx_flow_generated_test.go create mode 100644 google-beta/resource_dialogflowcx_flow_test.go create mode 100644 website/docs/r/dialogflow_cx_flow.html.markdown diff --git a/.changelog/4963.txt b/.changelog/4963.txt new file mode 100644 index 0000000000..8fb46546c1 --- /dev/null +++ b/.changelog/4963.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_dialogflow_cx_flow` +``` diff --git a/google-beta/provider.go b/google-beta/provider.go index 31044edba1..da1e4e764b 100644 --- a/google-beta/provider.go +++ b/google-beta/provider.go @@ -886,9 +886,9 @@ func Provider() *schema.Provider { return provider } -// Generated resources: 236 +// Generated resources: 237 // Generated IAM resources: 117 -// Total generated resources: 353 +// Total generated resources: 354 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -1095,6 +1095,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_dialogflow_fulfillment": resourceDialogflowFulfillment(), "google_dialogflow_cx_agent": resourceDialogflowCXAgent(), "google_dialogflow_cx_intent": resourceDialogflowCXIntent(), + "google_dialogflow_cx_flow": resourceDialogflowCXFlow(), "google_dns_managed_zone": resourceDNSManagedZone(), "google_dns_policy": resourceDNSPolicy(), "google_dns_record_set": resourceDNSResourceDnsRecordSet(), diff --git a/google-beta/resource_dialogflow_cx_flow.go b/google-beta/resource_dialogflow_cx_flow.go new file mode 100644 index 0000000000..92a7d35f8b --- /dev/null +++ b/google-beta/resource_dialogflow_cx_flow.go @@ -0,0 +1,1307 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// 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" + "log" + "reflect" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceDialogflowCXFlow() *schema.Resource { + return &schema.Resource{ + Create: resourceDialogflowCXFlowCreate, + Read: resourceDialogflowCXFlowRead, + Update: resourceDialogflowCXFlowUpdate, + Delete: resourceDialogflowCXFlowDelete, + + Importer: &schema.ResourceImporter{ + State: resourceDialogflowCXFlowImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(40 * time.Minute), + Update: schema.DefaultTimeout(40 * time.Minute), + Delete: schema.DefaultTimeout(4 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "display_name": { + Type: schema.TypeString, + Required: true, + Description: `The human-readable name of the flow.`, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(0, 500), + Description: `The description of the flow. The maximum length is 500 characters. If exceeded, the request is rejected.`, + }, + "event_handlers": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Description: `A flow's event handlers serve two purposes: +They are responsible for handling events (e.g. no match, webhook errors) in the flow. +They are inherited by every page's [event handlers][Page.event_handlers], which can be used to handle common events regardless of the current page. Event handlers defined in the page have higher priority than those defined in the flow. +Unlike transitionRoutes, these handlers are evaluated on a first-match basis. The first one that matches the event get executed, with the rest being ignored.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "event": { + Type: schema.TypeString, + Optional: true, + Description: `The name of the event to handle.`, + }, + "target_flow": { + Type: schema.TypeString, + Optional: true, + Description: `The target flow to transition to. +Format: projects//locations//agents//flows/.`, + }, + "target_page": { + Type: schema.TypeString, + Optional: true, + Description: `The target page to transition to. +Format: projects//locations//agents//flows//pages/.`, + }, + "trigger_fulfillment": { + Type: schema.TypeList, + Optional: true, + Description: `The fulfillment to call when the event occurs. Handling webhook errors with a fulfillment enabled with webhook could cause infinite loop. It is invalid to specify such fulfillment for a handler handling webhooks.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "messages": { + Type: schema.TypeList, + Optional: true, + Description: `The list of rich message responses to present to the user.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "text": { + Type: schema.TypeList, + Optional: true, + Description: `The text response message.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "text": { + Type: schema.TypeList, + Optional: true, + Description: `A collection of text responses.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "allow_playback_interruption": { + Type: schema.TypeBool, + Computed: true, + Description: `Whether the playback of this message can be interrupted by the end user's speech and the client can then starts the next Dialogflow request.`, + }, + }, + }, + }, + }, + }, + }, + "return_partial_responses": { + Type: schema.TypeBool, + Optional: true, + Description: `Whether Dialogflow should return currently queued fulfillment response messages in streaming APIs. If a webhook is specified, it happens before Dialogflow invokes webhook. Warning: 1) This flag only affects streaming API. Responses are still queued and returned once in non-streaming API. 2) The flag can be enabled in any fulfillment but only the first 3 partial responses will be returned. You may only want to apply it to fulfillments that have slow webhooks.`, + }, + "tag": { + Type: schema.TypeString, + Optional: true, + Description: `The tag used by the webhook to identify which fulfillment is being called. This field is required if webhook is specified.`, + }, + "webhook": { + Type: schema.TypeString, + Optional: true, + Description: `The webhook to call. Format: projects//locations//agents//webhooks/.`, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `The unique identifier of this event handler.`, + }, + }, + }, + }, + "language_code": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `The language of the following fields in flow: +Flow.event_handlers.trigger_fulfillment.messages +Flow.event_handlers.trigger_fulfillment.conditional_cases +Flow.transition_routes.trigger_fulfillment.messages +Flow.transition_routes.trigger_fulfillment.conditional_cases +If not specified, the agent's default language is used. Many languages are supported. Note: languages must be enabled in the agent before they can be used.`, + }, + "nlu_settings": { + Type: schema.TypeList, + Optional: true, + Description: `NLU related settings of the flow.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "classification_threshold": { + Type: schema.TypeFloat, + Optional: true, + Description: `To filter out false positive results and still get variety in matched natural language inputs for your agent, you can tune the machine learning classification threshold. +If the returned score value is less than the threshold value, then a no-match event will be triggered. The score values range from 0.0 (completely uncertain) to 1.0 (completely certain). If set to 0.0, the default of 0.3 is used.`, + }, + "model_training_mode": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"MODEL_TRAINING_MODE_AUTOMATIC", "MODEL_TRAINING_MODE_MANUAL", ""}, false), + Description: `Indicates NLU model training mode. +* MODEL_TRAINING_MODE_AUTOMATIC: NLU model training is automatically triggered when a flow gets modified. User can also manually trigger model training in this mode. +* MODEL_TRAINING_MODE_MANUAL: User needs to manually trigger NLU model training. Best for large flows whose models take long time to train. Possible values: ["MODEL_TRAINING_MODE_AUTOMATIC", "MODEL_TRAINING_MODE_MANUAL"]`, + }, + "model_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"MODEL_TYPE_STANDARD", "MODEL_TYPE_ADVANCED", ""}, false), + Description: `Indicates the type of NLU model. +* MODEL_TYPE_STANDARD: Use standard NLU model. +* MODEL_TYPE_ADVANCED: Use advanced NLU model. Possible values: ["MODEL_TYPE_STANDARD", "MODEL_TYPE_ADVANCED"]`, + }, + }, + }, + }, + "parent": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `The agent to create a flow for. +Format: projects//locations//agents/.`, + }, + "transition_route_groups": { + Type: schema.TypeList, + Optional: true, + Description: `A flow's transition route group serve two purposes: +They are responsible for matching the user's first utterances in the flow. +They are inherited by every page's [transition route groups][Page.transition_route_groups]. Transition route groups defined in the page have higher priority than those defined in the flow. +Format:projects//locations//agents//flows//transitionRouteGroups/.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "transition_routes": { + Type: schema.TypeList, + Optional: true, + Description: `A flow's transition routes serve two purposes: +They are responsible for matching the user's first utterances in the flow. +They are inherited by every page's [transition routes][Page.transition_routes] and can support use cases such as the user saying "help" or "can I talk to a human?", which can be handled in a common way regardless of the current page. Transition routes defined in the page have higher priority than those defined in the flow. + +TransitionRoutes are evalauted in the following order: + TransitionRoutes with intent specified. + TransitionRoutes with only condition specified. + TransitionRoutes with intent specified are inherited by pages in the flow.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "condition": { + Type: schema.TypeString, + Optional: true, + Description: `The condition to evaluate against form parameters or session parameters. +At least one of intent or condition must be specified. When both intent and condition are specified, the transition can only happen when both are fulfilled.`, + }, + "intent": { + Type: schema.TypeString, + Optional: true, + Description: `The unique identifier of an Intent. +Format: projects//locations//agents//intents/. Indicates that the transition can only happen when the given intent is matched. At least one of intent or condition must be specified. When both intent and condition are specified, the transition can only happen when both are fulfilled.`, + }, + "target_flow": { + Type: schema.TypeString, + Optional: true, + Description: `The target flow to transition to. +Format: projects//locations//agents//flows/.`, + }, + "target_page": { + Type: schema.TypeString, + Optional: true, + Description: `The target page to transition to. +Format: projects//locations//agents//flows//pages/.`, + }, + "trigger_fulfillment": { + Type: schema.TypeList, + Optional: true, + Description: `The fulfillment to call when the condition is satisfied. At least one of triggerFulfillment and target must be specified. When both are defined, triggerFulfillment is executed first.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "messages": { + Type: schema.TypeList, + Optional: true, + Description: `The list of rich message responses to present to the user.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "text": { + Type: schema.TypeList, + Optional: true, + Description: `The text response message.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "text": { + Type: schema.TypeList, + Optional: true, + Description: `A collection of text responses.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "allow_playback_interruption": { + Type: schema.TypeBool, + Computed: true, + Description: `Whether the playback of this message can be interrupted by the end user's speech and the client can then starts the next Dialogflow request.`, + }, + }, + }, + }, + }, + }, + }, + "return_partial_responses": { + Type: schema.TypeBool, + Optional: true, + Description: `Whether Dialogflow should return currently queued fulfillment response messages in streaming APIs. If a webhook is specified, it happens before Dialogflow invokes webhook. Warning: 1) This flag only affects streaming API. Responses are still queued and returned once in non-streaming API. 2) The flag can be enabled in any fulfillment but only the first 3 partial responses will be returned. You may only want to apply it to fulfillments that have slow webhooks.`, + }, + "tag": { + Type: schema.TypeString, + Optional: true, + Description: `The tag used by the webhook to identify which fulfillment is being called. This field is required if webhook is specified.`, + }, + "webhook": { + Type: schema.TypeString, + Optional: true, + Description: `The webhook to call. Format: projects//locations//agents//webhooks/.`, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `The unique identifier of this transition route.`, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `The unique identifier of the flow. +Format: projects//locations//agents//flows/.`, + }, + }, + UseJSONNumber: true, + } +} + +func resourceDialogflowCXFlowCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + displayNameProp, err := expandDialogflowCXFlowDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandDialogflowCXFlowDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + transitionRoutesProp, err := expandDialogflowCXFlowTransitionRoutes(d.Get("transition_routes"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("transition_routes"); !isEmptyValue(reflect.ValueOf(transitionRoutesProp)) && (ok || !reflect.DeepEqual(v, transitionRoutesProp)) { + obj["transitionRoutes"] = transitionRoutesProp + } + eventHandlersProp, err := expandDialogflowCXFlowEventHandlers(d.Get("event_handlers"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("event_handlers"); !isEmptyValue(reflect.ValueOf(eventHandlersProp)) && (ok || !reflect.DeepEqual(v, eventHandlersProp)) { + obj["eventHandlers"] = eventHandlersProp + } + transitionRouteGroupsProp, err := expandDialogflowCXFlowTransitionRouteGroups(d.Get("transition_route_groups"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("transition_route_groups"); !isEmptyValue(reflect.ValueOf(transitionRouteGroupsProp)) && (ok || !reflect.DeepEqual(v, transitionRouteGroupsProp)) { + obj["transitionRouteGroups"] = transitionRouteGroupsProp + } + nluSettingsProp, err := expandDialogflowCXFlowNluSettings(d.Get("nlu_settings"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("nlu_settings"); !isEmptyValue(reflect.ValueOf(nluSettingsProp)) && (ok || !reflect.DeepEqual(v, nluSettingsProp)) { + obj["nluSettings"] = nluSettingsProp + } + languageCodeProp, err := expandDialogflowCXFlowLanguageCode(d.Get("language_code"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("language_code"); !isEmptyValue(reflect.ValueOf(languageCodeProp)) && (ok || !reflect.DeepEqual(v, languageCodeProp)) { + obj["languageCode"] = languageCodeProp + } + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/flows") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Flow: %#v", obj) + billingProject := "" + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating Flow: %s", err) + } + if err := d.Set("name", flattenDialogflowCXFlowName(res["name"], d, config)); err != nil { + return fmt.Errorf(`Error setting computed identity field "name": %s`, err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{parent}}/flows/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Flow %q: %#v", d.Id(), res) + + return resourceDialogflowCXFlowRead(d, meta) +} + +func resourceDialogflowCXFlowRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/flows/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("DialogflowCXFlow %q", d.Id())) + } + + if err := d.Set("name", flattenDialogflowCXFlowName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + if err := d.Set("display_name", flattenDialogflowCXFlowDisplayName(res["displayName"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + if err := d.Set("description", flattenDialogflowCXFlowDescription(res["description"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + if err := d.Set("transition_routes", flattenDialogflowCXFlowTransitionRoutes(res["transitionRoutes"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + if err := d.Set("event_handlers", flattenDialogflowCXFlowEventHandlers(res["eventHandlers"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + if err := d.Set("transition_route_groups", flattenDialogflowCXFlowTransitionRouteGroups(res["transitionRouteGroups"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + if err := d.Set("nlu_settings", flattenDialogflowCXFlowNluSettings(res["nluSettings"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + if err := d.Set("language_code", flattenDialogflowCXFlowLanguageCode(res["languageCode"], d, config)); err != nil { + return fmt.Errorf("Error reading Flow: %s", err) + } + + return nil +} + +func resourceDialogflowCXFlowUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + obj := make(map[string]interface{}) + displayNameProp, err := expandDialogflowCXFlowDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandDialogflowCXFlowDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + transitionRoutesProp, err := expandDialogflowCXFlowTransitionRoutes(d.Get("transition_routes"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("transition_routes"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, transitionRoutesProp)) { + obj["transitionRoutes"] = transitionRoutesProp + } + eventHandlersProp, err := expandDialogflowCXFlowEventHandlers(d.Get("event_handlers"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("event_handlers"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, eventHandlersProp)) { + obj["eventHandlers"] = eventHandlersProp + } + transitionRouteGroupsProp, err := expandDialogflowCXFlowTransitionRouteGroups(d.Get("transition_route_groups"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("transition_route_groups"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, transitionRouteGroupsProp)) { + obj["transitionRouteGroups"] = transitionRouteGroupsProp + } + nluSettingsProp, err := expandDialogflowCXFlowNluSettings(d.Get("nlu_settings"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("nlu_settings"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nluSettingsProp)) { + obj["nluSettings"] = nluSettingsProp + } + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/flows/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Flow %q: %#v", d.Id(), obj) + updateMask := []string{} + + if d.HasChange("display_name") { + updateMask = append(updateMask, "displayName") + } + + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + + if d.HasChange("transition_routes") { + updateMask = append(updateMask, "transitionRoutes") + } + + if d.HasChange("event_handlers") { + updateMask = append(updateMask, "eventHandlers") + } + + if d.HasChange("transition_route_groups") { + updateMask = append(updateMask, "transitionRouteGroups") + } + + if d.HasChange("nlu_settings") { + updateMask = append(updateMask, "nluSettings") + } + // updateMask is a URL parameter but not present in the schema, so replaceVars + // won't set it + url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return fmt.Errorf("Error updating Flow %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating Flow %q: %#v", d.Id(), res) + } + + return resourceDialogflowCXFlowRead(d, meta) +} + +func resourceDialogflowCXFlowDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/flows/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Flow %q", d.Id()) + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "Flow") + } + + log.Printf("[DEBUG] Finished deleting Flow %q: %#v", d.Id(), res) + return nil +} + +func resourceDialogflowCXFlowImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + + // current import_formats can't import fields with forward slashes in their value and parent contains slashes + if err := parseImportId([]string{ + "(?P.+)/flows/(?P[^/]+)", + "(?P.+)/(?P[^/]+)", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "{{parent}}/flows/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenDialogflowCXFlowName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + return NameFromSelfLinkStateFunc(v) +} + +func flattenDialogflowCXFlowDisplayName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowDescription(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutes(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "name": flattenDialogflowCXFlowTransitionRoutesName(original["name"], d, config), + "intent": flattenDialogflowCXFlowTransitionRoutesIntent(original["intent"], d, config), + "condition": flattenDialogflowCXFlowTransitionRoutesCondition(original["condition"], d, config), + "trigger_fulfillment": flattenDialogflowCXFlowTransitionRoutesTriggerFulfillment(original["triggerFulfillment"], d, config), + "target_page": flattenDialogflowCXFlowTransitionRoutesTargetPage(original["targetPage"], d, config), + "target_flow": flattenDialogflowCXFlowTransitionRoutesTargetFlow(original["targetFlow"], d, config), + }) + } + return transformed +} +func flattenDialogflowCXFlowTransitionRoutesName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesIntent(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesCondition(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillment(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["messages"] = + flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessages(original["messages"], d, config) + transformed["webhook"] = + flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentWebhook(original["webhook"], d, config) + transformed["return_partial_responses"] = + flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentReturnPartialResponses(original["returnPartialResponses"], d, config) + transformed["tag"] = + flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentTag(original["tag"], d, config) + return []interface{}{transformed} +} +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessages(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "text": flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesText(original["text"], d, config), + }) + } + return transformed +} +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesText(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["text"] = + flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextText(original["text"], d, config) + transformed["allow_playback_interruption"] = + flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextAllowPlaybackInterruption(original["allowPlaybackInterruption"], d, config) + return []interface{}{transformed} +} +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextText(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextAllowPlaybackInterruption(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentWebhook(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentReturnPartialResponses(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesTriggerFulfillmentTag(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesTargetPage(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRoutesTargetFlow(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlers(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "name": flattenDialogflowCXFlowEventHandlersName(original["name"], d, config), + "event": flattenDialogflowCXFlowEventHandlersEvent(original["event"], d, config), + "trigger_fulfillment": flattenDialogflowCXFlowEventHandlersTriggerFulfillment(original["triggerFulfillment"], d, config), + "target_page": flattenDialogflowCXFlowEventHandlersTargetPage(original["targetPage"], d, config), + "target_flow": flattenDialogflowCXFlowEventHandlersTargetFlow(original["targetFlow"], d, config), + }) + } + return transformed +} +func flattenDialogflowCXFlowEventHandlersName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersEvent(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersTriggerFulfillment(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["messages"] = + flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessages(original["messages"], d, config) + transformed["webhook"] = + flattenDialogflowCXFlowEventHandlersTriggerFulfillmentWebhook(original["webhook"], d, config) + transformed["return_partial_responses"] = + flattenDialogflowCXFlowEventHandlersTriggerFulfillmentReturnPartialResponses(original["returnPartialResponses"], d, config) + transformed["tag"] = + flattenDialogflowCXFlowEventHandlersTriggerFulfillmentTag(original["tag"], d, config) + return []interface{}{transformed} +} +func flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessages(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "text": flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesText(original["text"], d, config), + }) + } + return transformed +} +func flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesText(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["text"] = + flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextText(original["text"], d, config) + transformed["allow_playback_interruption"] = + flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextAllowPlaybackInterruption(original["allowPlaybackInterruption"], d, config) + return []interface{}{transformed} +} +func flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextText(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextAllowPlaybackInterruption(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersTriggerFulfillmentWebhook(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersTriggerFulfillmentReturnPartialResponses(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersTriggerFulfillmentTag(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersTargetPage(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowEventHandlersTargetFlow(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowTransitionRouteGroups(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowNluSettings(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["model_type"] = + flattenDialogflowCXFlowNluSettingsModelType(original["modelType"], d, config) + transformed["classification_threshold"] = + flattenDialogflowCXFlowNluSettingsClassificationThreshold(original["classificationThreshold"], d, config) + transformed["model_training_mode"] = + flattenDialogflowCXFlowNluSettingsModelTrainingMode(original["modelTrainingMode"], d, config) + return []interface{}{transformed} +} +func flattenDialogflowCXFlowNluSettingsModelType(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowNluSettingsClassificationThreshold(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowNluSettingsModelTrainingMode(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXFlowLanguageCode(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func expandDialogflowCXFlowDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutes(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedName, err := expandDialogflowCXFlowTransitionRoutesName(original["name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) { + transformed["name"] = transformedName + } + + transformedIntent, err := expandDialogflowCXFlowTransitionRoutesIntent(original["intent"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedIntent); val.IsValid() && !isEmptyValue(val) { + transformed["intent"] = transformedIntent + } + + transformedCondition, err := expandDialogflowCXFlowTransitionRoutesCondition(original["condition"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCondition); val.IsValid() && !isEmptyValue(val) { + transformed["condition"] = transformedCondition + } + + transformedTriggerFulfillment, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillment(original["trigger_fulfillment"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTriggerFulfillment); val.IsValid() && !isEmptyValue(val) { + transformed["triggerFulfillment"] = transformedTriggerFulfillment + } + + transformedTargetPage, err := expandDialogflowCXFlowTransitionRoutesTargetPage(original["target_page"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTargetPage); val.IsValid() && !isEmptyValue(val) { + transformed["targetPage"] = transformedTargetPage + } + + transformedTargetFlow, err := expandDialogflowCXFlowTransitionRoutesTargetFlow(original["target_flow"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTargetFlow); val.IsValid() && !isEmptyValue(val) { + transformed["targetFlow"] = transformedTargetFlow + } + + req = append(req, transformed) + } + return req, nil +} + +func expandDialogflowCXFlowTransitionRoutesName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesIntent(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesCondition(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillment(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedMessages, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessages(original["messages"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedMessages); val.IsValid() && !isEmptyValue(val) { + transformed["messages"] = transformedMessages + } + + transformedWebhook, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentWebhook(original["webhook"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedWebhook); val.IsValid() && !isEmptyValue(val) { + transformed["webhook"] = transformedWebhook + } + + transformedReturnPartialResponses, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentReturnPartialResponses(original["return_partial_responses"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedReturnPartialResponses); val.IsValid() && !isEmptyValue(val) { + transformed["returnPartialResponses"] = transformedReturnPartialResponses + } + + transformedTag, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentTag(original["tag"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTag); val.IsValid() && !isEmptyValue(val) { + transformed["tag"] = transformedTag + } + + return transformed, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessages(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedText, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesText(original["text"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedText); val.IsValid() && !isEmptyValue(val) { + transformed["text"] = transformedText + } + + req = append(req, transformed) + } + return req, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesText(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedText, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextText(original["text"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedText); val.IsValid() && !isEmptyValue(val) { + transformed["text"] = transformedText + } + + transformedAllowPlaybackInterruption, err := expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextAllowPlaybackInterruption(original["allow_playback_interruption"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAllowPlaybackInterruption); val.IsValid() && !isEmptyValue(val) { + transformed["allowPlaybackInterruption"] = transformedAllowPlaybackInterruption + } + + return transformed, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextText(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentMessagesTextAllowPlaybackInterruption(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentWebhook(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentReturnPartialResponses(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesTriggerFulfillmentTag(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesTargetPage(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRoutesTargetFlow(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlers(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedName, err := expandDialogflowCXFlowEventHandlersName(original["name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) { + transformed["name"] = transformedName + } + + transformedEvent, err := expandDialogflowCXFlowEventHandlersEvent(original["event"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEvent); val.IsValid() && !isEmptyValue(val) { + transformed["event"] = transformedEvent + } + + transformedTriggerFulfillment, err := expandDialogflowCXFlowEventHandlersTriggerFulfillment(original["trigger_fulfillment"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTriggerFulfillment); val.IsValid() && !isEmptyValue(val) { + transformed["triggerFulfillment"] = transformedTriggerFulfillment + } + + transformedTargetPage, err := expandDialogflowCXFlowEventHandlersTargetPage(original["target_page"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTargetPage); val.IsValid() && !isEmptyValue(val) { + transformed["targetPage"] = transformedTargetPage + } + + transformedTargetFlow, err := expandDialogflowCXFlowEventHandlersTargetFlow(original["target_flow"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTargetFlow); val.IsValid() && !isEmptyValue(val) { + transformed["targetFlow"] = transformedTargetFlow + } + + req = append(req, transformed) + } + return req, nil +} + +func expandDialogflowCXFlowEventHandlersName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersEvent(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillment(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedMessages, err := expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessages(original["messages"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedMessages); val.IsValid() && !isEmptyValue(val) { + transformed["messages"] = transformedMessages + } + + transformedWebhook, err := expandDialogflowCXFlowEventHandlersTriggerFulfillmentWebhook(original["webhook"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedWebhook); val.IsValid() && !isEmptyValue(val) { + transformed["webhook"] = transformedWebhook + } + + transformedReturnPartialResponses, err := expandDialogflowCXFlowEventHandlersTriggerFulfillmentReturnPartialResponses(original["return_partial_responses"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedReturnPartialResponses); val.IsValid() && !isEmptyValue(val) { + transformed["returnPartialResponses"] = transformedReturnPartialResponses + } + + transformedTag, err := expandDialogflowCXFlowEventHandlersTriggerFulfillmentTag(original["tag"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTag); val.IsValid() && !isEmptyValue(val) { + transformed["tag"] = transformedTag + } + + return transformed, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessages(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedText, err := expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesText(original["text"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedText); val.IsValid() && !isEmptyValue(val) { + transformed["text"] = transformedText + } + + req = append(req, transformed) + } + return req, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesText(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedText, err := expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextText(original["text"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedText); val.IsValid() && !isEmptyValue(val) { + transformed["text"] = transformedText + } + + transformedAllowPlaybackInterruption, err := expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextAllowPlaybackInterruption(original["allow_playback_interruption"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAllowPlaybackInterruption); val.IsValid() && !isEmptyValue(val) { + transformed["allowPlaybackInterruption"] = transformedAllowPlaybackInterruption + } + + return transformed, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextText(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillmentMessagesTextAllowPlaybackInterruption(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillmentWebhook(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillmentReturnPartialResponses(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersTriggerFulfillmentTag(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersTargetPage(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowEventHandlersTargetFlow(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowTransitionRouteGroups(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowNluSettings(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedModelType, err := expandDialogflowCXFlowNluSettingsModelType(original["model_type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedModelType); val.IsValid() && !isEmptyValue(val) { + transformed["modelType"] = transformedModelType + } + + transformedClassificationThreshold, err := expandDialogflowCXFlowNluSettingsClassificationThreshold(original["classification_threshold"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedClassificationThreshold); val.IsValid() && !isEmptyValue(val) { + transformed["classificationThreshold"] = transformedClassificationThreshold + } + + transformedModelTrainingMode, err := expandDialogflowCXFlowNluSettingsModelTrainingMode(original["model_training_mode"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedModelTrainingMode); val.IsValid() && !isEmptyValue(val) { + transformed["modelTrainingMode"] = transformedModelTrainingMode + } + + return transformed, nil +} + +func expandDialogflowCXFlowNluSettingsModelType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowNluSettingsClassificationThreshold(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowNluSettingsModelTrainingMode(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXFlowLanguageCode(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google-beta/resource_dialogflow_cx_flow_generated_test.go b/google-beta/resource_dialogflow_cx_flow_generated_test.go new file mode 100644 index 0000000000..854803dafd --- /dev/null +++ b/google-beta/resource_dialogflow_cx_flow_generated_test.go @@ -0,0 +1,149 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// 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 TestAccDialogflowCXFlow_dialogflowcxFlowFullExample(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: testAccCheckDialogflowCXFlowDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDialogflowCXFlow_dialogflowcxFlowFullExample(context), + }, + { + ResourceName: "google_dialogflow_cx_flow.basic_flow", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent"}, + }, + }, + }) +} + +func testAccDialogflowCXFlow_dialogflowcxFlowFullExample(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_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?"] + } + } + } + } +} +`, context) +} + +func testAccCheckDialogflowCXFlowDestroyProducer(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_flow" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := googleProviderConfig(t) + + url, err := replaceVarsForTest(config, rs, "{{DialogflowCXBasePath}}{{parent}}/flows/{{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("DialogflowCXFlow still exists at %s", url) + } + } + + return nil + } +} diff --git a/google-beta/resource_dialogflowcx_flow_test.go b/google-beta/resource_dialogflowcx_flow_test.go new file mode 100644 index 0000000000..e0595a7675 --- /dev/null +++ b/google-beta/resource_dialogflowcx_flow_test.go @@ -0,0 +1,149 @@ +package google + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDialogflowCXFlow_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: testAccDialogflowCXFlow_basic(context), + }, + { + ResourceName: "google_dialogflow_cx_flow.my_flow", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDialogflowCXFlow_full(context), + }, + { + ResourceName: "google_dialogflow_cx_flow.my_flow", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccDialogflowCXFlow_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_entity" { + 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_flow" "my_flow" { + parent = google_dialogflow_cx_agent.agent_entity.id + display_name = "MyFlow" + + nlu_settings { + classification_threshold = 0.3 + model_type = "MODEL_TYPE_STANDARD" + } + } + `, context) +} + +func testAccDialogflowCXFlow_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_entity" { + 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_flow" "my_flow" { + parent = google_dialogflow_cx_agent.agent_entity.id + display_name = "MyFlow" + + 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?"] + } + } + } + } + } + `, context) +} diff --git a/website/docs/r/dialogflow_cx_flow.html.markdown b/website/docs/r/dialogflow_cx_flow.html.markdown new file mode 100644 index 0000000000..fe2fb3f0d9 --- /dev/null +++ b/website/docs/r/dialogflow_cx_flow.html.markdown @@ -0,0 +1,350 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# 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. +# +# ---------------------------------------------------------------------------- +subcategory: "Dialogflow CX" +layout: "google" +page_title: "Google: google_dialogflow_cx_flow" +sidebar_current: "docs-google-dialogflow-cx-flow" +description: |- + Flows represents the conversation flows when you build your chatbot agent. +--- + +# google\_dialogflow\_cx\_flow + +Flows represents the conversation flows when you build your chatbot agent. + + +To get more information about Flow, see: + +* [API documentation](https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents.flows) +* How-to Guides + * [Official Documentation](https://cloud.google.com/dialogflow/cx/docs) + + +## Example Usage - Dialogflowcx Flow Full + + +```hcl +resource "google_dialogflow_cx_agent" "agent" { + display_name = "dialogflowcx-agent" + 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?"] + } + } + } + } +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `display_name` - + (Required) + The human-readable name of the flow. + + +- - - + + +* `description` - + (Optional) + The description of the flow. The maximum length is 500 characters. If exceeded, the request is rejected. + +* `transition_routes` - + (Optional) + A flow's transition routes serve two purposes: + They are responsible for matching the user's first utterances in the flow. + They are inherited by every page's [transition routes][Page.transition_routes] and can support use cases such as the user saying "help" or "can I talk to a human?", which can be handled in a common way regardless of the current page. Transition routes defined in the page have higher priority than those defined in the flow. + + TransitionRoutes are evalauted in the following order: + TransitionRoutes with intent specified. + TransitionRoutes with only condition specified. + TransitionRoutes with intent specified are inherited by pages in the flow. + Structure is documented below. + +* `event_handlers` - + (Optional) + A flow's event handlers serve two purposes: + They are responsible for handling events (e.g. no match, webhook errors) in the flow. + They are inherited by every page's [event handlers][Page.event_handlers], which can be used to handle common events regardless of the current page. Event handlers defined in the page have higher priority than those defined in the flow. + Unlike transitionRoutes, these handlers are evaluated on a first-match basis. The first one that matches the event get executed, with the rest being ignored. + Structure is documented below. + +* `transition_route_groups` - + (Optional) + A flow's transition route group serve two purposes: + They are responsible for matching the user's first utterances in the flow. + They are inherited by every page's [transition route groups][Page.transition_route_groups]. Transition route groups defined in the page have higher priority than those defined in the flow. + Format:projects//locations//agents//flows//transitionRouteGroups/. + +* `nlu_settings` - + (Optional) + NLU related settings of the flow. + Structure is documented below. + +* `parent` - + (Optional) + The agent to create a flow for. + Format: projects//locations//agents/. + +* `language_code` - + (Optional) + The language of the following fields in flow: + Flow.event_handlers.trigger_fulfillment.messages + Flow.event_handlers.trigger_fulfillment.conditional_cases + Flow.transition_routes.trigger_fulfillment.messages + Flow.transition_routes.trigger_fulfillment.conditional_cases + If not specified, the agent's default language is used. Many languages are supported. Note: languages must be enabled in the agent before they can be used. + + +The `transition_routes` block supports: + +* `name` - + The unique identifier of this transition route. + +* `intent` - + (Optional) + The unique identifier of an Intent. + Format: projects//locations//agents//intents/. Indicates that the transition can only happen when the given intent is matched. At least one of intent or condition must be specified. When both intent and condition are specified, the transition can only happen when both are fulfilled. + +* `condition` - + (Optional) + The condition to evaluate against form parameters or session parameters. + At least one of intent or condition must be specified. When both intent and condition are specified, the transition can only happen when both are fulfilled. + +* `trigger_fulfillment` - + (Optional) + The fulfillment to call when the condition is satisfied. At least one of triggerFulfillment and target must be specified. When both are defined, triggerFulfillment is executed first. + Structure is documented below. + +* `target_page` - + (Optional) + The target page to transition to. + Format: projects//locations//agents//flows//pages/. + +* `target_flow` - + (Optional) + The target flow to transition to. + Format: projects//locations//agents//flows/. + + +The `trigger_fulfillment` block supports: + +* `messages` - + (Optional) + The list of rich message responses to present to the user. + Structure is documented below. + +* `webhook` - + (Optional) + The webhook to call. Format: projects//locations//agents//webhooks/. + +* `return_partial_responses` - + (Optional) + Whether Dialogflow should return currently queued fulfillment response messages in streaming APIs. If a webhook is specified, it happens before Dialogflow invokes webhook. Warning: 1) This flag only affects streaming API. Responses are still queued and returned once in non-streaming API. 2) The flag can be enabled in any fulfillment but only the first 3 partial responses will be returned. You may only want to apply it to fulfillments that have slow webhooks. + +* `tag` - + (Optional) + The tag used by the webhook to identify which fulfillment is being called. This field is required if webhook is specified. + + +The `messages` block supports: + +* `text` - + (Optional) + The text response message. + Structure is documented below. + + +The `text` block supports: + +* `text` - + (Optional) + A collection of text responses. + +* `allow_playback_interruption` - + Whether the playback of this message can be interrupted by the end user's speech and the client can then starts the next Dialogflow request. + +The `event_handlers` block supports: + +* `name` - + The unique identifier of this event handler. + +* `event` - + (Optional) + The name of the event to handle. + +* `trigger_fulfillment` - + (Optional) + The fulfillment to call when the event occurs. Handling webhook errors with a fulfillment enabled with webhook could cause infinite loop. It is invalid to specify such fulfillment for a handler handling webhooks. + Structure is documented below. + +* `target_page` - + (Optional) + The target page to transition to. + Format: projects//locations//agents//flows//pages/. + +* `target_flow` - + (Optional) + The target flow to transition to. + Format: projects//locations//agents//flows/. + + +The `trigger_fulfillment` block supports: + +* `messages` - + (Optional) + The list of rich message responses to present to the user. + Structure is documented below. + +* `webhook` - + (Optional) + The webhook to call. Format: projects//locations//agents//webhooks/. + +* `return_partial_responses` - + (Optional) + Whether Dialogflow should return currently queued fulfillment response messages in streaming APIs. If a webhook is specified, it happens before Dialogflow invokes webhook. Warning: 1) This flag only affects streaming API. Responses are still queued and returned once in non-streaming API. 2) The flag can be enabled in any fulfillment but only the first 3 partial responses will be returned. You may only want to apply it to fulfillments that have slow webhooks. + +* `tag` - + (Optional) + The tag used by the webhook to identify which fulfillment is being called. This field is required if webhook is specified. + + +The `messages` block supports: + +* `text` - + (Optional) + The text response message. + Structure is documented below. + + +The `text` block supports: + +* `text` - + (Optional) + A collection of text responses. + +* `allow_playback_interruption` - + Whether the playback of this message can be interrupted by the end user's speech and the client can then starts the next Dialogflow request. + +The `nlu_settings` block supports: + +* `model_type` - + (Optional) + Indicates the type of NLU model. + * MODEL_TYPE_STANDARD: Use standard NLU model. + * MODEL_TYPE_ADVANCED: Use advanced NLU model. + Possible values are `MODEL_TYPE_STANDARD` and `MODEL_TYPE_ADVANCED`. + +* `classification_threshold` - + (Optional) + To filter out false positive results and still get variety in matched natural language inputs for your agent, you can tune the machine learning classification threshold. + If the returned score value is less than the threshold value, then a no-match event will be triggered. The score values range from 0.0 (completely uncertain) to 1.0 (completely certain). If set to 0.0, the default of 0.3 is used. + +* `model_training_mode` - + (Optional) + Indicates NLU model training mode. + * MODEL_TRAINING_MODE_AUTOMATIC: NLU model training is automatically triggered when a flow gets modified. User can also manually trigger model training in this mode. + * MODEL_TRAINING_MODE_MANUAL: User needs to manually trigger NLU model training. Best for large flows whose models take long time to train. + Possible values are `MODEL_TRAINING_MODE_AUTOMATIC` and `MODEL_TRAINING_MODE_MANUAL`. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `{{parent}}/flows/{{name}}` + +* `name` - + The unique identifier of the flow. + Format: projects//locations//agents//flows/. + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 40 minutes. +- `update` - Default is 40 minutes. +- `delete` - Default is 4 minutes. + +## Import + + +Flow can be imported using any of these accepted formats: + +``` +$ terraform import google_dialogflow_cx_flow.default {{parent}}/flows/{{name}} +$ terraform import google_dialogflow_cx_flow.default {{parent}}/{{name}} +``` diff --git a/website/google.erb b/website/google.erb index 5a047b5e74..a0349bd21b 100644 --- a/website/google.erb +++ b/website/google.erb @@ -2312,6 +2312,10 @@ google_dialogflow_cx_agent +
  • + google_dialogflow_cx_flow +
  • +
  • google_dialogflow_cx_intent