Skip to content

Commit

Permalink
azurerm_proximity_placement_group - fix update when vm is attached (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o authored Mar 3, 2023
1 parent 5693ce9 commit 73bee76
Show file tree
Hide file tree
Showing 123 changed files with 13 additions and 6,122 deletions.
21 changes: 13 additions & 8 deletions internal/services/compute/proximity_placement_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-helpers/resourcemanager/zones"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/proximityplacementgroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/virtualmachines"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -57,7 +56,7 @@ func resourceProximityPlacementGroup() *pluginsdk.Resource {
MinItems: 1,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(virtualmachines.PossibleValuesForVirtualMachineSizeTypes(), false),
ValidateFunc: validation.StringIsNotEmpty,
},
},

Expand All @@ -82,8 +81,8 @@ func resourceProximityPlacementGroupCreateUpdate(d *pluginsdk.ResourceData, meta

id := proximityplacementgroups.NewProximityPlacementGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))

existing, err := client.Get(ctx, id, proximityplacementgroups.DefaultGetOperationOptions())
if d.IsNewResource() {
existing, err := client.Get(ctx, id, proximityplacementgroups.DefaultGetOperationOptions())
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing %s: %+v", id, err)
Expand All @@ -107,12 +106,18 @@ func resourceProximityPlacementGroupCreateUpdate(d *pluginsdk.ResourceData, meta
}
payload.Properties.Intent.VMSizes = utils.ExpandStringSlice(v.(*pluginsdk.Set).List())
} else if !d.IsNewResource() {
// Need to explicitly set an empty slice when updating to empty vm sizes
if payload.Properties.Intent == nil {
payload.Properties.Intent = &proximityplacementgroups.ProximityPlacementGroupPropertiesIntent{}
// Need to explicitly set an empty slice when updating vmSizes from non-empty to empty, and should not set it to an empty slice when existing vmSizes is empty when vm is attached
if model := existing.Model; model != nil {
if props := model.Properties; props != nil {
if intent := props.Intent; intent != nil && intent.VMSizes != nil {
if payload.Properties.Intent == nil {
payload.Properties.Intent = &proximityplacementgroups.ProximityPlacementGroupPropertiesIntent{}
}
vmSizes := make([]string, 0)
payload.Properties.Intent.VMSizes = &vmSizes
}
}
}
vmSizes := make([]string, 0)
payload.Properties.Intent.VMSizes = &vmSizes
}

if v, ok := d.GetOk("zone"); ok {
Expand Down
Loading

0 comments on commit 73bee76

Please sign in to comment.