Skip to content

Commit

Permalink
azurerm_image: add option to set the hyper_v_generation for the image
Browse files Browse the repository at this point in the history
The new clients require this information see [properties.hyperVGeneration][1] and it supports 2 values `V1` and `V2` [2]

the default is `V1` in azure cli `--hyper-v-generation` [3], so it should be safe to keep that as default.

[1]: https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#image
[2]: https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes
[3]: https://docs.microsoft.com/en-us/cli/azure/image?view=azure-cli-latest#optional-parameters
  • Loading branch information
abhinavdahiya committed Sep 27, 2019
1 parent b803a22 commit 33cb166
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
24 changes: 17 additions & 7 deletions azurerm/resource_arm_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func resourceArmImage() *schema.Resource {
ForceNew: true,
},

"hyper_v_generation": {
Type: schema.TypeString,
Optional: true,
Default: string(compute.HyperVGenerationTypesV1),
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(compute.HyperVGenerationTypesV1),
string(compute.HyperVGenerationTypesV2),
}, false),
},

"source_virtual_machine_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -177,6 +188,7 @@ func resourceArmImageCreateUpdate(d *schema.ResourceData, meta interface{}) erro
name := d.Get("name").(string)
resGroup := d.Get("resource_group_name").(string)
zoneResilient := d.Get("zone_resilient").(bool)
hyperVGeneration := d.Get("hyper_v_generation").(string)

if features.ShouldResourcesBeImported() && d.IsNewResource() {
existing, err := client.Get(ctx, resGroup, name, "")
Expand All @@ -194,7 +206,9 @@ func resourceArmImageCreateUpdate(d *schema.ResourceData, meta interface{}) erro
location := azure.NormalizeLocation(d.Get("location").(string))
expandedTags := tags.Expand(d.Get("tags").(map[string]interface{}))

properties := compute.ImageProperties{}
properties := compute.ImageProperties{
HyperVGeneration: compute.HyperVGenerationTypes(hyperVGeneration),
}

osDisk, err := expandAzureRmImageOsDisk(d)
if err != nil {
Expand Down Expand Up @@ -227,14 +241,10 @@ func resourceArmImageCreateUpdate(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("[ERROR] Cannot create image when both source VM and storage profile are empty")
}

properties = compute.ImageProperties{
StorageProfile: &storageProfile,
}
properties.StorageProfile = &storageProfile
} else {
//creating an image from source VM
properties = compute.ImageProperties{
SourceVirtualMachine: &sourceVM,
}
properties.SourceVirtualMachine = &sourceVM
}

createImage := compute.Image{
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The following arguments are supported:
* `data_disk` - (Optional) One or more `data_disk` elements as defined below.
* `tags` - (Optional) A mapping of tags to assign to the resource.
* `zone_resilient` - (Optional) Is zone resiliency enabled? Defaults to `false`. Changing this forces a new resource to be created.
* `hyper_v_generation` - (Optional) The HyperVGenerationType of the VirtualMachine created from the image as `V1`, `V2`. The default is `V1`.

~> **Note**: `zone_resilient` can only be set to `true` if the image is stored in a region that supports availability zones.

Expand Down

0 comments on commit 33cb166

Please sign in to comment.