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

Add public network access to workspace #22542

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
Expand Down Expand Up @@ -74,6 +75,12 @@ func resourceArmDesktopVirtualizationWorkspace() *pluginsdk.Resource {
ValidateFunc: validation.StringLenBetween(1, 512),
},

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

"tags": commonschema.Tags(),
},
}
Expand Down Expand Up @@ -113,6 +120,14 @@ func resourceArmDesktopVirtualizationWorkspaceCreateUpdate(d *pluginsdk.Resource
},
}

publicNetworkAccess := workspace.PublicNetworkAccessEnabled

if !d.Get("public_network_access_enabled").(bool) {
publicNetworkAccess = workspace.PublicNetworkAccessDisabled
}

payload.Properties.PublicNetworkAccess = pointer.To(publicNetworkAccess)

if _, err := client.CreateOrUpdate(ctx, id, payload); err != nil {
return fmt.Errorf("creating/updating %s: %+v", id, err)
}
Expand Down Expand Up @@ -152,6 +167,11 @@ func resourceArmDesktopVirtualizationWorkspaceRead(d *pluginsdk.ResourceData, me
if props := model.Properties; props != nil {
d.Set("description", props.Description)
d.Set("friendly_name", props.FriendlyName)
publicNetworkAccess := true
if v := props.PublicNetworkAccess; v != nil && *v != workspace.PublicNetworkAccessEnabled {
publicNetworkAccess = false
}
d.Set("public_network_access_enabled", publicNetworkAccess)
}

if err := tags.FlattenAndSet(d, model.Tags); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ resource "azurerm_resource_group" "test" {
}

resource "azurerm_virtual_desktop_workspace" "test" {
name = "acctestWS%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
friendly_name = "Acceptance Test!"
description = "Acceptance Test by creating acctws%d"
name = "acctestWS%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
friendly_name = "Acceptance Test!"
description = "Acceptance Test by creating acctws%d"
public_network_access_enabled = false
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomIntOfLength(8), data.RandomInteger)
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/virtual_desktop_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ The following arguments are supported:
* `friendly_name` - (Optional) A friendly name for the Virtual Desktop Workspace.

* `description` - (Optional) A description for the Virtual Desktop Workspace.

* `public_network_access_enabled` - (Optional) Whether public network access is allowed for this Virtual Desktop Workspace. Defaults to `true`.

* `tags` - (Optional) A mapping of tags to assign to the resource.

Expand Down