hashicorp / hashicorp/packer-plugin-azure
ARM: Improve validation of `direct_shared_gallery_image_id` and `community_gallery_image_id` and make include Microsoft links in plugin docs
- Dominant language
- Go
- Stars
- 63
- Forks
- 103
- PR merge metrics
- No merged PRs in 30d
Description
_This issue was originally opened by @sabuncumurat in https://github.com/hashicorp/packer/issues/13036 and has been migrated to this repository. The original issue description is below._
---
I have the following pkr.hcl file:
```
source "azure-arm" "from-sig" {
build_resource_group_name = "packer-build"
shared_image_gallery {
subscription = ""
resource_group = "MyImages"
gallery_name = "MyGallery"
image_name = "pkrgenimg"
image_version = "2.2.3"
}
shared_image_gallery_destination {
subscription = ""
resource_group = "MyImages"
gallery_name = "MyGallery"
image_name = "pkrgenimg"
image_version = "6.4.0"
target_region {
name = "northeurope"
}
...
}
```
The above works and version 6.4.0 of the image in question is generated successfully from version 2.2.3, as intended. All good.
When I replace `image_name` and `image_version` in the `shared_image_gallery` block with either `community_gallery_image_id` or `direct_shared_gallery_image_id`, the image generation fails:
```
shared_image_gallery {
subscription = ""
resource_group = "MyImages"
direct_shared_gallery_image_id = "/subscriptions//resourceGroups/MyImages/providers/Microsoft.Compute/galleries/MyGallery/images/pkrgenimg/versions/2.2.3"
}
```
PowerShell session error:
> ==> azure-arm.from-sig: ERROR: -> DeploymentFailed : At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.
> ==> azure-arm.from-sig: ERROR: -> BadRequest : Id /subscriptions/\/resourceGroups/MyImages/providers/Microsoft.Compute/galleries//images/ is not a valid resource reference.
Please note that in the second line of the error above, the Id string after BadRequest is missing components after the galleries part.
If this is not a bug, what is the proper way to use an `image_id` in a `shared_image_gallery` block?
And a related question - when the above image build fails, three artifacts are left behind and not cleaned up:

I have to remove them manually.
I am under the impression that Packer is supposed to clean up even in case of an error. Is this really the case?
Thank you.
Contributor guide
Research direction
Start with the pkr.hcl shared_image_gallery examples in the issue and reproduce the failures using direct_shared_gallery_image_id and community_gallery_image_id. Trace how these values are validated and used, and check the related cleanup behavior after a failed deployment. Done means invalid or unsupported inputs produce useful validation, failed builds clean up as expected, and the plugin documentation includes the relevant Microsoft links.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, go
- Domain
- cloud, documentation, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100