Use separate caching/sku for data disks
This commit is contained in:
parent
f601f54d0b
commit
ac3d19ee23
@ -88,6 +88,14 @@ type Config struct {
|
|||||||
// The [cache type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#cachingtypes)
|
// The [cache type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#cachingtypes)
|
||||||
// specified in the resulting image and for attaching it to the Packer VM. Defaults to `ReadOnly`
|
// specified in the resulting image and for attaching it to the Packer VM. Defaults to `ReadOnly`
|
||||||
OSDiskCacheType string `mapstructure:"os_disk_cache_type"`
|
OSDiskCacheType string `mapstructure:"os_disk_cache_type"`
|
||||||
|
|
||||||
|
// The [storage SKU](https://docs.microsoft.com/en-us/rest/api/compute/disks/createorupdate#diskstorageaccounttypes)
|
||||||
|
// to use for datadisks. Defaults to `Standard_LRS`.
|
||||||
|
DataDiskStorageAccountType string `mapstructure:"data_disk_storage_account_type"`
|
||||||
|
// The [cache type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#cachingtypes)
|
||||||
|
// specified in the resulting image and for attaching it to the Packer VM. Defaults to `ReadOnly`
|
||||||
|
DataDiskCacheType string `mapstructure:"data_disk_cache_type"`
|
||||||
|
|
||||||
// The [Hyper-V generation type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes) for Managed Image output.
|
// The [Hyper-V generation type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes) for Managed Image output.
|
||||||
// Defaults to `V1`.
|
// Defaults to `V1`.
|
||||||
ImageHyperVGeneration string `mapstructure:"image_hyperv_generation"`
|
ImageHyperVGeneration string `mapstructure:"image_hyperv_generation"`
|
||||||
@ -253,6 +261,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
|||||||
b.config.OSDiskCacheType = string(compute.CachingTypesReadOnly)
|
b.config.OSDiskCacheType = string(compute.CachingTypesReadOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.DataDiskStorageAccountType == "" {
|
||||||
|
b.config.DataDiskStorageAccountType = string(compute.PremiumLRS)
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.config.DataDiskCacheType == "" {
|
||||||
|
b.config.DataDiskCacheType = string(compute.CachingTypesReadOnly)
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.ImageHyperVGeneration == "" {
|
if b.config.ImageHyperVGeneration == "" {
|
||||||
b.config.ImageHyperVGeneration = string(compute.V1)
|
b.config.ImageHyperVGeneration = string(compute.V1)
|
||||||
}
|
}
|
||||||
@ -300,6 +316,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
|||||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("os_disk_storage_account_type: %v", err))
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("os_disk_storage_account_type: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := checkDiskCacheType(b.config.DataDiskCacheType); err != nil {
|
||||||
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("data_disk_cache_type: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := checkStorageAccountType(b.config.DataDiskStorageAccountType); err != nil {
|
||||||
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("data_disk_storage_account_type: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.ImageResourceID != "" {
|
if b.config.ImageResourceID != "" {
|
||||||
r, err := azure.ParseResourceID(b.config.ImageResourceID)
|
r, err := azure.ParseResourceID(b.config.ImageResourceID)
|
||||||
if err != nil ||
|
if err != nil ||
|
||||||
@ -527,6 +551,8 @@ func buildsteps(config Config, info *client.ComputeInfo) []multistep.Step {
|
|||||||
&StepCreateNewDiskset{
|
&StepCreateNewDiskset{
|
||||||
OSDiskID: config.TemporaryOSDiskID,
|
OSDiskID: config.TemporaryOSDiskID,
|
||||||
OSDiskSizeGB: config.OSDiskSizeGB,
|
OSDiskSizeGB: config.OSDiskSizeGB,
|
||||||
|
OSDiskStorageAccountType: config.OSDiskStorageAccountType,
|
||||||
|
DataDiskStorageAccountType: config.DataDiskStorageAccountType,
|
||||||
SourceImageResourceID: config.Source,
|
SourceImageResourceID: config.Source,
|
||||||
Location: info.Location,
|
Location: info.Location,
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ type StepCreateNewDiskset struct {
|
|||||||
OSDiskID string // Disk ID
|
OSDiskID string // Disk ID
|
||||||
OSDiskSizeGB int32 // optional, ignored if 0
|
OSDiskSizeGB int32 // optional, ignored if 0
|
||||||
OSDiskStorageAccountType string // from compute.DiskStorageAccountTypes
|
OSDiskStorageAccountType string // from compute.DiskStorageAccountTypes
|
||||||
|
DataDiskStorageAccountType string // from compute.DiskStorageAccountTypes
|
||||||
|
|
||||||
DataDiskIDPrefix string
|
DataDiskIDPrefix string
|
||||||
|
|
||||||
@ -205,9 +206,9 @@ func (s StepCreateNewDiskset) getDatadiskDefinitionFromImage(lun int32) compute.
|
|||||||
Lun: to.Int32Ptr(lun),
|
Lun: to.Int32Ptr(lun),
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.OSDiskStorageAccountType != "" {
|
if s.DataDiskStorageAccountType != "" {
|
||||||
disk.Sku = &compute.DiskSku{
|
disk.Sku = &compute.DiskSku{
|
||||||
Name: compute.DiskStorageAccountTypes(s.OSDiskStorageAccountType),
|
Name: compute.DiskStorageAccountTypes(s.DataDiskStorageAccountType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return disk
|
return disk
|
||||||
|
@ -93,6 +93,7 @@ func TestStepCreateNewDisk_Run(t *testing.T) {
|
|||||||
fields: StepCreateNewDiskset{
|
fields: StepCreateNewDiskset{
|
||||||
OSDiskID: "/subscriptions/SubscriptionID/resourcegroups/ResourceGroupName/providers/Microsoft.Compute/disks/TemporaryOSDiskName",
|
OSDiskID: "/subscriptions/SubscriptionID/resourcegroups/ResourceGroupName/providers/Microsoft.Compute/disks/TemporaryOSDiskName",
|
||||||
OSDiskStorageAccountType: string(compute.StandardLRS),
|
OSDiskStorageAccountType: string(compute.StandardLRS),
|
||||||
|
DataDiskStorageAccountType: string(compute.PremiumLRS),
|
||||||
DataDiskIDPrefix: "/subscriptions/SubscriptionID/resourcegroups/ResourceGroupName/providers/Microsoft.Compute/disks/TemporaryDataDisk-",
|
DataDiskIDPrefix: "/subscriptions/SubscriptionID/resourcegroups/ResourceGroupName/providers/Microsoft.Compute/disks/TemporaryDataDisk-",
|
||||||
HyperVGeneration: string(compute.V1),
|
HyperVGeneration: string(compute.V1),
|
||||||
Location: "westus",
|
Location: "westus",
|
||||||
@ -128,7 +129,7 @@ func TestStepCreateNewDisk_Run(t *testing.T) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sku": {
|
"sku": {
|
||||||
"name": "Standard_LRS"
|
"name": "Premium_LRS"
|
||||||
}
|
}
|
||||||
}`, `
|
}`, `
|
||||||
{
|
{
|
||||||
@ -143,7 +144,7 @@ func TestStepCreateNewDisk_Run(t *testing.T) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sku": {
|
"sku": {
|
||||||
"name": "Standard_LRS"
|
"name": "Premium_LRS"
|
||||||
}
|
}
|
||||||
}`, `
|
}`, `
|
||||||
{
|
{
|
||||||
@ -158,7 +159,7 @@ func TestStepCreateNewDisk_Run(t *testing.T) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sku": {
|
"sku": {
|
||||||
"name": "Standard_LRS"
|
"name": "Premium_LRS"
|
||||||
}
|
}
|
||||||
}`},
|
}`},
|
||||||
want: multistep.ActionContinue,
|
want: multistep.ActionContinue,
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
type StepCreateSharedImageVersion struct {
|
type StepCreateSharedImageVersion struct {
|
||||||
Destination SharedImageGalleryDestination
|
Destination SharedImageGalleryDestination
|
||||||
OSDiskCacheType string
|
OSDiskCacheType string
|
||||||
|
DataDiskCacheType string
|
||||||
Location string
|
Location string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ func (s *StepCreateSharedImageVersion) Run(ctx context.Context, state multistep.
|
|||||||
datadisks = append(datadisks, compute.GalleryDataDiskImage{
|
datadisks = append(datadisks, compute.GalleryDataDiskImage{
|
||||||
Lun: to.Int32Ptr(lun),
|
Lun: to.Int32Ptr(lun),
|
||||||
Source: &compute.GalleryArtifactVersionSource{ID: to.StringPtr(resource.String())},
|
Source: &compute.GalleryArtifactVersionSource{ID: to.StringPtr(resource.String())},
|
||||||
|
HostCaching: compute.HostCaching(s.DataDiskCacheType),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ func TestStepCreateSharedImageVersion_Run(t *testing.T) {
|
|||||||
type fields struct {
|
type fields struct {
|
||||||
Destination SharedImageGalleryDestination
|
Destination SharedImageGalleryDestination
|
||||||
OSDiskCacheType string
|
OSDiskCacheType string
|
||||||
|
DataDiskCacheType string
|
||||||
Location string
|
Location string
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -46,6 +47,8 @@ func TestStepCreateSharedImageVersion_Run(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ExcludeFromLatest: true,
|
ExcludeFromLatest: true,
|
||||||
},
|
},
|
||||||
|
OSDiskCacheType: "ReadWrite",
|
||||||
|
DataDiskCacheType: "None",
|
||||||
Location: "region2",
|
Location: "region2",
|
||||||
},
|
},
|
||||||
snapshotset: diskset(
|
snapshotset: diskset(
|
||||||
@ -68,6 +71,7 @@ func TestStepCreateSharedImageVersion_Run(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"storageProfile": {
|
"storageProfile": {
|
||||||
"osDiskImage": {
|
"osDiskImage": {
|
||||||
|
"hostCaching": "ReadWrite",
|
||||||
"source": {
|
"source": {
|
||||||
"id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/osdisksnapshot"
|
"id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/osdisksnapshot"
|
||||||
}
|
}
|
||||||
@ -75,15 +79,24 @@ func TestStepCreateSharedImageVersion_Run(t *testing.T) {
|
|||||||
"dataDiskImages": [
|
"dataDiskImages": [
|
||||||
{
|
{
|
||||||
"lun": 0,
|
"lun": 0,
|
||||||
"source": { "id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/datadisksnapshot0" }
|
"hostCaching": "None",
|
||||||
|
"source": {
|
||||||
|
"id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/datadisksnapshot0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lun": 1,
|
"lun": 1,
|
||||||
"source": { "id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/datadisksnapshot1" }
|
"hostCaching": "None",
|
||||||
|
"source": {
|
||||||
|
"id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/datadisksnapshot1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lun": 2,
|
"lun": 2,
|
||||||
"source": { "id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/datadisksnapshot2" }
|
"hostCaching": "None",
|
||||||
|
"source": {
|
||||||
|
"id": "/subscriptions/12345/resourceGroups/group1/providers/Microsoft.Compute/snapshots/datadisksnapshot2"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -120,6 +133,7 @@ func TestStepCreateSharedImageVersion_Run(t *testing.T) {
|
|||||||
s := &StepCreateSharedImageVersion{
|
s := &StepCreateSharedImageVersion{
|
||||||
Destination: tt.fields.Destination,
|
Destination: tt.fields.Destination,
|
||||||
OSDiskCacheType: tt.fields.OSDiskCacheType,
|
OSDiskCacheType: tt.fields.OSDiskCacheType,
|
||||||
|
DataDiskCacheType: tt.fields.DataDiskCacheType,
|
||||||
Location: tt.fields.Location,
|
Location: tt.fields.Location,
|
||||||
}
|
}
|
||||||
if got := s.Run(context.TODO(), state); !reflect.DeepEqual(got, tt.want) {
|
if got := s.Run(context.TODO(), state); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user