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

Add Specialized Field for Shared Image Gallery Destination #295

Merged
merged 7 commits into from
Apr 28, 2023

Conversation

JenGoldstrich
Copy link
Contributor

@JenGoldstrich JenGoldstrich commented Apr 20, 2023

Adds specialized option to Shared Image Gallery Destination block, the plugin has previously always called Generalize which tells Azure to set the build virtual machine state to Generalized. Azure does not allow capturing Specialized VMs into managed images, so I've limited this to direct publish to Shared Image Gallery/Compute Gallery

https://learn.microsoft.com/en-us/azure/virtual-machines/vm-specialized-image-version

Closes #262

Example HCL template:

source "azure-arm" "autogenerated_1" {
  communicator    = "winrm"
  image_offer     = "WindowsServer"
  image_publisher = "MicrosoftWindowsServer"
  image_sku       = "2012-R2-Datacenter"
  location        = "South Central US"
  os_type         = "Windows"
  use_azure_cli_auth   = "true"
  vm_size         = "Standard_DS2_v2"
  winrm_insecure  = "true"
  winrm_timeout   = "3m"
  winrm_use_ssl   = "true"
  winrm_username  = "packer"
  shared_image_gallery_destination  {
    gallery_name        = "jennaspecialized"
    image_name          = "jenna"
    image_version       = "1.1.1"
    resource_group      = "jenna"
    specialized = "true"
  }
}

build {
  sources = ["source.azure-arm.autogenerated_1"]
}

@JenGoldstrich JenGoldstrich force-pushed the specialize-sig branch 2 times, most recently from 395ec52 to f839fe0 Compare April 21, 2023 21:26
@JenGoldstrich JenGoldstrich marked this pull request as ready for review April 21, 2023 22:29
@JenGoldstrich JenGoldstrich requested a review from a team as a code owner April 21, 2023 22:29
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

This looks good. Nicely done. One suggestion and one question. But otherwise good. Approving so you can merge when ready.

@@ -106,6 +106,8 @@ type SharedImageGalleryDestination struct {
// Specify a storage account type for the Shared Image Gallery Image Version.
// Defaults to `Standard_LRS`. Accepted values are `Standard_LRS`, `Standard_ZRS` and `Premium_LRS`
SigDestinationStorageAccountType string `mapstructure:"storage_account_type"`
// Set to true if publishing to a Specialized Gallery, this skips a call to set the resulting VM's OS state as Generalized
SigDestinationSkipGeneralization bool `mapstructure:"skip_generalization"`
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about calling this attribute specialized to match the Azure CLI flag?

The behavior is the same as it is written the only change is the name of the configuration attribute.

Suggested change
SigDestinationSkipGeneralization bool `mapstructure:"skip_generalization"`
SigDestinationSkipGeneralization bool `mapstructure:"specialized"`

if c.SecureBootEnabled || c.VTpmEnabled {
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("A managed image (managed_image_name, managed_image_resource_group_name) can not set SecureBoot or VTpm, these features are only supported when directly publishing to a Shared Image Gallery"))
}
if c.SharedGalleryDestination.SigDestinationSkipGeneralization {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIce 👍

builder/azure/arm/config_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

LGTM

@JenGoldstrich JenGoldstrich changed the title Allow skipping OS generalization for direct publish to Compute Gallery images Add Specialized Field for Shared Image Gallery Destination Apr 28, 2023
@JenGoldstrich JenGoldstrich merged commit d9c0baf into main Apr 28, 2023
@JenGoldstrich JenGoldstrich deleted the specialize-sig branch April 28, 2023 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"shared_image_gallery_destination" should be able to process specialized images
2 participants