From 5fc51394be3a4f52d026dc618b6ec8a68169378f Mon Sep 17 00:00:00 2001 From: njucz Date: Thu, 11 Jun 2020 16:42:14 +0800 Subject: [PATCH] when callingWebHook is empty, make the field be nil, not a pointer of empty string --- .../bot/bot_channel_ms_teams_resource.go | 36 +++++++++---------- .../bot_channel_ms_teams_resource_test.go | 6 ++-- website/docs/r/bot_channel_ms_teams.markdown | 2 -- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/azurerm/internal/services/bot/bot_channel_ms_teams_resource.go b/azurerm/internal/services/bot/bot_channel_ms_teams_resource.go index 6ae8b7d0a23d..3b19dd979987 100644 --- a/azurerm/internal/services/bot/bot_channel_ms_teams_resource.go +++ b/azurerm/internal/services/bot/bot_channel_ms_teams_resource.go @@ -46,9 +46,12 @@ func resourceArmBotChannelMsTeams() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, + // issue: https://github.com/Azure/azure-rest-api-specs/issues/9809 + // this field could not update to empty, so add `Computed: true` to avoid diff "calling_web_hook": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validate.BotMSTeamsCallingWebHook(), }, @@ -84,9 +87,8 @@ func resourceArmBotChannelMsTeamsCreate(d *schema.ResourceData, meta interface{} channel := botservice.BotChannel{ Properties: botservice.MsTeamsChannel{ Properties: &botservice.MsTeamsChannelProperties{ - EnableCalling: utils.Bool(d.Get("enable_calling").(bool)), - CallingWebHook: utils.String(d.Get("calling_web_hook").(string)), - IsEnabled: utils.Bool(true), + EnableCalling: utils.Bool(d.Get("enable_calling").(bool)), + IsEnabled: utils.Bool(true), }, ChannelName: botservice.ChannelNameMsTeamsChannel1, }, @@ -94,17 +96,22 @@ func resourceArmBotChannelMsTeamsCreate(d *schema.ResourceData, meta interface{} Kind: botservice.KindBot, } + if v, ok := d.GetOk("calling_web_hook"); ok { + channel, _ := channel.Properties.AsMsTeamsChannel() + channel.Properties.CallingWebHook = utils.String(v.(string)) + } + if _, err := client.Create(ctx, resourceGroup, botName, botservice.ChannelNameMsTeamsChannel, channel); err != nil { - return fmt.Errorf("Error issuing create request for Channel MsTeams for Bot %q (Resource Group %q): %+v", resourceGroup, botName, err) + return fmt.Errorf("creating Channel MsTeams for Bot %q (Resource Group %q): %+v", botName, resourceGroup, err) } resp, err := client.Get(ctx, resourceGroup, botName, string(botservice.ChannelNameMsTeamsChannel)) if err != nil { - return fmt.Errorf("Error making get request for Channel MsTeams for Bot %q (Resource Group %q): %+v", resourceGroup, botName, err) + return fmt.Errorf("retrieving Channel MsTeams for Bot %q (Resource Group %q): %+v", botName, resourceGroup, err) } - if resp.ID == nil { - return fmt.Errorf("Cannot read Channel MsTeams for Bot %q (Resource Group %q): %+v", resourceGroup, botName, err) + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("empty or nil ID returned for Channel MsTeams for Bot %q (Resource Group %q): %+v", botName, resourceGroup, err) } d.SetId(*resp.ID) @@ -172,20 +179,9 @@ func resourceArmBotChannelMsTeamsUpdate(d *schema.ResourceData, meta interface{} } if _, err := client.Update(ctx, resourceGroup, botName, botservice.ChannelNameMsTeamsChannel, channel); err != nil { - return fmt.Errorf("Error issuing create request for Channel MsTeams for Bot %q (Resource Group %q): %+v", resourceGroup, botName, err) + return fmt.Errorf("updating Channel MsTeams for Bot %q (Resource Group %q): %+v", botName, resourceGroup, err) } - resp, err := client.Get(ctx, resourceGroup, botName, string(botservice.ChannelNameMsTeamsChannel)) - if err != nil { - return fmt.Errorf("Error making get request for Channel MsTeams for Bot %q (Resource Group %q): %+v", resourceGroup, botName, err) - } - - if resp.ID == nil { - return fmt.Errorf("Cannot read Channel MsTeams for Bot %q (Resource Group %q): %+v", resourceGroup, botName, err) - } - - d.SetId(*resp.ID) - return resourceArmBotChannelMsTeamsRead(d, meta) } @@ -204,7 +200,7 @@ func resourceArmBotChannelMsTeamsDelete(d *schema.ResourceData, meta interface{} resp, err := client.Delete(ctx, id.ResourceGroup, botName, string(botservice.ChannelNameMsTeamsChannel)) if err != nil { if !response.WasNotFound(resp.Response) { - return fmt.Errorf("Error deleting Channel MsTeams for Bot %q (Resource Group %q): %+v", id.ResourceGroup, botName, err) + return fmt.Errorf("deleting Channel MsTeams for Bot %q (Resource Group %q): %+v", botName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/bot/tests/bot_channel_ms_teams_resource_test.go b/azurerm/internal/services/bot/tests/bot_channel_ms_teams_resource_test.go index 5e44469e0384..49605f5ae7d1 100644 --- a/azurerm/internal/services/bot/tests/bot_channel_ms_teams_resource_test.go +++ b/azurerm/internal/services/bot/tests/bot_channel_ms_teams_resource_test.go @@ -130,8 +130,6 @@ resource "azurerm_bot_channel_ms_teams" "test" { bot_name = azurerm_bot_channels_registration.test.name location = azurerm_bot_channels_registration.test.location resource_group_name = azurerm_resource_group.test.name - calling_web_hook = "https://example.com/" - enable_calling = true } `, template) } @@ -145,8 +143,8 @@ resource "azurerm_bot_channel_ms_teams" "test" { bot_name = azurerm_bot_channels_registration.test.name location = azurerm_bot_channels_registration.test.location resource_group_name = azurerm_resource_group.test.name - calling_web_hook = "https://example2.com/" - enable_calling = false + calling_web_hook = "https://example.com/" + enable_calling = true } `, template) } diff --git a/website/docs/r/bot_channel_ms_teams.markdown b/website/docs/r/bot_channel_ms_teams.markdown index 8825b2f77391..54dec57328c0 100644 --- a/website/docs/r/bot_channel_ms_teams.markdown +++ b/website/docs/r/bot_channel_ms_teams.markdown @@ -34,8 +34,6 @@ resource "azurerm_bot_channel_ms_teams" "example" { bot_name = azurerm_bot_channels_registration.example.name location = azurerm_bot_channels_registration.example.location resource_group_name = azurerm_resource_group.example.name - calling_web_hook = "https://example2.com/" - enable_calling = false } ```