Skip to content

Commit f5fe03a

Browse files
authored
Merge pull request #592 from arsdragonfly/arsdragonfly/disk-controller-type
support disk controller type option
2 parents 056ba1b + 53739c3 commit f5fe03a

13 files changed

Lines changed: 972 additions & 0 deletions

.web-docs/components/builder/arm/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ Providing `temp_resource_group_name` or `location` in combination with
391391
[supports accelerated networking](https://learn.microsoft.com/en-us/azure/virtual-network/accelerated-networking-overview?tabs=NetworkManager&tryIt=true&source=docs#supported-vm-instances).
392392
Set to `false` to explicitly disable it. Defaults to unset (Azure decides).
393393

394+
- `disk_controller_type` (string) - Set the disk controller type for the build VM. Valid values are `SCSI`
395+
and `NVMe`. `NVMe` requires a VM size that
396+
[supports NVMe](https://learn.microsoft.com/en-us/azure/virtual-machines/nvme-overview).
397+
Defaults to unset (Azure decides based on VM size).
398+
394399
- `custom_data_file` (string) - Specify a file containing custom data to inject into the cloud-init
395400
process. The contents of the file are read and injected into the ARM
396401
template. The custom data will be passed to cloud-init for processing at

builder/azure/arm/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ type Config struct {
472472
// [supports accelerated networking](https://learn.microsoft.com/en-us/azure/virtual-network/accelerated-networking-overview?tabs=NetworkManager&tryIt=true&source=docs#supported-vm-instances).
473473
// Set to `false` to explicitly disable it. Defaults to unset (Azure decides).
474474
AcceleratedNetworking *bool `mapstructure:"accelerated_networking" required:"false"`
475+
// Set the disk controller type for the build VM. Valid values are `SCSI`
476+
// and `NVMe`. `NVMe` requires a VM size that
477+
// [supports NVMe](https://learn.microsoft.com/en-us/azure/virtual-machines/nvme-overview).
478+
// Defaults to unset (Azure decides based on VM size).
479+
DiskControllerType string `mapstructure:"disk_controller_type" required:"false"`
475480
// Specify a file containing custom data to inject into the cloud-init
476481
// process. The contents of the file are read and injected into the ARM
477482
// template. The custom data will be passed to cloud-init for processing at
@@ -1596,6 +1601,12 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) {
15961601
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("The disk_caching_type %q is invalid", c.DiskCachingType))
15971602
}
15981603

1604+
if c.DiskControllerType != "" {
1605+
if !strings.EqualFold(c.DiskControllerType, "SCSI") && !strings.EqualFold(c.DiskControllerType, "NVMe") {
1606+
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("The disk_controller_type %q is invalid, the valid values are SCSI and NVMe", c.DiskControllerType))
1607+
}
1608+
}
1609+
15991610
/////////////////////////////////////////////
16001611
// License Type (Azure Hybrid Benefit)
16011612
if c.LicenseType != "" {

builder/azure/arm/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/azure/arm/template_factory.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ func GetVirtualMachineTemplateBuilder(config *Config) (*template.TemplateBuilder
348348
}
349349
}
350350

351+
if config.DiskControllerType != "" {
352+
err = builder.SetDiskControllerType(config.DiskControllerType)
353+
if err != nil {
354+
return nil, err
355+
}
356+
}
357+
351358
if config.BootDiagSTGAccount != "" {
352359
err = builder.SetBootDiagnostics(config.BootDiagSTGAccount)
353360
if err != nil {
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"adminPassword": {
6+
"type": "securestring"
7+
},
8+
"adminUsername": {
9+
"type": "string"
10+
},
11+
"commandToExecute": {
12+
"type": "string"
13+
},
14+
"dataDiskName": {
15+
"type": "string"
16+
},
17+
"dnsNameForPublicIP": {
18+
"type": "string"
19+
},
20+
"nicName": {
21+
"type": "string"
22+
},
23+
"nsgName": {
24+
"type": "string"
25+
},
26+
"osDiskName": {
27+
"type": "string"
28+
},
29+
"publicIPAddressName": {
30+
"type": "string"
31+
},
32+
"storageAccountBlobEndpoint": {
33+
"type": "string"
34+
},
35+
"subnetName": {
36+
"type": "string"
37+
},
38+
"virtualNetworkName": {
39+
"type": "string"
40+
},
41+
"vmName": {
42+
"type": "string"
43+
},
44+
"vmSize": {
45+
"type": "string"
46+
}
47+
},
48+
"resources": [
49+
{
50+
"apiVersion": "[variables('networkApiVersion')]",
51+
"location": "[variables('location')]",
52+
"name": "[parameters('publicIPAddressName')]",
53+
"properties": {
54+
"dnsSettings": {
55+
"domainNameLabel": "[parameters('dnsNameForPublicIP')]"
56+
},
57+
"publicIPAllocationMethod": "[variables('publicIPAddressType')]"
58+
},
59+
"sku": {
60+
"name": "Standard",
61+
"tier": "Regional"
62+
},
63+
"type": "Microsoft.Network/publicIPAddresses"
64+
},
65+
{
66+
"apiVersion": "[variables('networkApiVersion')]",
67+
"dependsOn": [
68+
"[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPAddressName'))]",
69+
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
70+
],
71+
"location": "[variables('location')]",
72+
"name": "[parameters('nicName')]",
73+
"properties": {
74+
"ipConfigurations": [
75+
{
76+
"name": "ipconfig",
77+
"properties": {
78+
"privateIPAllocationMethod": "Dynamic",
79+
"publicIPAddress": {
80+
"id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddressName'))]"
81+
},
82+
"subnet": {
83+
"id": "[variables('subnetRef')]"
84+
}
85+
}
86+
}
87+
]
88+
},
89+
"type": "Microsoft.Network/networkInterfaces"
90+
},
91+
{
92+
"apiVersion": "[variables('computeApiVersion')]",
93+
"dependsOn": [
94+
"[concat('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
95+
],
96+
"location": "[variables('location')]",
97+
"name": "[parameters('vmName')]",
98+
"properties": {
99+
"diagnosticsProfile": {
100+
"bootDiagnostics": {
101+
"enabled": false
102+
}
103+
},
104+
"hardwareProfile": {
105+
"vmSize": "[parameters('vmSize')]"
106+
},
107+
"networkProfile": {
108+
"networkInterfaces": [
109+
{
110+
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
111+
}
112+
]
113+
},
114+
"osProfile": {
115+
"adminUsername": "[parameters('adminUsername')]",
116+
"computerName": "[parameters('vmName')]",
117+
"linuxConfiguration": {
118+
"disablePasswordAuthentication": true,
119+
"ssh": {
120+
"publicKeys": [
121+
{
122+
"keyData": "",
123+
"path": "[variables('sshKeyPath')]"
124+
}
125+
]
126+
}
127+
}
128+
},
129+
"storageProfile": {
130+
"imageReference": {
131+
"offer": "ignored00",
132+
"publisher": "ignored00",
133+
"sku": "ignored00",
134+
"version": "latest"
135+
},
136+
"osDisk": {
137+
"caching": "ReadWrite",
138+
"createOption": "FromImage",
139+
"name": "[parameters('osDiskName')]"
140+
}
141+
}
142+
},
143+
"type": "Microsoft.Compute/virtualMachines"
144+
},
145+
{
146+
"apiVersion": "[variables('computeApiVersion')]",
147+
"condition": "[not(empty(parameters('commandToExecute')))]",
148+
"dependsOn": [
149+
"[resourceId('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
150+
],
151+
"location": "[variables('location')]",
152+
"name": "[concat(parameters('vmName'), '/extension-customscript')]",
153+
"properties": {
154+
"autoUpgradeMinorVersion": true,
155+
"publisher": "Microsoft.Compute",
156+
"settings": {
157+
"commandToExecute": "[parameters('commandToExecute')]"
158+
},
159+
"type": "CustomScriptExtension",
160+
"typeHandlerVersion": "1.10"
161+
},
162+
"type": "Microsoft.Compute/virtualMachines/extensions"
163+
},
164+
{
165+
"apiVersion": "[variables('networkApiVersion')]",
166+
"location": "[variables('location')]",
167+
"name": "[parameters('nsgName')]",
168+
"properties": {
169+
"securityRules": [
170+
{
171+
"name": "AllowIPsToSshWinRMInbound",
172+
"properties": {
173+
"access": "Allow",
174+
"description": "Allow inbound traffic from specified IP addresses",
175+
"destinationAddressPrefix": "VirtualNetwork",
176+
"destinationPortRange": "0",
177+
"direction": "Inbound",
178+
"priority": 100,
179+
"protocol": "Tcp",
180+
"sourceAddressPrefix": "*",
181+
"sourcePortRange": "*"
182+
}
183+
}
184+
]
185+
},
186+
"type": "Microsoft.Network/networkSecurityGroups"
187+
},
188+
{
189+
"apiVersion": "[variables('networkApiVersion')]",
190+
"dependsOn": [
191+
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('nsgName'))]"
192+
],
193+
"location": "[variables('location')]",
194+
"name": "[variables('virtualNetworkName')]",
195+
"properties": {
196+
"addressSpace": {
197+
"addressPrefixes": [
198+
"[variables('addressPrefix')]"
199+
]
200+
},
201+
"subnets": [
202+
{
203+
"name": "[variables('subnetName')]",
204+
"properties": {
205+
"addressPrefix": "[variables('subnetAddressPrefix')]",
206+
"networkSecurityGroup": {
207+
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('nsgName'))]"
208+
}
209+
}
210+
}
211+
]
212+
},
213+
"type": "Microsoft.Network/virtualNetworks"
214+
}
215+
],
216+
"variables": {
217+
"addressPrefix": "10.0.0.0/16",
218+
"computeApiVersion": "2023-03-01",
219+
"location": "[resourceGroup().location]",
220+
"networkApiVersion": "2023-04-01",
221+
"publicIPAddressType": "Static",
222+
"sshKeyPath": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
223+
"subnetAddressPrefix": "10.0.0.0/24",
224+
"subnetName": "[parameters('subnetName')]",
225+
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
226+
"virtualNetworkName": "[parameters('virtualNetworkName')]",
227+
"virtualNetworkResourceGroup": "[resourceGroup().name]",
228+
"vmStorageAccountContainerName": "images",
229+
"vnetID": "[resourceId(variables('virtualNetworkResourceGroup'), 'Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
230+
}
231+
}

0 commit comments

Comments
 (0)