azure: Fix custom managed images
I missed a change in my SDK update, and when I integrated this missing change I broke custom images.
This commit is contained in:
parent
1874514e4f
commit
0d427939bc
|
@ -68,9 +68,7 @@ type Config struct {
|
|||
|
||||
CustomManagedImageResourceGroupName string `mapstructure:"custom_managed_image_resource_group_name"`
|
||||
CustomManagedImageName string `mapstructure:"custom_managed_image_name"`
|
||||
customManagedImageLocation string
|
||||
customManagedImageBlobUri string
|
||||
customManagedImageOSState compute.OperatingSystemStateTypes
|
||||
customManagedImageID string
|
||||
|
||||
Location string `mapstructure:"location"`
|
||||
VMSize string `mapstructure:"vm_size"`
|
||||
|
|
|
@ -50,9 +50,7 @@ func (s *resourceResolver) Resolve(c *Config) error {
|
|||
return err
|
||||
}
|
||||
|
||||
c.customManagedImageBlobUri = *image.ImageProperties.StorageProfile.OsDisk.BlobURI
|
||||
c.customManagedImageLocation = *image.Location
|
||||
c.customManagedImageOSState = image.ImageProperties.StorageProfile.OsDisk.OsState
|
||||
c.customManagedImageID = *image.ID
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -53,7 +53,7 @@ func GetVirtualMachineDeployment(config *Config) (*resources.Deployment, error)
|
|||
if config.ImageUrl != "" {
|
||||
builder.SetImageUrl(config.ImageUrl, osType)
|
||||
} else if config.CustomManagedImageName != "" {
|
||||
builder.SetManagedDiskUrl(config.CustomManagedImageName, config.customManagedImageLocation, config.customManagedImageBlobUri, config.customManagedImageOSState)
|
||||
builder.SetManagedDiskUrl(config.customManagedImageID)
|
||||
} 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,
|
||||
|
|
|
@ -87,8 +87,7 @@
|
|||
{
|
||||
"apiVersion": "[variables('apiVersion')]",
|
||||
"dependsOn": [
|
||||
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]",
|
||||
"[concat('Microsoft.Compute/images/', 'CustomManagedImageName')]"
|
||||
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
|
||||
],
|
||||
"location": "[variables('location')]",
|
||||
"name": "[parameters('vmName')]",
|
||||
|
@ -125,30 +124,17 @@
|
|||
},
|
||||
"storageProfile": {
|
||||
"imageReference": {
|
||||
"id": "[resourceId(resourceGroup().name, 'Microsoft.Compute/images', 'CustomManagedImageName')]"
|
||||
"id": ""
|
||||
},
|
||||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"name": "osdisk"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "Microsoft.Compute/virtualMachines"
|
||||
},
|
||||
{
|
||||
"apiVersion": "[variables('managedDiskApiVersion')]",
|
||||
"location": "",
|
||||
"name": "CustomManagedImageName",
|
||||
"properties": {
|
||||
"storageProfile": {
|
||||
"osDisk": {
|
||||
"blobUri": "",
|
||||
"createOption": "fromImage",
|
||||
"name": "osdisk",
|
||||
"osType": "Linux"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "Microsoft.Compute/images"
|
||||
"type": "Microsoft.Compute/virtualMachines"
|
||||
}
|
||||
],
|
||||
"variables": {
|
||||
|
|
|
@ -101,38 +101,21 @@ func (s *TemplateBuilder) BuildWindows(keyVaultName, winRMCertificateUrl string)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *TemplateBuilder) SetManagedDiskUrl(managedDiskImageName, location, blobUri string, osState compute.OperatingSystemStateTypes) error {
|
||||
func (s *TemplateBuilder) SetManagedDiskUrl(managedImageId string) error {
|
||||
resource, err := s.getResourceByType(resourceVirtualMachine)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resourceId := s.toResourceID(resourceManagedDisk, managedDiskImageName)
|
||||
profile := resource.Properties.StorageProfile
|
||||
profile.ImageReference = &compute.ImageReference{
|
||||
ID: to.StringPtr(resourceId),
|
||||
ID: &managedImageId,
|
||||
}
|
||||
profile.OsDisk.Name = to.StringPtr("osdisk")
|
||||
profile.OsDisk.OsType = s.osType
|
||||
profile.OsDisk.CreateOption = compute.FromImage
|
||||
profile.OsDisk.Vhd = nil
|
||||
|
||||
*resource.DependsOn = append(*resource.DependsOn, fmt.Sprintf("[concat('%s/', '%s')]", resourceManagedDisk, managedDiskImageName))
|
||||
|
||||
managedDiskResource := &Resource{
|
||||
Type: to.StringPtr(resourceManagedDisk),
|
||||
ApiVersion: to.StringPtr(s.toVariable("managedDiskApiVersion")),
|
||||
Name: to.StringPtr(managedDiskImageName),
|
||||
Location: to.StringPtr(location),
|
||||
Properties: &Properties{
|
||||
StorageProfile: &StorageProfileUnion{
|
||||
OsDisk: &OSDiskUnion{
|
||||
OsType: s.osType,
|
||||
OsState: osState,
|
||||
BlobURI: to.StringPtr(blobUri),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
*s.template.Resources = append(*s.template.Resources, *managedDiskResource)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue