[azurerm] Add os_type and image_uri in azurerm_virtual_machine (#6553)

Fix #6372

Partial fix of #6526
This commit is contained in:
Antoine Rouaze 2016-05-09 19:51:19 +02:00 committed by Paul Stack
parent b2cb8d27f6
commit a105de19c0
2 changed files with 29 additions and 0 deletions

View File

@ -118,6 +118,11 @@ func resourceArmVirtualMachine() *schema.Resource {
Required: true, Required: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"os_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
@ -128,6 +133,11 @@ func resourceArmVirtualMachine() *schema.Resource {
Required: true, Required: true,
}, },
"image_uri": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"caching": &schema.Schema{ "caching": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -1082,6 +1092,7 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk,
name := disk["name"].(string) name := disk["name"].(string)
vhdURI := disk["vhd_uri"].(string) vhdURI := disk["vhd_uri"].(string)
imageURI := disk["image_uri"].(string)
createOption := disk["create_option"].(string) createOption := disk["create_option"].(string)
osDisk := &compute.OSDisk{ osDisk := &compute.OSDisk{
@ -1092,6 +1103,22 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk,
CreateOption: compute.DiskCreateOptionTypes(createOption), CreateOption: compute.DiskCreateOptionTypes(createOption),
} }
if v := disk["image_uri"].(string); v != "" {
osDisk.Image = &compute.VirtualHardDisk{
URI: &imageURI,
}
}
if v := disk["os_type"].(string); v != "" {
if v == "linux" {
osDisk.OsType = compute.Linux
} else if v == "windows" {
osDisk.OsType = compute.Windows
} else {
return nil, fmt.Errorf("[ERROR] os_type must be 'linux' or 'windows'")
}
}
if v := disk["caching"].(string); v != "" { if v := disk["caching"].(string); v != "" {
osDisk.Caching = compute.CachingTypes(v) osDisk.Caching = compute.CachingTypes(v)
} }

View File

@ -142,6 +142,8 @@ For more information on the different example configurations, please check out t
* `vhd_uri` - (Required) Specifies the vhd uri. * `vhd_uri` - (Required) Specifies the vhd uri.
* `create_option` - (Required) Specifies how the virtual machine should be created. Possible values are `attach` and `FromImage`. * `create_option` - (Required) Specifies how the virtual machine should be created. Possible values are `attach` and `FromImage`.
* `caching` - (Optional) Specifies the caching requirements. * `caching` - (Optional) Specifies the caching requirements.
* `image_uri` - (Optional) Specifies the image_uri in the form publisherName:offer:skus:version.
* `os_type` - (Optional) Specifies the operating system Type, valid values are windows, linux.
`storage_data_disk` supports the following: `storage_data_disk` supports the following: