Skip to content

Commit

Permalink
desktopvirtualization: fixing the host pool id/adding validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Nov 4, 2020
1 parent 570e3ba commit 17bab2d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package validate

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/desktopvirtualization/parse"
)

func VirtualDesktopHostPoolID(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
return
}

if _, err := parse.VirtualDesktopHostPoolID(v); err != nil {
errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err))
return
}

return warnings, errors
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/desktopvirtualization/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/desktopvirtualization/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -70,8 +71,9 @@ func resourceArmVirtualDesktopApplicationGroup() *schema.Resource {
},

"host_pool_id": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.VirtualDesktopHostPoolID,
},

"friendly_name": {
Expand Down Expand Up @@ -145,6 +147,7 @@ func resourceArmVirtualDesktopApplicationGroupCreateUpdate(d *schema.ResourceDat

func resourceArmVirtualDesktopApplicationGroupRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DesktopVirtualization.ApplicationGroupsClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -174,8 +177,18 @@ func resourceArmVirtualDesktopApplicationGroupRead(d *schema.ResourceData, meta
if props := resp.ApplicationGroupProperties; props != nil {
d.Set("friendly_name", props.FriendlyName)
d.Set("description", props.Description)
d.Set("host_pool_id", props.HostPoolArmPath)
d.Set("type", string(props.ApplicationGroupType))

hostPoolIdStr := ""
if props.HostPoolArmPath != nil {
hostPoolId, err := parse.VirtualDesktopHostPoolID(*props.HostPoolArmPath)
if err != nil {
return fmt.Errorf("parsing Host Pool ID %q: %+v", *props.HostPoolArmPath, err)
}

hostPoolIdStr = hostPoolId.ID(subscriptionId)
}
d.Set("host_pool_id", hostPoolIdStr)
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ resource "azurerm_virtual_desktop_application_group" "test" {
type = "Desktop"
host_pool_id = azurerm_virtual_desktop_host_pool.test.id
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomIntOfLength(8))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/desktopvirtualization/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
Expand Down Expand Up @@ -44,7 +43,7 @@ func resourceArmVirtualDesktopHostPool() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.DevSpaceName(),
ValidateFunc: validation.StringIsNotEmpty,
},

"location": azure.SchemaLocation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ resource "azurerm_virtual_desktop_host_pool" "test" {
validate_environment = true
load_balancer_type = "BreadthFirst"
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomString)
}

Expand Down Expand Up @@ -240,7 +239,6 @@ resource "azurerm_virtual_desktop_host_pool" "import" {
location = azurerm_virtual_desktop_host_pool.test.location
resource_group_name = azurerm_virtual_desktop_host_pool.test.resource_group_name
validate_environment = azurerm_virtual_desktop_host_pool.test.validate_environment
description = azurerm_virtual_desktop_host_pool.test.description
type = azurerm_virtual_desktop_host_pool.test.type
load_balancer_type = azurerm_virtual_desktop_host_pool.test.load_balancer_type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package desktopvirtualization
import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -131,7 +132,7 @@ func resourceArmVirtualDesktopWorkspaceApplicationGroupAssociationRead(d *schema
applicationGroupId := id.ApplicationGroup.ID(subscriptionId)
if props := workspace.WorkspaceProperties; props != nil && props.ApplicationGroupReferences != nil {
for _, reference := range *props.ApplicationGroupReferences {
exists = reference == applicationGroupId
exists = strings.EqualFold(reference, applicationGroupId)
if exists {
break
}
Expand Down

0 comments on commit 17bab2d

Please sign in to comment.