Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling_web_hook could be empty for azurerm_bot_channel_ms_teams #7294

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions azurerm/internal/services/bot/bot_channel_ms_teams_resource.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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