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

New Resource azurerm_virtual_desktop_application #12077

Merged
merged 9 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -7,6 +7,7 @@ import (

type Client struct {
ApplicationGroupsClient *desktopvirtualization.ApplicationGroupsClient
ApplicationsClient *desktopvirtualization.ApplicationsClient
DesktopsClient *desktopvirtualization.DesktopsClient
HostPoolsClient *desktopvirtualization.HostPoolsClient
OperationsClient *desktopvirtualization.OperationsClient
Expand All @@ -19,6 +20,9 @@ func NewClient(o *common.ClientOptions) *Client {
ApplicationGroupsClient := desktopvirtualization.NewApplicationGroupsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ApplicationGroupsClient.Client, o.ResourceManagerAuthorizer)

ApplicationsClient := desktopvirtualization.NewApplicationsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ApplicationsClient.Client, o.ResourceManagerAuthorizer)

DesktopsClient := desktopvirtualization.NewDesktopsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&DesktopsClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -36,6 +40,7 @@ func NewClient(o *common.ClientOptions) *Client {

return &Client{
ApplicationGroupsClient: &ApplicationGroupsClient,
ApplicationsClient: &ApplicationsClient,
DesktopsClient: &DesktopsClient,
HostPoolsClient: &HostPoolsClient,
OperationsClient: &OperationsClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package migration

import (
"context"
"log"

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

var _ pluginsdk.StateUpgrade = ApplicationV0ToV1{}

type ApplicationV0ToV1 struct{}

func (ApplicationV0ToV1) Schema() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},

"application_group_id": {
Type: pluginsdk.TypeString,
Required: true,
},

"friendly_name": {
Type: pluginsdk.TypeString,
Optional: true,
},

"description": {
Type: pluginsdk.TypeString,
Optional: true,
},

"file_path": {
Type: pluginsdk.TypeString,
Optional: true,
},

"command_line_setting": {
Type: pluginsdk.TypeString,
Optional: true,
},

"command_line_arguments": {
Type: pluginsdk.TypeString,
Optional: true,
},

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

"icon_path": {
Type: pluginsdk.TypeString,
Optional: true,
},

"icon_index": {
Type: pluginsdk.TypeInt,
Optional: true,
},
}
}

func (ApplicationV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId := rawState["id"].(string)
id, err := parse.ApplicationIDInsensitively(oldId)
if err != nil {
return nil, err
}
newId := id.ID()
log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId)
rawState["id"] = newId

oldApplicationGroupId := rawState["application_group_id"].(string)
applicationGroupId, err := parse.HostPoolIDInsensitively(oldApplicationGroupId)
if err != nil {
return nil, err
}
newApplicationGroupId := applicationGroupId.ID()
log.Printf("[DEBUG] Updating Host Pool ID from %q to %q", oldApplicationGroupId, applicationGroupId)
rawState["application_group_id"] = newApplicationGroupId

return rawState, nil
}
}
131 changes: 131 additions & 0 deletions azurerm/internal/services/desktopvirtualization/parse/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type ApplicationId struct {
SubscriptionId string
ResourceGroup string
ApplicationGroupName string
Name string
}

func NewApplicationID(subscriptionId, resourceGroup, applicationGroupName, name string) ApplicationId {
return ApplicationId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
ApplicationGroupName: applicationGroupName,
Name: name,
}
}

func (id ApplicationId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Application Group Name %q", id.ApplicationGroupName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Application", segmentsStr)
}

func (id ApplicationId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DesktopVirtualization/applicationGroups/%s/applications/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.ApplicationGroupName, id.Name)
}

// ApplicationID parses a Application ID into an ApplicationId struct
func ApplicationID(input string) (*ApplicationId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := ApplicationId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.ApplicationGroupName, err = id.PopSegment("applicationGroups"); err != nil {
return nil, err
}
if resourceId.Name, err = id.PopSegment("applications"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}

// ApplicationIDInsensitively parses an Application ID into an ApplicationId struct, insensitively
// This should only be used to parse an ID for rewriting, the ApplicationID
// method should be used instead for validation etc.
//
// Whilst this may seem strange, this enables Terraform have consistent casing
// which works around issues in Core, whilst handling broken API responses.
func ApplicationIDInsensitively(input string) (*ApplicationId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := ApplicationId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

// find the correct casing for the 'applicationGroups' segment
applicationGroupsKey := "applicationGroups"
for key := range id.Path {
if strings.EqualFold(key, applicationGroupsKey) {
applicationGroupsKey = key
break
}
}
if resourceId.ApplicationGroupName, err = id.PopSegment(applicationGroupsKey); err != nil {
return nil, err
}

// find the correct casing for the 'applications' segment
applicationsKey := "applications"
for key := range id.Path {
if strings.EqualFold(key, applicationsKey) {
applicationsKey = key
break
}
}
if resourceId.Name, err = id.PopSegment(applicationsKey); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
Loading