diff --git a/builder/azure/arm/builder.go b/builder/azure/arm/builder.go index d399524a1..ef92f4cbc 100644 --- a/builder/azure/arm/builder.go +++ b/builder/azure/arm/builder.go @@ -90,17 +90,17 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe } if b.config.isManagedImage() { - group, err := azureClient.GroupsClient.Get(b.config.TargetManagedImageResourceGroupName) + group, err := azureClient.GroupsClient.Get(b.config.ManagedImageResourceGroupName) if err != nil { - return nil, fmt.Errorf("Cannot locate the managed image resource group %s.", b.config.TargetManagedImageResourceGroupName) + return nil, fmt.Errorf("Cannot locate the managed image resource group %s.", b.config.ManagedImageResourceGroupName) } - b.config.targetManageImageLocation = *group.Location + b.config.manageImageLocation = *group.Location // If a managed image already exists it cannot be overwritten. - _, err = azureClient.ImagesClient.Get(b.config.TargetManagedImageResourceGroupName, b.config.TargetManagedImageName, "") + _, err = azureClient.ImagesClient.Get(b.config.ManagedImageResourceGroupName, b.config.ManagedImageName, "") if err == nil { - return nil, fmt.Errorf("A managed image named %s already exists in the resource group %s.", b.config.TargetManagedImageName, b.config.TargetManagedImageResourceGroupName) + return nil, fmt.Errorf("A managed image named %s already exists in the resource group %s.", b.config.ManagedImageName, b.config.ManagedImageResourceGroupName) } } @@ -254,13 +254,13 @@ func (b *Builder) configureStateBag(stateBag multistep.StateBag) { stateBag.Put(constants.ArmStorageAccountName, b.config.StorageAccount) stateBag.Put(constants.ArmIsManagedImage, b.config.isManagedImage()) - stateBag.Put(constants.ArmTargetManagedImageResourceGroupName, b.config.TargetManagedImageResourceGroupName) - stateBag.Put(constants.ArmTargetManagedImageName, b.config.TargetManagedImageName) + stateBag.Put(constants.ArmManagedImageResourceGroupName, b.config.ManagedImageResourceGroupName) + stateBag.Put(constants.ArmManagedImageName, b.config.ManagedImageName) } // Parameters that are only known at runtime after querying Azure. func (b *Builder) setRuntimeParameters(stateBag multistep.StateBag) { - stateBag.Put(constants.ArmTargetManagedImageLocation, b.config.targetManageImageLocation) + stateBag.Put(constants.ArmManagedImageLocation, b.config.manageImageLocation) } func (b *Builder) setTemplateParameters(stateBag multistep.StateBag) { diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 6366da0d1..0f42f6511 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -66,18 +66,18 @@ type Config struct { ImageVersion string `mapstructure:"image_version"` ImageUrl string `mapstructure:"image_url"` - ManagedImageResourceGroupName string `mapstructure:"managed_image_resource_group_name"` - ManagedImageName string `mapstructure:"managed_image_name"` - managedImageLocation string - managedImageBlobUri string - managedImageOSState compute.OperatingSystemStateTypes + CustomManagedImageResourceGroupName string `mapstructure:"custom_managed_image_resource_group_name"` + CustomManagedImageName string `mapstructure:"custom_managed_image_name"` + customManagedImageLocation string + customManagedImageBlobUri string + customManagedImageOSState compute.OperatingSystemStateTypes Location string `mapstructure:"location"` VMSize string `mapstructure:"vm_size"` - TargetManagedImageResourceGroupName string `mapstructure:"target_managed_image_resource_group_name"` - TargetManagedImageName string `mapstructure:"target_managed_image_name"` - targetManageImageLocation string + ManagedImageResourceGroupName string `mapstructure:"managed_image_resource_group_name"` + ManagedImageName string `mapstructure:"managed_image_name"` + manageImageLocation string // Deployment AzureTags map[string]*string `mapstructure:"azure_tags"` @@ -134,7 +134,7 @@ func (c *Config) toVMID() string { } func (c *Config) isManagedImage() bool { - return c.TargetManagedImageName != "" + return c.ManagedImageName != "" } func (c *Config) toVirtualMachineCaptureParameters() *compute.VirtualMachineCaptureParameters { @@ -501,35 +501,33 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) { ///////////////////////////////////////////// // Compute if c.ImageUrl != "" && - (c.ManagedImageName != "" || c.ManagedImageResourceGroupName != "") && + (c.CustomManagedImageName != "" || c.CustomManagedImageResourceGroupName != "") && (c.ImagePublisher != "" || c.ImageOffer != "" || c.ImageSku != "") { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("Specify either a VHD (image_url), Image Reference (image_publisher, image_offer, image_sku) or a Managed Disk (managed_disk_image_name, managed_disk_resource_group_name")) + errs = packer.MultiErrorAppend(errs, fmt.Errorf("Specify either a VHD (image_url), Image Reference (image_publisher, image_offer, image_sku) or a Managed Disk (custom_managed_disk_image_name, custom_managed_disk_resource_group_name")) } - if c.ImageUrl == "" && c.ManagedImageName == "" { + if c.ImageUrl == "" && c.CustomManagedImageName == "" { if c.ImagePublisher == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("An image_publisher must be specified")) } - if c.ImageOffer == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("An image_offer must be specified")) } - if c.ImageSku == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("An image_sku must be specified")) } } else if c.ImageUrl == "" && c.ImagePublisher == "" { - if c.ManagedImageName == "" { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("A managed_image_name must be specified")) + if c.CustomManagedImageResourceGroupName == "" { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("An custom_managed_image_resource_group_name must be specified")) + } + if c.CustomManagedImageName == "" { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("A custom_managed_image_name must be specified")) } if c.ManagedImageResourceGroupName == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("An managed_image_resource_group_name must be specified")) } - if c.TargetManagedImageName == "" { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("An target_managed_image_name must be specified")) - } - if c.TargetManagedImageResourceGroupName == "" { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("An target_managed_image_resource_group_name must be specified")) + if c.ManagedImageName == "" { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("An managed_image_name must be specified")) } } else { if c.ImagePublisher != "" || c.ImageOffer != "" || c.ImageSku != "" || c.ImageVersion != "" { diff --git a/builder/azure/arm/resource_resolver.go b/builder/azure/arm/resource_resolver.go index 632573730..ceaa7d746 100644 --- a/builder/azure/arm/resource_resolver.go +++ b/builder/azure/arm/resource_resolver.go @@ -45,14 +45,14 @@ func (s *resourceResolver) Resolve(c *Config) error { } if s.shouldResolveManagedImageName(c) { - image, err := findManagedImageByName(s.client, c.ManagedImageName, c.ManagedImageResourceGroupName) + image, err := findManagedImageByName(s.client, c.CustomManagedImageName, c.CustomManagedImageResourceGroupName) if err != nil { return err } - c.managedImageBlobUri = *image.ImageProperties.StorageProfile.OsDisk.BlobURI - c.managedImageLocation = *image.Location - c.managedImageOSState = image.ImageProperties.StorageProfile.OsDisk.OsState + c.customManagedImageBlobUri = *image.ImageProperties.StorageProfile.OsDisk.BlobURI + c.customManagedImageLocation = *image.Location + c.customManagedImageOSState = image.ImageProperties.StorageProfile.OsDisk.OsState } return nil @@ -63,7 +63,7 @@ func (s *resourceResolver) shouldResolveResourceGroup(c *Config) bool { } func (s *resourceResolver) shouldResolveManagedImageName(c *Config) bool { - return c.ManagedImageName != "" + return c.CustomManagedImageName != "" } func getResourceGroupNameFromId(id string) string { diff --git a/builder/azure/arm/step_capture_image.go b/builder/azure/arm/step_capture_image.go index 09dd93354..d3f26c5de 100644 --- a/builder/azure/arm/step_capture_image.go +++ b/builder/azure/arm/step_capture_image.go @@ -69,9 +69,9 @@ func (s *StepCaptureImage) Run(state multistep.StateBag) multistep.StepAction { var imageParameters = state.Get(constants.ArmImageParameters).(*compute.Image) var isManagedImage = state.Get(constants.ArmIsManagedImage).(bool) - var targetManagedImageResourceGroupName = state.Get(constants.ArmTargetManagedImageResourceGroupName).(string) - var targetManagedImageName = state.Get(constants.ArmTargetManagedImageName).(string) - var targetManagedImageLocation = state.Get(constants.ArmTargetManagedImageLocation).(string) + var targetManagedImageResourceGroupName = state.Get(constants.ArmManagedImageResourceGroupName).(string) + var targetManagedImageName = state.Get(constants.ArmManagedImageName).(string) + var targetManagedImageLocation = state.Get(constants.ArmManagedImageLocation).(string) s.say(fmt.Sprintf(" -> Compute ResourceGroupName : '%s'", resourceGroupName)) s.say(fmt.Sprintf(" -> Compute Name : '%s'", computeName)) diff --git a/builder/azure/arm/step_capture_image_test.go b/builder/azure/arm/step_capture_image_test.go index 604cb257e..24bba776e 100644 --- a/builder/azure/arm/step_capture_image_test.go +++ b/builder/azure/arm/step_capture_image_test.go @@ -131,9 +131,9 @@ func createTestStateBagStepCaptureImage() multistep.StateBag { stateBag.Put(constants.ArmVirtualMachineCaptureParameters, &compute.VirtualMachineCaptureParameters{}) stateBag.Put(constants.ArmIsManagedImage, false) - stateBag.Put(constants.ArmTargetManagedImageResourceGroupName, "") - stateBag.Put(constants.ArmTargetManagedImageName, "") - stateBag.Put(constants.ArmTargetManagedImageLocation, "") + stateBag.Put(constants.ArmManagedImageResourceGroupName, "") + stateBag.Put(constants.ArmManagedImageName, "") + stateBag.Put(constants.ArmManagedImageLocation, "") stateBag.Put(constants.ArmImageParameters, &compute.Image{}) return stateBag diff --git a/builder/azure/arm/template_factory.go b/builder/azure/arm/template_factory.go index 73585c249..034f41dfd 100644 --- a/builder/azure/arm/template_factory.go +++ b/builder/azure/arm/template_factory.go @@ -52,9 +52,9 @@ func GetVirtualMachineDeployment(config *Config) (*resources.Deployment, error) if config.ImageUrl != "" { builder.SetImageUrl(config.ImageUrl, osType) - } else if config.ManagedImageName != "" { - builder.SetManagedDiskUrl(config.ManagedImageName, config.managedImageLocation, config.managedImageBlobUri, config.managedImageOSState) - } else if config.TargetManagedImageName != "" && config.ImagePublisher != "" { + } else if config.CustomManagedImageName != "" { + builder.SetManagedDiskUrl(config.CustomManagedImageName, config.customManagedImageLocation, config.customManagedImageBlobUri, config.customManagedImageOSState) + } else if config.ManagedImageName != "" && config.ImagePublisher != "" { imageID := fmt.Sprintf("/subscriptions/%s/providers/Microsoft.Compute/locations/%s/publishers/%s/ArtifactTypes/vmimage/offers/%s/skus/%s/versions/%s", config.SubscriptionID, config.Location, diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json index 9fc61b614..4370b37f1 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment08.approved.json @@ -88,7 +88,7 @@ "apiVersion": "[variables('apiVersion')]", "dependsOn": [ "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]", - "[concat('Microsoft.Compute/images/', 'ManagedImageName')]" + "[concat('Microsoft.Compute/images/', 'CustomManagedImageName')]" ], "location": "[variables('location')]", "name": "[parameters('vmName')]", @@ -125,7 +125,7 @@ }, "storageProfile": { "imageReference": { - "id": "[resourceId(resourceGroup().name, 'Microsoft.Compute/images', 'ManagedImageName')]" + "id": "[resourceId(resourceGroup().name, 'Microsoft.Compute/images', 'CustomManagedImageName')]" }, "osDisk": { "caching": "ReadWrite", @@ -139,7 +139,7 @@ { "apiVersion": "[variables('managedDiskApiVersion')]", "location": "", - "name": "ManagedImageName", + "name": "CustomManagedImageName", "properties": { "storageProfile": { "osDisk": { diff --git a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json index d99858702..03a00fa32 100644 --- a/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json +++ b/builder/azure/arm/template_factory_test.TestVirtualMachineDeployment09.approved.json @@ -124,9 +124,9 @@ }, "storageProfile": { "imageReference": { - "offer": "UbuntuServer", - "publisher": "Canonical", - "sku": "16.04-LTS", + "offer": "--image-offer--", + "publisher": "--image-publisher--", + "sku": "--image-sku--", "version": "--version--" }, "osDisk": { diff --git a/builder/azure/arm/template_factory_test.go b/builder/azure/arm/template_factory_test.go index 315123ad5..0301b1012 100644 --- a/builder/azure/arm/template_factory_test.go +++ b/builder/azure/arm/template_factory_test.go @@ -269,10 +269,10 @@ func TestVirtualMachineDeployment08(t *testing.T) { "subscription_id": "ignore", "os_type": constants.Target_Linux, "communicator": "none", + "custom_managed_image_resource_group_name": "CustomManagedImageResourceGroupName", + "custom_managed_image_name": "CustomManagedImageName", "managed_image_name": "ManagedImageName", "managed_image_resource_group_name": "ManagedImageResourceGroupName", - "target_managed_image_name": "TargetManagedImageName", - "target_managed_image_resource_group_name": "TargetManagedImageResourceGroupName", } c, _, err := newConfig(config, getPackerConfiguration()) @@ -294,20 +294,20 @@ func TestVirtualMachineDeployment08(t *testing.T) { // Ensure the VM template is correct when building from a platform managed image. func TestVirtualMachineDeployment09(t *testing.T) { config := map[string]interface{}{ - "capture_name_prefix": "ignore", - "capture_container_name": "ignore", - "location": "ignore", - "resource_group_name": "ignore", - "storage_account": "ignore", - "subscription_id": "ignore", - "os_type": constants.Target_Linux, - "communicator": "none", - "image_publisher": "Canonical", - "image_offer": "UbuntuServer", - "image_sku": "16.04-LTS", - "image_version": "--version--", - "target_managed_image_name": "TargetManagedImageName", - "target_managed_image_resource_group_name": "TargetManagedImageResourceGroupName", + "capture_name_prefix": "ignore", + "capture_container_name": "ignore", + "location": "ignore", + "resource_group_name": "ignore", + "storage_account": "ignore", + "subscription_id": "ignore", + "os_type": constants.Target_Linux, + "communicator": "none", + "image_publisher": "--image-publisher--", + "image_offer": "--image-offer--", + "image_sku": "--image-sku--", + "image_version": "--version--", + "managed_image_name": "ManagedImageName", + "managed_image_resource_group_name": "ManagedImageResourceGroupName", } c, _, err := newConfig(config, getPackerConfiguration()) diff --git a/builder/azure/common/constants/stateBag.go b/builder/azure/common/constants/stateBag.go index 9fa8fbfab..b1289547f 100644 --- a/builder/azure/common/constants/stateBag.go +++ b/builder/azure/common/constants/stateBag.go @@ -30,8 +30,8 @@ const ( ArmTags string = "arm.Tags" ArmVirtualMachineCaptureParameters string = "arm.VirtualMachineCaptureParameters" - ArmIsManagedImage string = "arm.IsManagedImage" - ArmTargetManagedImageResourceGroupName string = "arm.TargetManagedImageResourceGroupName" - ArmTargetManagedImageLocation string = "arm.TargetManagedImageLocation" - ArmTargetManagedImageName string = "arm.TargetManagedImageName" + ArmIsManagedImage string = "arm.IsManagedImage" + ArmManagedImageResourceGroupName string = "arm.ManagedImageResourceGroupName" + ArmManagedImageLocation string = "arm.ManagedImageLocation" + ArmManagedImageName string = "arm.ManagedImageName" )