Skip to content

Commit

Permalink
r/virtual_desktop_workspace_application_group_association: switching …
Browse files Browse the repository at this point in the history
…to use the patch method rather than put/post
  • Loading branch information
tombuildsstuff committed Jun 22, 2022
1 parent 93fd97d commit d1ad74e
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ func resourceVirtualDesktopWorkspaceApplicationGroupAssociationCreate(d *plugins
locks.ByName(applicationGroupId.ApplicationGroupName, applicationGroupType)
defer locks.UnlockByName(applicationGroupId.ApplicationGroupName, applicationGroupType)

workspace, err := client.Get(ctx, *workspaceId)
existing, err := client.Get(ctx, *workspaceId)
if err != nil {
if response.WasNotFound(workspace.HttpResponse) {
if response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("%s was not found", *workspaceId)
}

return fmt.Errorf("retrieving %s: %+v", *workspaceId, err)
}
if workspace.Model == nil {
if existing.Model == nil {
return fmt.Errorf("retrieving %s: model was nil", *workspaceId)
}
model := *workspace.Model
model := *existing.Model

applicationGroupAssociations := []string{}
if props := model.Properties; props != nil && props.ApplicationGroupReferences != nil {
Expand All @@ -105,9 +105,12 @@ func resourceVirtualDesktopWorkspaceApplicationGroupAssociationCreate(d *plugins
}
applicationGroupAssociations = append(applicationGroupAssociations, applicationGroupIdStr)

model.Properties.ApplicationGroupReferences = &applicationGroupAssociations

if _, err = client.CreateOrUpdate(ctx, *workspaceId, model); err != nil {
payload := workspace.WorkspacePatch{
Properties: &workspace.WorkspacePatchProperties{
ApplicationGroupReferences: &applicationGroupAssociations,
},
}
if _, err = client.Update(ctx, *workspaceId, payload); err != nil {
return fmt.Errorf("creating association between %s and %s: %+v", *workspaceId, *applicationGroupId, err)
}

Expand Down Expand Up @@ -168,18 +171,18 @@ func resourceVirtualDesktopWorkspaceApplicationGroupAssociationDelete(d *plugins
locks.ByName(id.ApplicationGroup.ApplicationGroupName, applicationGroupType)
defer locks.UnlockByName(id.ApplicationGroup.ApplicationGroupName, applicationGroupType)

workspace, err := client.Get(ctx, id.Workspace)
existing, err := client.Get(ctx, id.Workspace)
if err != nil {
if response.WasNotFound(workspace.HttpResponse) {
if response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("%s was not found", id.Workspace)
}

return fmt.Errorf("retrieving %s: %+v", id.Workspace, err)
}
if workspace.Model == nil {
if existing.Model == nil {
return fmt.Errorf("retrieving %s: model was nil", id.Workspace)
}
model := *workspace.Model
model := *existing.Model

applicationGroupReferences := []string{}
applicationGroupId := id.ApplicationGroup.ID()
Expand All @@ -193,9 +196,12 @@ func resourceVirtualDesktopWorkspaceApplicationGroupAssociationDelete(d *plugins
}
}

model.Properties.ApplicationGroupReferences = &applicationGroupReferences

if _, err = client.CreateOrUpdate(ctx, id.Workspace, model); err != nil {
payload := workspace.WorkspacePatch{
Properties: &workspace.WorkspacePatchProperties{
ApplicationGroupReferences: &applicationGroupReferences,
},
}
if _, err = client.Update(ctx, id.Workspace, payload); err != nil {
return fmt.Errorf("removing association between %s and %s: %+v", id.Workspace, id.ApplicationGroup, err)
}

Expand Down

0 comments on commit d1ad74e

Please sign in to comment.