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

azurerm_bot_channel_ms_teams - support for deployment_environment #23122

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
45 changes: 40 additions & 5 deletions internal/services/bot/bot_channel_ms_teams_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
package bot

import (
"context"
"fmt"
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -54,6 +56,12 @@ func resourceBotChannelMsTeams() *pluginsdk.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},

"accepted_terms_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

// 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": {
Expand All @@ -63,13 +71,34 @@ func resourceBotChannelMsTeams() *pluginsdk.Resource {
ValidateFunc: validate.BotMSTeamsCallingWebHook(),
},

"deployment_environment": {
Type: pluginsdk.TypeString,
Optional: true,
Default: "CommercialDeployment",
ValidateFunc: validation.StringInSlice([]string{
"CommercialDeployment",
"GCCModerateDeployment",
}, false),
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_calling": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(
func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
oldVal, newVal := d.GetChange("accepted_terms_enabled")
if oldVal.(bool) && !newVal.(bool) {
return fmt.Errorf("`accepted_terms_enabled` cannot be disabled once it's been enabled")
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
},
),
}
}

Expand All @@ -95,8 +124,10 @@ func resourceBotChannelMsTeamsCreate(d *pluginsdk.ResourceData, meta interface{}
channel := botservice.BotChannel{
Properties: botservice.MsTeamsChannel{
Properties: &botservice.MsTeamsChannelProperties{
EnableCalling: utils.Bool(d.Get("enable_calling").(bool)),
IsEnabled: utils.Bool(true),
AcceptedTerms: utils.Bool(d.Get("accepted_terms_enabled").(bool)),
DeploymentEnvironment: utils.String(d.Get("deployment_environment").(string)),
EnableCalling: utils.Bool(d.Get("enable_calling").(bool)),
IsEnabled: utils.Bool(true),
},
ChannelName: botservice.ChannelNameBasicChannelChannelNameMsTeamsChannel,
},
Expand Down Expand Up @@ -145,7 +176,9 @@ func resourceBotChannelMsTeamsRead(d *pluginsdk.ResourceData, meta interface{})
if props := resp.Properties; props != nil {
if channel, ok := props.AsMsTeamsChannel(); ok {
if channelProps := channel.Properties; channelProps != nil {
d.Set("accepted_terms_enabled", channelProps.AcceptedTerms)
d.Set("calling_web_hook", channelProps.CallingWebhook)
d.Set("deployment_environment", channelProps.DeploymentEnvironment)
d.Set("enable_calling", channelProps.EnableCalling)
}
}
Expand All @@ -167,9 +200,11 @@ func resourceBotChannelMsTeamsUpdate(d *pluginsdk.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),
AcceptedTerms: utils.Bool(d.Get("accepted_terms_enabled").(bool)),
DeploymentEnvironment: utils.String(d.Get("deployment_environment").(string)),
EnableCalling: utils.Bool(d.Get("enable_calling").(bool)),
CallingWebhook: utils.String(d.Get("calling_web_hook").(string)),
IsEnabled: utils.Bool(true),
},
ChannelName: botservice.ChannelNameBasicChannelChannelNameMsTeamsChannel,
},
Expand Down
19 changes: 11 additions & 8 deletions internal/services/bot/bot_channel_ms_teams_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ func (BotChannelMsTeamsResource) basicConfig(data acceptance.TestData) string {
%s

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
bot_name = azurerm_bot_channels_registration.test.name
location = azurerm_bot_channels_registration.test.location
resource_group_name = azurerm_resource_group.test.name
accepted_terms_enabled = true
}
`, BotChannelsRegistrationResource{}.basicConfig(data))
}
Expand All @@ -94,11 +95,13 @@ func (BotChannelMsTeamsResource) basicUpdate(data acceptance.TestData) string {
%s

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
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
accepted_terms_enabled = true
deployment_environment = "CommercialDeployment"
}
`, BotChannelsRegistrationResource{}.basicConfig(data))
}
4 changes: 4 additions & 0 deletions website/docs/r/bot_channel_ms_teams.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ The following arguments are supported:

* `bot_name` - (Required) The name of the Bot Resource this channel will be associated with. Changing this forces a new resource to be created.

* `accepted_terms_enabled` - (Optional) Is accepted terms for Microsoft Teams channel calls enabled? Defaults to `false`.

* `calling_web_hook` - (Optional) Specifies the webhook for Microsoft Teams channel calls.

* `deployment_environment` - (Optional) The deployment environment for Microsoft Teams channel calls. Possible values are `CommercialDeployment` and `GCCModerateDeployment`. Defaults to `CommercialDeployment`.

* `enable_calling` - (Optional) Specifies whether to enable Microsoft Teams channel calls. This defaults to `false`.

## Attributes Reference
Expand Down