hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.46k stars 4.54k forks source link

shared_image_version not returning "latest" for large image galleries #26343

Open ktower opened 3 weeks ago

ktower commented 3 weeks ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.5

AzureRM Provider Version

3.108.0

Affected Resource(s)/Data Source(s)

azurerm_shared_image_version

Terraform Configuration Files

data "azurerm_shared_image_version" "image_from_gallery" {
  name.               = "latest"
  image_name.         = "my_image_name"
  gallery_name        = "my_gallery"
  resource_group_name = "my_rg"
}

output "image_version" {
  value = data.azurerm_shared_iamge_version.image_from_gallery.name
}

Debug Output/Panic Output

unable to provide at this time in order to prevent disclosure of internal data.

Expected Behaviour

Data source should provide a reference to the "latest" version of the image gallery.

Actual Behaviour

In galleries with large numbers of image versions, the 50th image version is provided.

Example:

$ terraform output image_latest
"2218.0.0"
$ az sig image-version list -g redacted --gallery-name redacted -i redacted -o tsv | wc -l
     154
$ az sig image-version list -g redacted --gallery-name redacted -i redacted -o tsv | head -50 | tail -1 | awk '{print $3}'
2218.0.0
$ az sig image-version list -g redacted --gallery-name redacted -i redacted -o tsv | tail -1 | awk '
{print $3}'
2424.0.0

Steps to Reproduce

Problem appears to manifest in all provider versions >= 3.98. Version 3.97 properly returns the latest image version.

Important Factoids

No response

References

No response

Chambras commented 3 weeks ago

Interesting 3.98.0 is when that part was migrated to use go-azure-sdk

xuzhang3 commented 2 weeks ago

This is a bug of the SDK not handling the paged response correctly, only the first page of the response was handled. The nextLink was ignored.

Response structure:

{
values: [],
nextLink: xxx.
}

but the SDK only handle the value. https://github.com/hashicorp/terraform-provider-azurerm/blob/main/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/method_listbygalleryimage.go#L52

xuzhang3 commented 2 weeks ago

SDK issue: https://github.com/hashicorp/go-azure-sdk/issues/1026