From fc3dff8c5b7f02af92cc5d6c52b02dd10f473c3e Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 30 Aug 2023 12:43:38 +0800 Subject: [PATCH 1/4] azurerm_bot_channel_ms_teams - support for accepted_terms_enabled and deployment_environment --- .../bot/bot_channel_ms_teams_resource.go | 45 ++++++++++++++++--- .../bot/bot_channel_ms_teams_resource_test.go | 19 ++++---- .../docs/r/bot_channel_ms_teams.html.markdown | 4 ++ 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/internal/services/bot/bot_channel_ms_teams_resource.go b/internal/services/bot/bot_channel_ms_teams_resource.go index 0acaf1a78de2..e86d3d5e2a5b 100644 --- a/internal/services/bot/bot_channel_ms_teams_resource.go +++ b/internal/services/bot/bot_channel_ms_teams_resource.go @@ -4,6 +4,7 @@ package bot import ( + "context" "fmt" "log" "time" @@ -11,6 +12,7 @@ import ( "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" @@ -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": { @@ -63,6 +71,16 @@ 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, @@ -70,6 +88,17 @@ func resourceBotChannelMsTeams() *pluginsdk.Resource { 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") + } + + return nil + }, + ), } } @@ -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, }, @@ -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) } } @@ -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, }, diff --git a/internal/services/bot/bot_channel_ms_teams_resource_test.go b/internal/services/bot/bot_channel_ms_teams_resource_test.go index 97bd44e4355c..5a05c1383b07 100644 --- a/internal/services/bot/bot_channel_ms_teams_resource_test.go +++ b/internal/services/bot/bot_channel_ms_teams_resource_test.go @@ -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)) } @@ -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 = "GCCModerateDeployment" } `, BotChannelsRegistrationResource{}.basicConfig(data)) } diff --git a/website/docs/r/bot_channel_ms_teams.html.markdown b/website/docs/r/bot_channel_ms_teams.html.markdown index da4a0ed1f094..82036c0b9803 100644 --- a/website/docs/r/bot_channel_ms_teams.html.markdown +++ b/website/docs/r/bot_channel_ms_teams.html.markdown @@ -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 From dfdbb4b49085507812f2c4bb09120379c45b1c04 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 30 Aug 2023 12:46:05 +0800 Subject: [PATCH 2/4] update code --- internal/services/bot/bot_channel_ms_teams_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/bot/bot_channel_ms_teams_resource_test.go b/internal/services/bot/bot_channel_ms_teams_resource_test.go index 5a05c1383b07..f32e128beebe 100644 --- a/internal/services/bot/bot_channel_ms_teams_resource_test.go +++ b/internal/services/bot/bot_channel_ms_teams_resource_test.go @@ -101,7 +101,7 @@ resource "azurerm_bot_channel_ms_teams" "test" { calling_web_hook = "https://example.com/" enable_calling = true accepted_terms_enabled = true - deployment_environment = "GCCModerateDeployment" + deployment_environment = "CommercialDeployment" } `, BotChannelsRegistrationResource{}.basicConfig(data)) } From 1431dc3c2d9cd39a523b3979911bd9e179456115 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 4 Sep 2023 11:06:05 +0800 Subject: [PATCH 3/4] update code --- website/docs/r/bot_channel_ms_teams.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/bot_channel_ms_teams.html.markdown b/website/docs/r/bot_channel_ms_teams.html.markdown index 82036c0b9803..b9d8f559ff51 100644 --- a/website/docs/r/bot_channel_ms_teams.html.markdown +++ b/website/docs/r/bot_channel_ms_teams.html.markdown @@ -49,6 +49,8 @@ The following arguments are supported: * `accepted_terms_enabled` - (Optional) Is accepted terms for Microsoft Teams channel calls enabled? Defaults to `false`. +-> **NOTE:** Once `accepted_terms_enabled` is enabled, it cannot be disabled anymore. Even if this resource is destroyed, it still cannot be updated back to `false` once it's enabled. Unless the parent resource `azurerm_bot_channels_registration` is destroyed, then it would be set back 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`. From e308530041c808c04e2b6116e8c484f35540ee49 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Tue, 12 Sep 2023 15:39:37 +0800 Subject: [PATCH 4/4] update code --- .../bot/bot_channel_ms_teams_resource.go | 24 ++----------------- .../bot/bot_channel_ms_teams_resource_test.go | 8 +++---- .../docs/r/bot_channel_ms_teams.html.markdown | 4 ---- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/internal/services/bot/bot_channel_ms_teams_resource.go b/internal/services/bot/bot_channel_ms_teams_resource.go index e86d3d5e2a5b..2d39eeb9faed 100644 --- a/internal/services/bot/bot_channel_ms_teams_resource.go +++ b/internal/services/bot/bot_channel_ms_teams_resource.go @@ -4,7 +4,6 @@ package bot import ( - "context" "fmt" "log" "time" @@ -12,7 +11,6 @@ import ( "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" @@ -56,12 +54,6 @@ 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": { @@ -88,17 +80,6 @@ func resourceBotChannelMsTeams() *pluginsdk.Resource { 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") - } - - return nil - }, - ), } } @@ -124,7 +105,7 @@ func resourceBotChannelMsTeamsCreate(d *pluginsdk.ResourceData, meta interface{} channel := botservice.BotChannel{ Properties: botservice.MsTeamsChannel{ Properties: &botservice.MsTeamsChannelProperties{ - AcceptedTerms: utils.Bool(d.Get("accepted_terms_enabled").(bool)), + AcceptedTerms: utils.Bool(true), DeploymentEnvironment: utils.String(d.Get("deployment_environment").(string)), EnableCalling: utils.Bool(d.Get("enable_calling").(bool)), IsEnabled: utils.Bool(true), @@ -176,7 +157,6 @@ 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) @@ -200,7 +180,7 @@ func resourceBotChannelMsTeamsUpdate(d *pluginsdk.ResourceData, meta interface{} channel := botservice.BotChannel{ Properties: botservice.MsTeamsChannel{ Properties: &botservice.MsTeamsChannelProperties{ - AcceptedTerms: utils.Bool(d.Get("accepted_terms_enabled").(bool)), + AcceptedTerms: utils.Bool(true), 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)), diff --git a/internal/services/bot/bot_channel_ms_teams_resource_test.go b/internal/services/bot/bot_channel_ms_teams_resource_test.go index f32e128beebe..67f193eae6ff 100644 --- a/internal/services/bot/bot_channel_ms_teams_resource_test.go +++ b/internal/services/bot/bot_channel_ms_teams_resource_test.go @@ -82,10 +82,9 @@ 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 - accepted_terms_enabled = true + bot_name = azurerm_bot_channels_registration.test.name + location = azurerm_bot_channels_registration.test.location + resource_group_name = azurerm_resource_group.test.name } `, BotChannelsRegistrationResource{}.basicConfig(data)) } @@ -100,7 +99,6 @@ resource "azurerm_bot_channel_ms_teams" "test" { 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)) diff --git a/website/docs/r/bot_channel_ms_teams.html.markdown b/website/docs/r/bot_channel_ms_teams.html.markdown index b9d8f559ff51..5a07b28500df 100644 --- a/website/docs/r/bot_channel_ms_teams.html.markdown +++ b/website/docs/r/bot_channel_ms_teams.html.markdown @@ -47,10 +47,6 @@ 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`. - --> **NOTE:** Once `accepted_terms_enabled` is enabled, it cannot be disabled anymore. Even if this resource is destroyed, it still cannot be updated back to `false` once it's enabled. Unless the parent resource `azurerm_bot_channels_registration` is destroyed, then it would be set back 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`.