Skip to content

Commit

Permalink
r/bot_channel_directline: handling this being created by default behi…
Browse files Browse the repository at this point in the history
…nd the scenes
  • Loading branch information
tombuildsstuff committed Dec 7, 2020
1 parent add1d20 commit edd6b43
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
25 changes: 16 additions & 9 deletions azurerm/internal/services/bot/bot_channel_directline_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(""))
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions azurerm/internal/services/bot/bot_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit edd6b43

Please sign in to comment.