| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| |
| // ---------------------------------------------------------------------------- |
| // |
| // *** AUTO GENERATED CODE *** Type: MMv1 *** |
| // |
| // ---------------------------------------------------------------------------- |
| // |
| // 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 dialogflowcx |
| |
| import ( |
| "encoding/json" |
| "fmt" |
| "log" |
| "net/http" |
| "reflect" |
| "strings" |
| "time" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" |
| |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| ) |
| |
| func ResourceDialogflowCXAgent() *schema.Resource { |
| return &schema.Resource{ |
| Create: resourceDialogflowCXAgentCreate, |
| Read: resourceDialogflowCXAgentRead, |
| Update: resourceDialogflowCXAgentUpdate, |
| Delete: resourceDialogflowCXAgentDelete, |
| |
| Importer: &schema.ResourceImporter{ |
| State: resourceDialogflowCXAgentImport, |
| }, |
| |
| Timeouts: &schema.ResourceTimeout{ |
| Create: schema.DefaultTimeout(40 * time.Minute), |
| Update: schema.DefaultTimeout(40 * time.Minute), |
| Delete: schema.DefaultTimeout(20 * time.Minute), |
| }, |
| |
| CustomizeDiff: customdiff.All( |
| tpgresource.DefaultProviderProject, |
| ), |
| |
| Schema: map[string]*schema.Schema{ |
| "default_language_code": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The default language of the agent as a language tag. [See Language Support](https://cloud.google.com/dialogflow/cx/docs/reference/language) |
| for a list of the currently supported language codes. This field cannot be updated after creation.`, |
| }, |
| "display_name": { |
| Type: schema.TypeString, |
| Required: true, |
| Description: `The human-readable name of the agent, unique within the location.`, |
| }, |
| "location": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The name of the location this agent is located in. |
| |
| ~> **Note:** The first time you are deploying an Agent in your project you must configure location settings. |
| This is a one time step but at the moment you can only [configure location settings](https://cloud.google.com/dialogflow/cx/docs/concept/region#location-settings) via the Dialogflow CX console. |
| Another options is to use global location so you don't need to manually configure location settings.`, |
| }, |
| "time_zone": { |
| Type: schema.TypeString, |
| Required: true, |
| Description: `The time zone of this agent from the [time zone database](https://www.iana.org/time-zones), e.g., America/New_York, |
| Europe/Paris.`, |
| }, |
| "advanced_settings": { |
| Type: schema.TypeList, |
| Computed: true, |
| Optional: true, |
| Description: `Hierarchical advanced settings for this agent. The settings exposed at the lower level overrides the settings exposed at the higher level. |
| Hierarchy: Agent->Flow->Page->Fulfillment/Parameter.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "audio_export_gcs_destination": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `If present, incoming audio is exported by Dialogflow to the configured Google Cloud Storage destination. Exposed at the following levels: |
| * Agent level |
| * Flow level`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "uri": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The Google Cloud Storage URI for the exported objects. Whether a full object name, or just a prefix, its usage depends on the Dialogflow operation. |
| Format: gs://bucket/object-name-or-prefix`, |
| }, |
| }, |
| }, |
| }, |
| "dtmf_settings": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `Define behaviors for DTMF (dual tone multi frequency). DTMF settings does not override each other. DTMF settings set at different levels define DTMF detections running in parallel. Exposed at the following levels: |
| * Agent level |
| * Flow level |
| * Page level |
| * Parameter level`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "enabled": { |
| Type: schema.TypeBool, |
| Optional: true, |
| Description: `If true, incoming audio is processed for DTMF (dual tone multi frequency) events. For example, if the caller presses a button on their telephone keypad and DTMF processing is enabled, Dialogflow will detect the event (e.g. a "3" was pressed) in the incoming audio and pass the event to the bot to drive business logic (e.g. when 3 is pressed, return the account balance).`, |
| }, |
| "finish_digit": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The digit that terminates a DTMF digit sequence.`, |
| }, |
| "max_digits": { |
| Type: schema.TypeInt, |
| Optional: true, |
| Description: `Max length of DTMF digits.`, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| "avatar_uri": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The URI of the agent's avatar. Avatars are used throughout the Dialogflow console and in the self-hosted Web Demo integration.`, |
| }, |
| "description": { |
| Type: schema.TypeString, |
| Optional: true, |
| ValidateFunc: validation.StringLenBetween(0, 500), |
| Description: `The description of this agent. The maximum length is 500 characters. If exceeded, the request is rejected.`, |
| }, |
| "enable_spell_correction": { |
| Type: schema.TypeBool, |
| Optional: true, |
| Description: `Indicates if automatic spell correction is enabled in detect intent requests.`, |
| }, |
| "enable_stackdriver_logging": { |
| Type: schema.TypeBool, |
| Optional: true, |
| Description: `Determines whether this agent should log conversation queries.`, |
| }, |
| "git_integration_settings": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `Git integration settings for this agent.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "github_settings": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `Settings of integration with GitHub.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "access_token": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The access token used to authenticate the access to the GitHub repository.`, |
| Sensitive: true, |
| }, |
| "branches": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `A list of branches configured to be used from Dialogflow.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "display_name": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The unique repository display name for the GitHub repository.`, |
| }, |
| "repository_uri": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The GitHub repository URI related to the agent.`, |
| }, |
| "tracking_branch": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The branch of the GitHub repository tracked for this agent.`, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| "security_settings": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `Name of the SecuritySettings reference for the agent. Format: projects/<Project ID>/locations/<Location ID>/securitySettings/<Security Settings ID>.`, |
| }, |
| "speech_to_text_settings": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `Settings related to speech recognition.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "enable_speech_adaptation": { |
| Type: schema.TypeBool, |
| Optional: true, |
| Description: `Whether to use speech adaptation for speech recognition.`, |
| }, |
| }, |
| }, |
| }, |
| "supported_language_codes": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `The list of all languages supported by this agent (except for the default_language_code).`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "text_to_speech_settings": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `Settings related to speech synthesizing.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "synthesize_speech_configs": { |
| Type: schema.TypeString, |
| Optional: true, |
| ValidateFunc: validation.StringIsJSON, |
| StateFunc: func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }, |
| Description: `Configuration of how speech should be synthesized, mapping from [language](https://cloud.google.com/dialogflow/cx/docs/reference/language) to [SynthesizeSpeechConfig](https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents#synthesizespeechconfig). |
| These settings affect: |
| * The phone gateway synthesize configuration set via Agent.text_to_speech_settings. |
| * How speech is synthesized when invoking session APIs. 'Agent.text_to_speech_settings' only applies if 'OutputAudioConfig.synthesize_speech_config' is not specified.`, |
| }, |
| }, |
| }, |
| }, |
| "name": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The unique identifier of the agent.`, |
| }, |
| "start_flow": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Name of the start flow in this agent. A start flow will be automatically created when the agent is created, and can only be deleted by deleting the agent. Format: projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>.`, |
| }, |
| "project": { |
| Type: schema.TypeString, |
| Optional: true, |
| Computed: true, |
| ForceNew: true, |
| }, |
| }, |
| UseJSONNumber: true, |
| } |
| } |
| |
| func resourceDialogflowCXAgentCreate(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| obj := make(map[string]interface{}) |
| displayNameProp, err := expandDialogflowCXAgentDisplayName(d.Get("display_name"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { |
| obj["displayName"] = displayNameProp |
| } |
| defaultLanguageCodeProp, err := expandDialogflowCXAgentDefaultLanguageCode(d.Get("default_language_code"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("default_language_code"); !tpgresource.IsEmptyValue(reflect.ValueOf(defaultLanguageCodeProp)) && (ok || !reflect.DeepEqual(v, defaultLanguageCodeProp)) { |
| obj["defaultLanguageCode"] = defaultLanguageCodeProp |
| } |
| supportedLanguageCodesProp, err := expandDialogflowCXAgentSupportedLanguageCodes(d.Get("supported_language_codes"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("supported_language_codes"); !tpgresource.IsEmptyValue(reflect.ValueOf(supportedLanguageCodesProp)) && (ok || !reflect.DeepEqual(v, supportedLanguageCodesProp)) { |
| obj["supportedLanguageCodes"] = supportedLanguageCodesProp |
| } |
| timeZoneProp, err := expandDialogflowCXAgentTimeZone(d.Get("time_zone"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("time_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(timeZoneProp)) && (ok || !reflect.DeepEqual(v, timeZoneProp)) { |
| obj["timeZone"] = timeZoneProp |
| } |
| descriptionProp, err := expandDialogflowCXAgentDescription(d.Get("description"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { |
| obj["description"] = descriptionProp |
| } |
| avatarUriProp, err := expandDialogflowCXAgentAvatarUri(d.Get("avatar_uri"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("avatar_uri"); !tpgresource.IsEmptyValue(reflect.ValueOf(avatarUriProp)) && (ok || !reflect.DeepEqual(v, avatarUriProp)) { |
| obj["avatarUri"] = avatarUriProp |
| } |
| speechToTextSettingsProp, err := expandDialogflowCXAgentSpeechToTextSettings(d.Get("speech_to_text_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("speech_to_text_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(speechToTextSettingsProp)) && (ok || !reflect.DeepEqual(v, speechToTextSettingsProp)) { |
| obj["speechToTextSettings"] = speechToTextSettingsProp |
| } |
| securitySettingsProp, err := expandDialogflowCXAgentSecuritySettings(d.Get("security_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("security_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(securitySettingsProp)) && (ok || !reflect.DeepEqual(v, securitySettingsProp)) { |
| obj["securitySettings"] = securitySettingsProp |
| } |
| enableStackdriverLoggingProp, err := expandDialogflowCXAgentEnableStackdriverLogging(d.Get("enable_stackdriver_logging"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_stackdriver_logging"); !tpgresource.IsEmptyValue(reflect.ValueOf(enableStackdriverLoggingProp)) && (ok || !reflect.DeepEqual(v, enableStackdriverLoggingProp)) { |
| obj["enableStackdriverLogging"] = enableStackdriverLoggingProp |
| } |
| enableSpellCorrectionProp, err := expandDialogflowCXAgentEnableSpellCorrection(d.Get("enable_spell_correction"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_spell_correction"); !tpgresource.IsEmptyValue(reflect.ValueOf(enableSpellCorrectionProp)) && (ok || !reflect.DeepEqual(v, enableSpellCorrectionProp)) { |
| obj["enableSpellCorrection"] = enableSpellCorrectionProp |
| } |
| advancedSettingsProp, err := expandDialogflowCXAgentAdvancedSettings(d.Get("advanced_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("advanced_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(advancedSettingsProp)) && (ok || !reflect.DeepEqual(v, advancedSettingsProp)) { |
| obj["advancedSettings"] = advancedSettingsProp |
| } |
| gitIntegrationSettingsProp, err := expandDialogflowCXAgentGitIntegrationSettings(d.Get("git_integration_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("git_integration_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(gitIntegrationSettingsProp)) && (ok || !reflect.DeepEqual(v, gitIntegrationSettingsProp)) { |
| obj["gitIntegrationSettings"] = gitIntegrationSettingsProp |
| } |
| textToSpeechSettingsProp, err := expandDialogflowCXAgentTextToSpeechSettings(d.Get("text_to_speech_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("text_to_speech_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(textToSpeechSettingsProp)) && (ok || !reflect.DeepEqual(v, textToSpeechSettingsProp)) { |
| obj["textToSpeechSettings"] = textToSpeechSettingsProp |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DialogflowCXBasePath}}projects/{{project}}/locations/{{location}}/agents") |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Creating new Agent: %#v", obj) |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Agent: %s", err) |
| } |
| billingProject = project |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| headers := make(http.Header) |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "POST", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutCreate), |
| Headers: headers, |
| }) |
| if err != nil { |
| return fmt.Errorf("Error creating Agent: %s", err) |
| } |
| if err := d.Set("name", flattenDialogflowCXAgentName(res["name"], d, config)); err != nil { |
| return fmt.Errorf(`Error setting computed identity field "name": %s`, err) |
| } |
| |
| // Store the ID now |
| id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/agents/{{name}}") |
| if err != nil { |
| return fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| log.Printf("[DEBUG] Finished creating Agent %q: %#v", d.Id(), res) |
| |
| return resourceDialogflowCXAgentRead(d, meta) |
| } |
| |
| func resourceDialogflowCXAgentRead(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DialogflowCXBasePath}}projects/{{project}}/locations/{{location}}/agents/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Agent: %s", err) |
| } |
| billingProject = project |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| headers := make(http.Header) |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "GET", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Headers: headers, |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("DialogflowCXAgent %q", d.Id())) |
| } |
| |
| if err := d.Set("project", project); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| |
| if err := d.Set("name", flattenDialogflowCXAgentName(res["name"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("display_name", flattenDialogflowCXAgentDisplayName(res["displayName"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("default_language_code", flattenDialogflowCXAgentDefaultLanguageCode(res["defaultLanguageCode"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("supported_language_codes", flattenDialogflowCXAgentSupportedLanguageCodes(res["supportedLanguageCodes"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("time_zone", flattenDialogflowCXAgentTimeZone(res["timeZone"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("description", flattenDialogflowCXAgentDescription(res["description"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("avatar_uri", flattenDialogflowCXAgentAvatarUri(res["avatarUri"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("speech_to_text_settings", flattenDialogflowCXAgentSpeechToTextSettings(res["speechToTextSettings"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("start_flow", flattenDialogflowCXAgentStartFlow(res["startFlow"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("security_settings", flattenDialogflowCXAgentSecuritySettings(res["securitySettings"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("enable_stackdriver_logging", flattenDialogflowCXAgentEnableStackdriverLogging(res["enableStackdriverLogging"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("enable_spell_correction", flattenDialogflowCXAgentEnableSpellCorrection(res["enableSpellCorrection"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("advanced_settings", flattenDialogflowCXAgentAdvancedSettings(res["advancedSettings"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("git_integration_settings", flattenDialogflowCXAgentGitIntegrationSettings(res["gitIntegrationSettings"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| if err := d.Set("text_to_speech_settings", flattenDialogflowCXAgentTextToSpeechSettings(res["textToSpeechSettings"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Agent: %s", err) |
| } |
| |
| return nil |
| } |
| |
| func resourceDialogflowCXAgentUpdate(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Agent: %s", err) |
| } |
| billingProject = project |
| |
| obj := make(map[string]interface{}) |
| displayNameProp, err := expandDialogflowCXAgentDisplayName(d.Get("display_name"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { |
| obj["displayName"] = displayNameProp |
| } |
| supportedLanguageCodesProp, err := expandDialogflowCXAgentSupportedLanguageCodes(d.Get("supported_language_codes"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("supported_language_codes"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, supportedLanguageCodesProp)) { |
| obj["supportedLanguageCodes"] = supportedLanguageCodesProp |
| } |
| timeZoneProp, err := expandDialogflowCXAgentTimeZone(d.Get("time_zone"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("time_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, timeZoneProp)) { |
| obj["timeZone"] = timeZoneProp |
| } |
| descriptionProp, err := expandDialogflowCXAgentDescription(d.Get("description"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { |
| obj["description"] = descriptionProp |
| } |
| avatarUriProp, err := expandDialogflowCXAgentAvatarUri(d.Get("avatar_uri"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("avatar_uri"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, avatarUriProp)) { |
| obj["avatarUri"] = avatarUriProp |
| } |
| speechToTextSettingsProp, err := expandDialogflowCXAgentSpeechToTextSettings(d.Get("speech_to_text_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("speech_to_text_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, speechToTextSettingsProp)) { |
| obj["speechToTextSettings"] = speechToTextSettingsProp |
| } |
| securitySettingsProp, err := expandDialogflowCXAgentSecuritySettings(d.Get("security_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("security_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, securitySettingsProp)) { |
| obj["securitySettings"] = securitySettingsProp |
| } |
| enableStackdriverLoggingProp, err := expandDialogflowCXAgentEnableStackdriverLogging(d.Get("enable_stackdriver_logging"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_stackdriver_logging"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableStackdriverLoggingProp)) { |
| obj["enableStackdriverLogging"] = enableStackdriverLoggingProp |
| } |
| enableSpellCorrectionProp, err := expandDialogflowCXAgentEnableSpellCorrection(d.Get("enable_spell_correction"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_spell_correction"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableSpellCorrectionProp)) { |
| obj["enableSpellCorrection"] = enableSpellCorrectionProp |
| } |
| advancedSettingsProp, err := expandDialogflowCXAgentAdvancedSettings(d.Get("advanced_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("advanced_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, advancedSettingsProp)) { |
| obj["advancedSettings"] = advancedSettingsProp |
| } |
| gitIntegrationSettingsProp, err := expandDialogflowCXAgentGitIntegrationSettings(d.Get("git_integration_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("git_integration_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, gitIntegrationSettingsProp)) { |
| obj["gitIntegrationSettings"] = gitIntegrationSettingsProp |
| } |
| textToSpeechSettingsProp, err := expandDialogflowCXAgentTextToSpeechSettings(d.Get("text_to_speech_settings"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("text_to_speech_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, textToSpeechSettingsProp)) { |
| obj["textToSpeechSettings"] = textToSpeechSettingsProp |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DialogflowCXBasePath}}projects/{{project}}/locations/{{location}}/agents/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Updating Agent %q: %#v", d.Id(), obj) |
| headers := make(http.Header) |
| updateMask := []string{} |
| |
| if d.HasChange("display_name") { |
| updateMask = append(updateMask, "displayName") |
| } |
| |
| if d.HasChange("supported_language_codes") { |
| updateMask = append(updateMask, "supportedLanguageCodes") |
| } |
| |
| if d.HasChange("time_zone") { |
| updateMask = append(updateMask, "timeZone") |
| } |
| |
| if d.HasChange("description") { |
| updateMask = append(updateMask, "description") |
| } |
| |
| if d.HasChange("avatar_uri") { |
| updateMask = append(updateMask, "avatarUri") |
| } |
| |
| if d.HasChange("speech_to_text_settings") { |
| updateMask = append(updateMask, "speechToTextSettings") |
| } |
| |
| if d.HasChange("security_settings") { |
| updateMask = append(updateMask, "securitySettings") |
| } |
| |
| if d.HasChange("enable_stackdriver_logging") { |
| updateMask = append(updateMask, "enableStackdriverLogging") |
| } |
| |
| if d.HasChange("enable_spell_correction") { |
| updateMask = append(updateMask, "enableSpellCorrection") |
| } |
| |
| if d.HasChange("advanced_settings") { |
| updateMask = append(updateMask, "advancedSettings") |
| } |
| |
| if d.HasChange("git_integration_settings") { |
| updateMask = append(updateMask, "gitIntegrationSettings") |
| } |
| |
| if d.HasChange("text_to_speech_settings") { |
| updateMask = append(updateMask, "textToSpeechSettings") |
| } |
| // updateMask is a URL parameter but not present in the schema, so ReplaceVars |
| // won't set it |
| url, err = transport_tpg.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 := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| // if updateMask is empty we are not updating anything so skip the post |
| if len(updateMask) > 0 { |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "PATCH", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutUpdate), |
| Headers: headers, |
| }) |
| |
| if err != nil { |
| return fmt.Errorf("Error updating Agent %q: %s", d.Id(), err) |
| } else { |
| log.Printf("[DEBUG] Finished updating Agent %q: %#v", d.Id(), res) |
| } |
| |
| } |
| |
| return resourceDialogflowCXAgentRead(d, meta) |
| } |
| |
| func resourceDialogflowCXAgentDelete(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Agent: %s", err) |
| } |
| billingProject = project |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DialogflowCXBasePath}}projects/{{project}}/locations/{{location}}/agents/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| var obj map[string]interface{} |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| headers := make(http.Header) |
| |
| log.Printf("[DEBUG] Deleting Agent %q", d.Id()) |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "DELETE", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutDelete), |
| Headers: headers, |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, "Agent") |
| } |
| |
| log.Printf("[DEBUG] Finished deleting Agent %q: %#v", d.Id(), res) |
| return nil |
| } |
| |
| func resourceDialogflowCXAgentImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { |
| config := meta.(*transport_tpg.Config) |
| if err := tpgresource.ParseImportId([]string{ |
| "^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/agents/(?P<name>[^/]+)$", |
| "^(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<name>[^/]+)$", |
| "^(?P<location>[^/]+)/(?P<name>[^/]+)$", |
| }, d, config); err != nil { |
| return nil, err |
| } |
| |
| // Replace import id for the resource id |
| id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/agents/{{name}}") |
| if err != nil { |
| return nil, fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| return []*schema.ResourceData{d}, nil |
| } |
| |
| func flattenDialogflowCXAgentName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| return tpgresource.NameFromSelfLinkStateFunc(v) |
| } |
| |
| func flattenDialogflowCXAgentDisplayName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentDefaultLanguageCode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentSupportedLanguageCodes(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentTimeZone(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentAvatarUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentSpeechToTextSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["enable_speech_adaptation"] = |
| flattenDialogflowCXAgentSpeechToTextSettingsEnableSpeechAdaptation(original["enableSpeechAdaptation"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDialogflowCXAgentSpeechToTextSettingsEnableSpeechAdaptation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentStartFlow(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentSecuritySettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentEnableStackdriverLogging(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentEnableSpellCorrection(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentAdvancedSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["audio_export_gcs_destination"] = |
| flattenDialogflowCXAgentAdvancedSettingsAudioExportGcsDestination(original["audioExportGcsDestination"], d, config) |
| transformed["dtmf_settings"] = |
| flattenDialogflowCXAgentAdvancedSettingsDtmfSettings(original["dtmfSettings"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDialogflowCXAgentAdvancedSettingsAudioExportGcsDestination(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["uri"] = |
| flattenDialogflowCXAgentAdvancedSettingsAudioExportGcsDestinationUri(original["uri"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDialogflowCXAgentAdvancedSettingsAudioExportGcsDestinationUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentAdvancedSettingsDtmfSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["enabled"] = |
| flattenDialogflowCXAgentAdvancedSettingsDtmfSettingsEnabled(original["enabled"], d, config) |
| transformed["max_digits"] = |
| flattenDialogflowCXAgentAdvancedSettingsDtmfSettingsMaxDigits(original["maxDigits"], d, config) |
| transformed["finish_digit"] = |
| flattenDialogflowCXAgentAdvancedSettingsDtmfSettingsFinishDigit(original["finishDigit"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDialogflowCXAgentAdvancedSettingsDtmfSettingsEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentAdvancedSettingsDtmfSettingsMaxDigits(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| // Handles the string fixed64 format |
| if strVal, ok := v.(string); ok { |
| if intVal, err := tpgresource.StringToFixed64(strVal); err == nil { |
| return intVal |
| } |
| } |
| |
| // number values are represented as float64 |
| if floatVal, ok := v.(float64); ok { |
| intVal := int(floatVal) |
| return intVal |
| } |
| |
| return v // let terraform core handle it otherwise |
| } |
| |
| func flattenDialogflowCXAgentAdvancedSettingsDtmfSettingsFinishDigit(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDialogflowCXAgentGitIntegrationSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| transformed["github_settings"] = |
| flattenDialogflowCXAgentGitIntegrationSettingsGithubSettings(original["githubSettings"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDialogflowCXAgentGitIntegrationSettingsGithubSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| // ignore access_token, which is always returned as REDACTED |
| delete(original, "access_token") |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["display_name"] = original["displayName"] |
| transformed["repository_uri"] = original["repositoryUri"] |
| transformed["tracking_branch"] = original["trackingBranch"] |
| transformed["access_token"] = d.Get("git_integration_settings.0.github_settings.0.access_token") |
| transformed["branches"] = original["branches"] |
| return []interface{}{transformed} |
| } |
| |
| func flattenDialogflowCXAgentTextToSpeechSettings(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| transformed["synthesize_speech_configs"] = |
| flattenDialogflowCXAgentTextToSpeechSettingsSynthesizeSpeechConfigs(original["synthesizeSpeechConfigs"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDialogflowCXAgentTextToSpeechSettingsSynthesizeSpeechConfigs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| b, err := json.Marshal(v) |
| if err != nil { |
| // TODO: return error once https://github.com/GoogleCloudPlatform/magic-modules/issues/3257 is fixed. |
| log.Printf("[ERROR] failed to marshal schema to JSON: %v", err) |
| } |
| return string(b) |
| } |
| |
| func expandDialogflowCXAgentDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentDefaultLanguageCode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentSupportedLanguageCodes(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentTimeZone(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentAvatarUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentSpeechToTextSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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{}) |
| |
| transformedEnableSpeechAdaptation, err := expandDialogflowCXAgentSpeechToTextSettingsEnableSpeechAdaptation(original["enable_speech_adaptation"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedEnableSpeechAdaptation); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["enableSpeechAdaptation"] = transformedEnableSpeechAdaptation |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDialogflowCXAgentSpeechToTextSettingsEnableSpeechAdaptation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentSecuritySettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentEnableStackdriverLogging(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentEnableSpellCorrection(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentAdvancedSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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{}) |
| |
| transformedAudioExportGcsDestination, err := expandDialogflowCXAgentAdvancedSettingsAudioExportGcsDestination(original["audio_export_gcs_destination"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedAudioExportGcsDestination); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["audioExportGcsDestination"] = transformedAudioExportGcsDestination |
| } |
| |
| transformedDtmfSettings, err := expandDialogflowCXAgentAdvancedSettingsDtmfSettings(original["dtmf_settings"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedDtmfSettings); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["dtmfSettings"] = transformedDtmfSettings |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDialogflowCXAgentAdvancedSettingsAudioExportGcsDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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{}) |
| |
| transformedUri, err := expandDialogflowCXAgentAdvancedSettingsAudioExportGcsDestinationUri(original["uri"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedUri); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["uri"] = transformedUri |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDialogflowCXAgentAdvancedSettingsAudioExportGcsDestinationUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentAdvancedSettingsDtmfSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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{}) |
| |
| transformedEnabled, err := expandDialogflowCXAgentAdvancedSettingsDtmfSettingsEnabled(original["enabled"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["enabled"] = transformedEnabled |
| } |
| |
| transformedMaxDigits, err := expandDialogflowCXAgentAdvancedSettingsDtmfSettingsMaxDigits(original["max_digits"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedMaxDigits); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["maxDigits"] = transformedMaxDigits |
| } |
| |
| transformedFinishDigit, err := expandDialogflowCXAgentAdvancedSettingsDtmfSettingsFinishDigit(original["finish_digit"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedFinishDigit); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["finishDigit"] = transformedFinishDigit |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDialogflowCXAgentAdvancedSettingsDtmfSettingsEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentAdvancedSettingsDtmfSettingsMaxDigits(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentAdvancedSettingsDtmfSettingsFinishDigit(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentGitIntegrationSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| l := v.([]interface{}) |
| if len(l) == 0 { |
| return nil, nil |
| } |
| |
| if l[0] == nil { |
| transformed := make(map[string]interface{}) |
| return transformed, nil |
| } |
| raw := l[0] |
| original := raw.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| |
| transformedGithubSettings, err := expandDialogflowCXAgentGitIntegrationSettingsGithubSettings(original["github_settings"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedGithubSettings); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["githubSettings"] = transformedGithubSettings |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDialogflowCXAgentGitIntegrationSettingsGithubSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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{}) |
| |
| transformedDisplayName, err := expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsDisplayName(original["display_name"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["displayName"] = transformedDisplayName |
| } |
| |
| transformedRepositoryUri, err := expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsRepositoryUri(original["repository_uri"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedRepositoryUri); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["repositoryUri"] = transformedRepositoryUri |
| } |
| |
| transformedTrackingBranch, err := expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsTrackingBranch(original["tracking_branch"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedTrackingBranch); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["trackingBranch"] = transformedTrackingBranch |
| } |
| |
| transformedAccessToken, err := expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsAccessToken(original["access_token"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedAccessToken); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["accessToken"] = transformedAccessToken |
| } |
| |
| transformedBranches, err := expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsBranches(original["branches"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedBranches); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["branches"] = transformedBranches |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsRepositoryUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsTrackingBranch(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsAccessToken(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentGitIntegrationSettingsGithubSettingsBranches(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDialogflowCXAgentTextToSpeechSettings(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| l := v.([]interface{}) |
| if len(l) == 0 { |
| return nil, nil |
| } |
| |
| if l[0] == nil { |
| transformed := make(map[string]interface{}) |
| return transformed, nil |
| } |
| raw := l[0] |
| original := raw.(map[string]interface{}) |
| transformed := make(map[string]interface{}) |
| |
| transformedSynthesizeSpeechConfigs, err := expandDialogflowCXAgentTextToSpeechSettingsSynthesizeSpeechConfigs(original["synthesize_speech_configs"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedSynthesizeSpeechConfigs); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["synthesizeSpeechConfigs"] = transformedSynthesizeSpeechConfigs |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDialogflowCXAgentTextToSpeechSettingsSynthesizeSpeechConfigs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| b := []byte(v.(string)) |
| if len(b) == 0 { |
| return nil, nil |
| } |
| m := make(map[string]interface{}) |
| if err := json.Unmarshal(b, &m); err != nil { |
| return nil, err |
| } |
| return m, nil |
| } |