From edd6b43750f568c540cde5e1a47d785adf951cdf Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 7 Dec 2020 13:14:07 +0100 Subject: [PATCH] r/bot_channel_directline: handling this being created by default behind the scenes --- .../bot/bot_channel_directline_resource.go | 25 ++++++++++++------- .../services/bot/bot_web_app_resource.go | 2 ++ .../bot_channel_directline_resource_test.go | 4 +++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/azurerm/internal/services/bot/bot_channel_directline_resource.go b/azurerm/internal/services/bot/bot_channel_directline_resource.go index 401cfdf49c3d..8231fa1d7363 100644 --- a/azurerm/internal/services/bot/bot_channel_directline_resource.go +++ b/azurerm/internal/services/bot/bot_channel_directline_resource.go @@ -123,16 +123,23 @@ func resourceArmBotChannelDirectlineCreate(d *schema.ResourceData, meta interfac ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - resourceId := parse.NewBotChannelID(subscriptionId, d.Get("resource_group_name").(string), d.Get("bot_name").(string), string(botservice.ChannelNameDirectLineChannel)) - if d.IsNewResource() { - existing, err := client.Get(ctx, resourceId.ResourceGroup, resourceId.BotServiceName, resourceId.ChannelName) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Directline Channel for Bot %q (Resource Group %q): %+v", resourceId.BotServiceName, resourceId.ResourceGroup, err) - } + resourceId := parse.NewBotChannelID(subscriptionId, d.Get("resource_group_name").(string), d.Get("bot_name").(string), string(botservice.ChannelNameDirectLineChannel1)) + existing, err := client.Get(ctx, resourceId.ResourceGroup, resourceId.BotServiceName, resourceId.ChannelName) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("checking for presence of existing Directline Channel for Bot %q (Resource Group %q): %+v", resourceId.BotServiceName, resourceId.ResourceGroup, err) } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_bot_channel_directline", resourceId.ID("")) + } + if !utils.ResponseWasNotFound(existing.Response) { + // a "Default Site" site gets created and returned.. so let's check it's not just that + if props := existing.Properties; props != nil { + directLineChannel, ok := props.AsDirectLineChannel() + if ok && directLineChannel.Properties != nil { + sites := filterSites(directLineChannel.Properties.Sites) + if len(sites) != 0 { + return tf.ImportAsExistsError("azurerm_bot_channel_directline", resourceId.ID("")) + } + } } } diff --git a/azurerm/internal/services/bot/bot_web_app_resource.go b/azurerm/internal/services/bot/bot_web_app_resource.go index 20b1cda11530..95740fd28d49 100644 --- a/azurerm/internal/services/bot/bot_web_app_resource.go +++ b/azurerm/internal/services/bot/bot_web_app_resource.go @@ -193,6 +193,8 @@ func resourceArmBotWebAppCreate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("creating Web App Bot %q (Resource Group %q): %+v", resourceId.Name, resourceId.ResourceGroup, err) } + // TODO: in 3.0 we should remove the "Default Site" on the Directline resource at this point if we can + d.SetId(resourceId.ID("")) return resourceArmBotWebAppRead(d, meta) } diff --git a/azurerm/internal/services/bot/tests/bot_channel_directline_resource_test.go b/azurerm/internal/services/bot/tests/bot_channel_directline_resource_test.go index 3fab6c433b70..04b0dd97449a 100644 --- a/azurerm/internal/services/bot/tests/bot_channel_directline_resource_test.go +++ b/azurerm/internal/services/bot/tests/bot_channel_directline_resource_test.go @@ -13,6 +13,10 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +func TestAccAzureRMBotChannelDirectline_basic(t *testing.T) { + testAccAzureRMBotChannelDirectline_basic(t) +} + func testAccAzureRMBotChannelDirectline_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_bot_channel_directline", "test")