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

azurerm_proximity_placement_group - fix update when vm is attached #20131

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't really do this here, whilst it may be lagging behind the swagger updates, not validating the values invites a lot of other problems. Is there a reason there's a lag between the swagger updates and the service updates?

Copy link
Contributor Author

@myc2h6o myc2h6o Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string slice only populates value for HardwareProfile.vmSize but not the full list of VM Sizes, thus some of the possible values are not contained there. It is currently not applicable to get a static full list, so updating it to the same validation as in VM

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that not indicate that the swagger is incomplete and needs these missing values added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the service is moving away from the static enum list, so the list is incomplete any more. It is said in the swagger that "The enum data type is currently deprecated and will be removed by December 23rd 2023.".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh then that would explain why it is not maintained. there isn't much we can do about it then. thanks @myc2h6o

},
},

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