diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index f13ff0f9..36d885fd 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -109,7 +109,7 @@ type SharedImageGalleryDestination struct { // Set to true if publishing to a Specialized Gallery, this skips a call to set the build VM's OS state as Generalized SigDestinationSpecialized bool `mapstructure:"specialized"` // Set to true if you want to publish using Shallow Replication, this is faster but skips copying the full image to the gallery image region, read more about Shallow Replication [here](https://learn.microsoft.com/en-us/azure/virtual-machines/shared-image-galleries?tabs=azure-cli#shallow-replication) - SigDestinationShallowReplicationMode bool `mapstructure:"shallow_replication"` + SigDestinationShallowReplicationMode bool `mapstructure:"shallow_replication" required:"false"` } type Spot struct { @@ -217,7 +217,7 @@ type Config struct { // The number of replicas of the Image Version to be created per region. This // property would take effect for a region when regionalReplicaCount is not specified. // Replica count must be between 1 and 100, but 50 replicas should be sufficient for most use cases. - SharedGalleryImageVersionReplicaCount int32 `mapstructure:"shared_image_gallery_replica_count" required:"false"` + SharedGalleryImageVersionReplicaCount int64 `mapstructure:"shared_image_gallery_replica_count" required:"false"` // If set to true, Virtual Machines deployed from the latest version of the // Image Definition won't use this Image Version. SharedGalleryImageVersionExcludeFromLatest bool `mapstructure:"shared_gallery_image_version_exclude_from_latest" required:"false"` diff --git a/builder/azure/arm/step_publish_to_shared_image_gallery.go b/builder/azure/arm/step_publish_to_shared_image_gallery.go index 84041c83..c51fe4f0 100644 --- a/builder/azure/arm/step_publish_to_shared_image_gallery.go +++ b/builder/azure/arm/step_publish_to_shared_image_gallery.go @@ -110,7 +110,7 @@ func (s *StepPublishToSharedImageGallery) publishToSig(publishArgs PublishArgs) } } replicationMode := galleryimageversions.ReplicationModeFull - if true { + if publishArgs.shallowReplicationMode { replicationMode = galleryimageversions.ReplicationModeShallow } galleryImageVersion := galleryimageversions.GalleryImageVersion{ @@ -207,6 +207,9 @@ func (s *StepPublishToSharedImageGallery) Run(ctx context.Context, stateBag mult s.say(fmt.Sprintf(" -> SIG image version exclude from latest : '%t'", miSGImageVersionExcludeFromLatest)) s.say(fmt.Sprintf(" -> SIG replica count [1, 100] : '%d'", miSigReplicaCount)) shallowReplicationMode := stateBag.Get(constants.ArmSharedImageGalleryDestinationShallowReplication).(bool) + if shallowReplicationMode { + s.say(" -> Creating SIG Image with Shallow Replication") + } subscriptionID := stateBag.Get(constants.ArmSharedImageGalleryDestinationSubscription).(string) createdGalleryImageVersionID, err := s.publish( PublishArgs{ diff --git a/builder/azure/arm/step_publish_to_shared_image_gallery_test.go b/builder/azure/arm/step_publish_to_shared_image_gallery_test.go index c3dbe999..627ba98d 100644 --- a/builder/azure/arm/step_publish_to_shared_image_gallery_test.go +++ b/builder/azure/arm/step_publish_to_shared_image_gallery_test.go @@ -16,7 +16,7 @@ import ( func TestStepPublishToSharedImageGalleryShouldNotPublishForVhd(t *testing.T) { var testSubject = &StepPublishToSharedImageGallery{ - publish: func(context.Context, string, string, SharedImageGalleryDestination, string, bool, int64, string, string, map[string]string) (string, error) { + publish: func(PublishArgs) (string, error) { return "test", nil }, say: func(message string) {}, @@ -37,7 +37,7 @@ func TestStepPublishToSharedImageGalleryShouldNotPublishForVhd(t *testing.T) { func TestStepPublishToSharedImageGalleryShouldPublishForManagedImageWithSig(t *testing.T) { var testSubject = &StepPublishToSharedImageGallery{ - publish: func(context.Context, string, string, SharedImageGalleryDestination, string, bool, int64, string, string, map[string]string) (string, error) { + publish: func(PublishArgs) (string, error) { return "", nil }, say: func(message string) {}, @@ -58,7 +58,7 @@ func TestStepPublishToSharedImageGalleryShouldPublishForManagedImageWithSig(t *t func TestStepPublishToSharedImageGalleryShouldPublishForNonManagedImageWithSig(t *testing.T) { var testSubject = &StepPublishToSharedImageGallery{ - publish: func(context.Context, string, string, SharedImageGalleryDestination, string, bool, int64, string, string, map[string]string) (string, error) { + publish: func(PublishArgs) (string, error) { return "", nil }, say: func(message string) {}, diff --git a/builder/azure/arm/testdata/arm_linux_specialized.pkr.hcl b/builder/azure/arm/testdata/arm_linux_specialized.pkr.hcl index 3be91c29..d4a00006 100644 --- a/builder/azure/arm/testdata/arm_linux_specialized.pkr.hcl +++ b/builder/azure/arm/testdata/arm_linux_specialized.pkr.hcl @@ -4,25 +4,26 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } variable "ssh_private_key_location" { default = "${env("ARM_SSH_PRIVATE_KEY_FILE")}" - type = string + type = string } source "azure-arm" "linux-sig" { - image_offer = "0001-com-ubuntu-server-jammy" - image_publisher = "canonical" - image_sku = "22_04-lts-arm64" - use_azure_cli_auth = true - location = "South Central US" - vm_size = "Standard_D4ps_v5" - ssh_username = "packer" + image_offer = "0001-com-ubuntu-server-jammy" + image_publisher = "canonical" + image_sku = "22_04-lts-arm64" + use_azure_cli_auth = true + location = "South Central US" + vm_size = "Standard_D4ps_v5" + ssh_username = "packer" ssh_private_key_file = var.ssh_private_key_location - communicator = "ssh" + communicator = "ssh" shared_image_gallery_destination { - image_name = "arm-linux-specialized-sig" - gallery_name = "acctestgallery" - image_version = "1.0.0" - resource_group = "packer-acceptance-test" - specialized = true + image_name = "arm-linux-specialized-sig" + gallery_name = "acctestgallery" + image_version = "1.0.0" + resource_group = "packer-acceptance-test" + specialized = true + shallow_replication = true } os_type = "Linux" diff --git a/builder/azure/arm/testdata/child_from_specialized_parent.pkr.hcl b/builder/azure/arm/testdata/child_from_specialized_parent.pkr.hcl index 9d8c742b..c770780d 100644 --- a/builder/azure/arm/testdata/child_from_specialized_parent.pkr.hcl +++ b/builder/azure/arm/testdata/child_from_specialized_parent.pkr.hcl @@ -3,24 +3,24 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } variable "subscription" { - default = "${env("ARM_SUBSCRIPTION_ID")}" - type = string + default = "${env("ARM_SUBSCRIPTION_ID")}" + type = string sensitive = true } variable "ssh_private_key_location" { default = "${env("ARM_SSH_PRIVATE_KEY_FILE")}" - type = string + type = string } source "azure-arm" "linux-sig" { - use_azure_cli_auth = true - location = "South Central US" - vm_size = "Standard_D4ps_v5" - ssh_username = "packer" + use_azure_cli_auth = true + location = "South Central US" + vm_size = "Standard_D4ps_v5" + ssh_username = "packer" ssh_private_key_file = var.ssh_private_key_location - communicator = "ssh" - shared_image_gallery{ + communicator = "ssh" + shared_image_gallery { subscription = var.subscription image_name = "arm-linux-specialized-sig" gallery_name = "acctestgallery" @@ -28,11 +28,12 @@ source "azure-arm" "linux-sig" { resource_group = "packer-acceptance-test" } shared_image_gallery_destination { - image_name = "arm-linux-specialized-sig" - gallery_name = "acctestgallery" - image_version = "1.0.1" - resource_group = "packer-acceptance-test" - specialized = true + image_name = "arm-linux-specialized-sig" + gallery_name = "acctestgallery" + image_version = "1.0.1" + resource_group = "packer-acceptance-test" + specialized = true + shallow_replication = true } os_type = "Linux"