Merge pull request #3995 from boumenot/pr-issue-3965
azure: Allow user to override size of OS disk
This commit is contained in:
commit
17c2c6f4f7
|
@ -81,7 +81,8 @@ type Config struct {
|
|||
VirtualNetworkResourceGroupName string `mapstructure:"virtual_network_resource_group_name"`
|
||||
|
||||
// OS
|
||||
OSType string `mapstructure:"os_type"`
|
||||
OSType string `mapstructure:"os_type"`
|
||||
OSDiskSizeGB int32 `mapstructure:"os_disk_size_gb"`
|
||||
|
||||
// Runtime Values
|
||||
UserName string
|
||||
|
|
|
@ -55,6 +55,10 @@ func GetVirtualMachineDeployment(config *Config) (*resources.Deployment, error)
|
|||
builder.SetMarketPlaceImage(config.ImagePublisher, config.ImageOffer, config.ImageSku, config.ImageVersion)
|
||||
}
|
||||
|
||||
if config.OSDiskSizeGB > 0 {
|
||||
builder.SetOSDiskSizeGB(config.OSDiskSizeGB)
|
||||
}
|
||||
|
||||
if config.VirtualNetworkName != "" {
|
||||
builder.SetVirtualNetwork(
|
||||
config.VirtualNetworkResourceGroupName,
|
||||
|
|
|
@ -3,10 +3,10 @@ package template
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
||||
"github.com/Azure/go-autorest/autorest/to"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -128,6 +128,18 @@ func (s *TemplateBuilder) SetImageUrl(imageUrl string, osType compute.OperatingS
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *TemplateBuilder) SetOSDiskSizeGB(diskSizeGB int32) error {
|
||||
resource, err := s.getResourceByType(resourceVirtualMachine)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
profile := resource.Properties.StorageProfile
|
||||
profile.OsDisk.DiskSizeGB = to.Int32Ptr(diskSizeGB)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *TemplateBuilder) SetVirtualNetwork(virtualNetworkResourceGroup, virtualNetworkName, subnetName string) error {
|
||||
s.setVariable("virtualNetworkResourceGroup", virtualNetworkResourceGroup)
|
||||
s.setVariable("virtualNetworkName", virtualNetworkName)
|
||||
|
|
|
@ -87,6 +87,7 @@
|
|||
"osDisk": {
|
||||
"caching": "ReadWrite",
|
||||
"createOption": "FromImage",
|
||||
"diskSizeGB": 100,
|
||||
"image": {
|
||||
"uri": "http://azure/custom.vhd"
|
||||
},
|
||||
|
|
|
@ -73,6 +73,7 @@ func TestBuildLinux02(t *testing.T) {
|
|||
|
||||
testSubject.BuildLinux("--test-ssh-authorized-key--")
|
||||
testSubject.SetImageUrl("http://azure/custom.vhd", compute.Linux)
|
||||
testSubject.SetOSDiskSizeGB(100)
|
||||
|
||||
err = testSubject.SetVirtualNetwork("--virtual-network-resource-group--", "--virtual-network--", "--subnet-name--")
|
||||
if err != nil {
|
||||
|
|
|
@ -87,6 +87,9 @@ builder.
|
|||
`Linux` this configures an SSH authorized key. For `Windows` this
|
||||
configures a WinRM certificate.
|
||||
|
||||
- `os_disk_size_gb` (int32) Specify the size of the OS disk in GB (gigabytes). Values of zero or less than zero are
|
||||
ignored.
|
||||
|
||||
- `virtual_network_name` (string) Use a pre-existing virtual network for the VM. This option enables private
|
||||
communication with the VM, no public IP address is **used** or **provisioned**. This value should only be set if
|
||||
Packer is executed from a host on the same subnet / virtual network.
|
||||
|
|
Loading…
Reference in New Issue