From bb249e14d7d18ab8f1c3980e0d587a992cc7de65 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Tue, 29 Aug 2023 10:48:43 +0800 Subject: [PATCH 1/5] azurerm_bot_channel_direct_line_speech - support for cognitive_service_id --- .../bot_channel_direct_line_speech_resource.go | 18 ++++++++++++++++++ ...channel_direct_line_speech_resource_test.go | 1 + ...ot_channel_direct_line_speech.html.markdown | 2 ++ 3 files changed, 21 insertions(+) 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..9803022db0e3 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_service_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_service_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_service_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 v, ok := d.GetOk("cognitive_service_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)) 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..31a9ec60e0ba 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_service_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" 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..8bbe6c540911 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_service_id` - (Optional) The resource ID of the Cognitive Service. + * `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. From 374712fb173500b36f5a8c7fbe8b0aacc87eb445 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Tue, 5 Sep 2023 16:58:39 +0800 Subject: [PATCH 2/5] update code --- .../bot/bot_channel_direct_line_speech_resource.go | 8 ++++---- .../bot/bot_channel_direct_line_speech_resource_test.go | 2 +- .../docs/r/bot_channel_direct_line_speech.html.markdown | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) 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 9803022db0e3..79d23896a778 100644 --- a/internal/services/bot/bot_channel_direct_line_speech_resource.go +++ b/internal/services/bot/bot_channel_direct_line_speech_resource.go @@ -65,7 +65,7 @@ func resourceBotChannelDirectLineSpeech() *pluginsdk.Resource { "cognitive_service_location": commonschema.LocationWithoutForceNew(), - "cognitive_service_id": { + "cognitive_account_id": { Type: schema.TypeString, Optional: true, ValidateFunc: cognitiveservicesaccounts.ValidateAccountID, @@ -119,7 +119,7 @@ func resourceBotChannelDirectLineSpeechCreate(d *pluginsdk.ResourceData, meta in Kind: botservice.KindBot, } - if v, ok := d.GetOk("cognitive_service_id"); ok { + if v, ok := d.GetOk("cognitive_account_id"); ok { channel, _ := channel.Properties.AsDirectLineSpeechChannel() channel.Properties.CognitiveServiceResourceID = utils.String(v.(string)) } @@ -170,7 +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_service_id", channelProps.CognitiveServiceResourceID) + d.Set("cognitive_account_id", channelProps.CognitiveServiceResourceID) d.Set("custom_speech_model_id", channelProps.CustomSpeechModelID) d.Set("custom_voice_deployment_id", channelProps.CustomVoiceDeploymentID) } @@ -204,7 +204,7 @@ func resourceBotChannelDirectLineSpeechUpdate(d *pluginsdk.ResourceData, meta in Kind: botservice.KindBot, } - if v, ok := d.GetOk("cognitive_service_id"); ok { + if v, ok := d.GetOk("cognitive_account_id"); ok { channel, _ := channel.Properties.AsDirectLineSpeechChannel() channel.Properties.CognitiveServiceResourceID = 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 31a9ec60e0ba..7978b6e176b0 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,7 +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_service_id = azurerm_cognitive_account.test.id + 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" 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 8bbe6c540911..69eb5c415b35 100644 --- a/website/docs/r/bot_channel_direct_line_speech.html.markdown +++ b/website/docs/r/bot_channel_direct_line_speech.html.markdown @@ -55,7 +55,7 @@ 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_service_id` - (Optional) The resource ID of the Cognitive Service. +* `cognitive_account_id` - (Optional) The resource ID of the Cognitive Account. * `cognitive_service_access_key` - (Required) The access key to access the Cognitive Service. From 2b519c6eefd988793b7356804114c5bb685788e9 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Tue, 5 Sep 2023 17:48:02 +0800 Subject: [PATCH 3/5] update code --- website/docs/r/bot_channel_direct_line_speech.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 69eb5c415b35..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,7 +55,7 @@ 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 resource ID of the Cognitive Account. +* `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. From 76189ad2972a619376806847906ad853e49efb0a Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 6 Sep 2023 09:18:41 +0800 Subject: [PATCH 4/5] update code --- .../services/bot/bot_channel_direct_line_speech_resource.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 79d23896a778..d07ffc5fe8ca 100644 --- a/internal/services/bot/bot_channel_direct_line_speech_resource.go +++ b/internal/services/bot/bot_channel_direct_line_speech_resource.go @@ -204,9 +204,9 @@ func resourceBotChannelDirectLineSpeechUpdate(d *pluginsdk.ResourceData, meta in Kind: botservice.KindBot, } - if v, ok := d.GetOk("cognitive_account_id"); ok { + if d.HasChange("cognitive_account_id") { channel, _ := channel.Properties.AsDirectLineSpeechChannel() - channel.Properties.CognitiveServiceResourceID = utils.String(v.(string)) + channel.Properties.CognitiveServiceResourceID = utils.String(d.Get("cognitive_account_id").(string)) } if v, ok := d.GetOk("custom_speech_model_id"); ok { From 94d6e073f6aa78107f161cace994ca717cf1a095 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 6 Sep 2023 10:31:57 +0800 Subject: [PATCH 5/5] update code --- .../services/bot/bot_channel_direct_line_speech_resource_test.go | 1 + 1 file changed, 1 insertion(+) 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 7978b6e176b0..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 @@ -207,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"