Initial changes to support Shared Image Gallery
This commit is contained in:
parent
b7b1720a91
commit
55be0da5da
|
@ -80,6 +80,12 @@ type Config struct {
|
|||
CaptureContainerName string `mapstructure:"capture_container_name"`
|
||||
|
||||
// Compute
|
||||
ImageGallerySubscription string `mapstructure:"image_gallery_subscription"`
|
||||
ImageGalleryResourceGroup string `mapstructure:"image_gallery_resource_group"`
|
||||
ImageGalleryName string `mapstructure:"image_gallery_name"`
|
||||
ImageGalleryImageName string `mapstructure:"image_gallery_image_name"`
|
||||
ImageGalleryImageVersion string `mapstructure:"image_gallery_image_version"`
|
||||
|
||||
ImagePublisher string `mapstructure:"image_publisher"`
|
||||
ImageOffer string `mapstructure:"image_offer"`
|
||||
ImageSku string `mapstructure:"image_sku"`
|
||||
|
@ -584,6 +590,10 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) {
|
|||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("A managed image must be created from a managed image, it cannot be created from a VHD."))
|
||||
}
|
||||
|
||||
if c.ImageGalleryName != "" {
|
||||
fmt.Println("Skipping checks for shared image gallery")
|
||||
return
|
||||
}
|
||||
if c.ImageUrl == "" && c.CustomManagedImageName == "" {
|
||||
if c.ImagePublisher == "" {
|
||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("An image_publisher must be specified"))
|
||||
|
|
|
@ -72,6 +72,18 @@ func GetVirtualMachineDeployment(config *Config) (*resources.Deployment, error)
|
|||
config.ImageVersion)
|
||||
|
||||
builder.SetManagedMarketplaceImage(config.Location, config.ImagePublisher, config.ImageOffer, config.ImageSku, config.ImageVersion, imageID, config.managedImageStorageAccountType)
|
||||
} else if config.ImageGallerySubscription != "" && config.ImageGalleryResourceGroup != "" && config.ImageGalleryName != "" && config.ImageGalleryImageName != "" {
|
||||
imageID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/galleries/%s/images/%s",
|
||||
config.ImageGallerySubscription,
|
||||
config.ImageGalleryResourceGroup,
|
||||
config.ImageGalleryName,
|
||||
config.ImageGalleryImageName)
|
||||
if config.ImageGalleryImageVersion != "" {
|
||||
imageID += fmt.Sprintf("/versions/%s",
|
||||
config.ImageGalleryImageVersion)
|
||||
}
|
||||
|
||||
builder.SetSharedGalleryImage(config.Location, imageID)
|
||||
} else {
|
||||
builder.SetMarketPlaceImage(config.ImagePublisher, config.ImageOffer, config.ImageSku, config.ImageVersion)
|
||||
}
|
||||
|
|
|
@ -145,6 +145,25 @@ func (s *TemplateBuilder) SetManagedMarketplaceImage(location, publisher, offer,
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *TemplateBuilder) SetSharedGalleryImage(location, imageID string) error {
|
||||
resource, err := s.getResourceByType(resourceVirtualMachine)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
profile := resource.Properties.StorageProfile
|
||||
profile.ImageReference = &compute.ImageReference{
|
||||
ID: &imageID}
|
||||
profile.OsDisk.OsType = s.osType
|
||||
// profile.OsDisk.CreateOption = compute.DiskCreateOptionTypesFromImage
|
||||
profile.OsDisk.Vhd = nil
|
||||
// profile.OsDisk.ManagedDisk = &compute.ManagedDiskParameters{
|
||||
// StorageAccountType: storageAccountType,
|
||||
//}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *TemplateBuilder) SetMarketPlaceImage(publisher, offer, sku, version string) error {
|
||||
resource, err := s.getResourceByType(resourceVirtualMachine)
|
||||
if err != nil {
|
||||
|
@ -486,7 +505,7 @@ const BasicTemplate = `{
|
|||
},
|
||||
"variables": {
|
||||
"addressPrefix": "10.0.0.0/16",
|
||||
"apiVersion": "2017-03-30",
|
||||
"apiVersion": "2018-04-01",
|
||||
"managedDiskApiVersion": "2017-03-30",
|
||||
"networkInterfacesApiVersion": "2017-04-01",
|
||||
"publicIPAddressApiVersion": "2017-04-01",
|
||||
|
|
Loading…
Reference in New Issue