Skip to content

Commit

Permalink
Merge pull request #7294 from njuCZ/issue_5450
Browse files Browse the repository at this point in the history
calling_web_hook could be empty for `azurerm_bot_channel_ms_teams`
  • Loading branch information
tombuildsstuff committed Jun 11, 2020
2 parents f4be30f + 5fc5139 commit 92539a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
36 changes: 16 additions & 20 deletions azurerm/internal/services/bot/bot_channel_ms_teams_resource.go
Expand Up @@ -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(),
},

Expand Down Expand Up @@ -84,27 +87,31 @@ 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,
},
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
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)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}
}

Expand Down
Expand Up @@ -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)
}
Expand All @@ -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)
}
2 changes: 0 additions & 2 deletions website/docs/r/bot_channel_ms_teams.markdown
Expand Up @@ -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
}
```

Expand Down

0 comments on commit 92539a8

Please sign in to comment.