diff --git a/internal/services/bot/bot_channel_direct_line_speech_resource.go b/internal/services/bot/bot_channel_direct_line_speech_resource.go index d0fb0b0f0d75..d07ffc5fe8ca 100644 --- a/internal/services/bot/bot_channel_direct_line_speech_resource.go +++ b/internal/services/bot/bot_channel_direct_line_speech_resource.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-05-01/cognitiveservicesaccounts" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" @@ -64,6 +65,12 @@ func resourceBotChannelDirectLineSpeech() *pluginsdk.Resource { "cognitive_service_location": commonschema.LocationWithoutForceNew(), + "cognitive_account_id": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: cognitiveservicesaccounts.ValidateAccountID, + }, + "custom_speech_model_id": { Type: schema.TypeString, Optional: true, @@ -112,6 +119,11 @@ func resourceBotChannelDirectLineSpeechCreate(d *pluginsdk.ResourceData, meta in Kind: botservice.KindBot, } + if v, ok := d.GetOk("cognitive_account_id"); ok { + channel, _ := channel.Properties.AsDirectLineSpeechChannel() + channel.Properties.CognitiveServiceResourceID = utils.String(v.(string)) + } + if v, ok := d.GetOk("custom_speech_model_id"); ok { channel, _ := channel.Properties.AsDirectLineSpeechChannel() channel.Properties.CustomSpeechModelID = utils.String(v.(string)) @@ -158,6 +170,7 @@ func resourceBotChannelDirectLineSpeechRead(d *pluginsdk.ResourceData, meta inte if props := resp.Properties; props != nil { if channel, ok := props.AsDirectLineSpeechChannel(); ok { if channelProps := channel.Properties; channelProps != nil { + d.Set("cognitive_account_id", channelProps.CognitiveServiceResourceID) d.Set("custom_speech_model_id", channelProps.CustomSpeechModelID) d.Set("custom_voice_deployment_id", channelProps.CustomVoiceDeploymentID) } @@ -191,6 +204,11 @@ func resourceBotChannelDirectLineSpeechUpdate(d *pluginsdk.ResourceData, meta in Kind: botservice.KindBot, } + if d.HasChange("cognitive_account_id") { + channel, _ := channel.Properties.AsDirectLineSpeechChannel() + channel.Properties.CognitiveServiceResourceID = utils.String(d.Get("cognitive_account_id").(string)) + } + if v, ok := d.GetOk("custom_speech_model_id"); ok { channel, _ := channel.Properties.AsDirectLineSpeechChannel() channel.Properties.CustomSpeechModelID = utils.String(v.(string)) diff --git a/internal/services/bot/bot_channel_direct_line_speech_resource_test.go b/internal/services/bot/bot_channel_direct_line_speech_resource_test.go index 27e58f32d686..e6a59e91f2b8 100644 --- a/internal/services/bot/bot_channel_direct_line_speech_resource_test.go +++ b/internal/services/bot/bot_channel_direct_line_speech_resource_test.go @@ -171,6 +171,7 @@ resource "azurerm_bot_channel_direct_line_speech" "test" { bot_name = azurerm_bot_channels_registration.test.name location = azurerm_bot_channels_registration.test.location resource_group_name = azurerm_resource_group.test.name + cognitive_account_id = azurerm_cognitive_account.test.id cognitive_service_location = azurerm_cognitive_account.test.location cognitive_service_access_key = azurerm_cognitive_account.test.primary_access_key custom_speech_model_id = "a9316355-7b04-4468-9f6e-114419e6c9cc" @@ -206,6 +207,7 @@ resource "azurerm_bot_channel_direct_line_speech" "test" { bot_name = azurerm_bot_channels_registration.test.name location = azurerm_bot_channels_registration.test.location resource_group_name = azurerm_resource_group.test.name + cognitive_account_id = azurerm_cognitive_account.test2.id cognitive_service_location = azurerm_cognitive_account.test2.location cognitive_service_access_key = azurerm_cognitive_account.test2.primary_access_key custom_speech_model_id = "cf7a4202-9be3-4195-9619-5a747260626d" diff --git a/website/docs/r/bot_channel_direct_line_speech.html.markdown b/website/docs/r/bot_channel_direct_line_speech.html.markdown index bf18c4dcc96c..58d88286e99e 100644 --- a/website/docs/r/bot_channel_direct_line_speech.html.markdown +++ b/website/docs/r/bot_channel_direct_line_speech.html.markdown @@ -55,6 +55,8 @@ The following arguments are supported: * `bot_name` - (Required) The name of the Bot Resource this channel will be associated with. Changing this forces a new resource to be created. +* `cognitive_account_id` - (Optional) The ID of the Cognitive Account this Bot Channel should be associated with. + * `cognitive_service_access_key` - (Required) The access key to access the Cognitive Service. * `cognitive_service_location` - (Required) Specifies the supported Azure location where the Cognitive Service resource exists.