Skip to content

Commit

Permalink
azurerm_bot_channel_directline - support for user_upload_enabled,…
Browse files Browse the repository at this point in the history
… `endpoint_parameters_enabled` and `storage_enabled` (#23149)

`azurerm_bot_channel_directline` - support for `user_upload_enabled`, `endpoint_parameters_enabled` and `storage_enabled`
  • Loading branch information
neil-yechenwei authored Sep 19, 2023
1 parent 4c0ff69 commit 4312123
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
49 changes: 47 additions & 2 deletions internal/services/bot/bot_channel_directline_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,29 @@ func resourceBotChannelDirectline() *pluginsdk.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},

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

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

"endpoint_parameters_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},

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

"v1_allowed": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -162,7 +179,7 @@ func resourceBotChannelDirectlineCreate(d *pluginsdk.ResourceData, meta interfac
}
d.SetId(resourceId.ID())

// Unable to create a new site with enhanced_authentication_enabled in the same operation, so we need to make two calls
// Unable to add a new site with enhanced_authentication_enabled, user_upload_enabled, endpoint_parameters_enabled, storage_enabled in the same operation, so we need to make two calls
if _, err := client.Update(ctx, resourceId.ResourceGroup, resourceId.BotServiceName, botservice.ChannelNameDirectLineChannel, channel); err != nil {
return fmt.Errorf("updating Directline Channel for Bot %q (Resource Group %q): %+v", resourceId.BotServiceName, resourceId.ResourceGroup, err)
}
Expand Down Expand Up @@ -236,6 +253,12 @@ func resourceBotChannelDirectlineUpdate(d *pluginsdk.ResourceData, meta interfac
return fmt.Errorf("updating Directline Channel for Bot %q (Resource Group %q): %+v", id.BotServiceName, id.ResourceGroup, err)
}

// Unable to add a new site with enhanced_authentication_enabled, user_upload_enabled, endpoint_parameters_enabled, storage_enabled in the same operation, so we need to make two calls
// Once this issue https://github.com/Azure/azure-rest-api-specs/issues/25758 is fixed, this update will be removed
if _, err := client.Update(ctx, id.ResourceGroup, id.BotServiceName, botservice.ChannelNameDirectLineChannel, channel); err != nil {
return fmt.Errorf("updating Directline Channel for Bot %q (Resource Group %q): %+v", id.BotServiceName, id.ResourceGroup, err)
}

return resourceBotChannelDirectlineRead(d, meta)
}

Expand Down Expand Up @@ -268,7 +291,11 @@ func expandDirectlineSites(input []interface{}) *[]botservice.DirectLineSite {
}

site := element.(map[string]interface{})
expanded := botservice.DirectLineSite{}
expanded := botservice.DirectLineSite{
IsBlockUserUploadEnabled: utils.Bool(!site["user_upload_enabled"].(bool)),
IsEndpointParametersEnabled: utils.Bool(site["endpoint_parameters_enabled"].(bool)),
IsNoStorageEnabled: utils.Bool(!site["storage_enabled"].(bool)),
}

if v, ok := site["name"].(string); ok {
expanded.SiteName = &v
Expand Down Expand Up @@ -310,6 +337,24 @@ func flattenDirectlineSites(input []botservice.DirectLineSite) []interface{} {
site["name"] = *v
}

userUploadEnabled := true
if v := element.IsBlockUserUploadEnabled; v != nil {
userUploadEnabled = !*v
}
site["user_upload_enabled"] = userUploadEnabled

var endpointParametersEnabled bool
if v := element.IsEndpointParametersEnabled; v != nil {
endpointParametersEnabled = *v
}
site["endpoint_parameters_enabled"] = endpointParametersEnabled

storageEnabled := true
if v := element.IsNoStorageEnabled; v != nil {
storageEnabled = !*v
}
site["storage_enabled"] = storageEnabled

if element.Key != nil {
site["key"] = *element.Key
}
Expand Down
15 changes: 14 additions & 1 deletion internal/services/bot/bot_channel_directline_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,26 @@ resource "azurerm_bot_channel_directline" "test" {
bot_name = "${azurerm_bot_channels_registration.test.name}"
location = "${azurerm_bot_channels_registration.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
site {
name = "test"
name = "test1"
enabled = true
v1_allowed = true
v3_allowed = true
enhanced_authentication_enabled = true
trusted_origins = ["https://example.com"]
user_upload_enabled = false
endpoint_parameters_enabled = true
storage_enabled = false
}
site {
name = "test2"
enabled = true
enhanced_authentication_enabled = false
user_upload_enabled = true
endpoint_parameters_enabled = false
storage_enabled = true
}
}
`, BotChannelsRegistrationResource{}.basicConfig(data))
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/bot_channel_directline.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ A `site` block has the following properties:

* `name` - (Required) The name of the site

* `user_upload_enabled` - (Optional) Is the user upload enabled for this site? Defaults to `true`.

* `enabled` - (Optional) Enables/Disables this site. Enabled by default Defaults to `true`.

* `endpoint_parameters_enabled` - (Optional) Is the endpoint parameters enabled for this site?

* `storage_enabled` - (Optional) Is the storage site enabled for detailed logging? Defaults to `true`.

* `v1_allowed` - (Optional) Enables v1 of the Directline protocol for this site. Enabled by default Defaults to `true`.

* `v3_allowed` - (Optional) Enables v3 of the Directline protocol for this site. Enabled by default Defaults to `true`.
Expand Down

0 comments on commit 4312123

Please sign in to comment.