From 887922ef265415a50c3313349dc615e329639ba3 Mon Sep 17 00:00:00 2001 From: Yichun Ma Date: Tue, 14 Jun 2022 14:10:47 +0800 Subject: [PATCH] `r\linux/windows_virtual_machine`: add support for `capacity_reservation_group_id` --- .../compute/linux_virtual_machine_resource.go | 48 +++ ...x_virtual_machine_resource_scaling_test.go | 277 ++++++++++++++++++ .../windows_virtual_machine_resource.go | 48 +++ ...s_virtual_machine_resource_scaling_test.go | 261 +++++++++++++++++ .../r/linux_virtual_machine.html.markdown | 4 + .../r/windows_virtual_machine.html.markdown | 4 + 6 files changed, 642 insertions(+) diff --git a/internal/services/compute/linux_virtual_machine_resource.go b/internal/services/compute/linux_virtual_machine_resource.go index b8494189274f..6c4dfc520679 100644 --- a/internal/services/compute/linux_virtual_machine_resource.go +++ b/internal/services/compute/linux_virtual_machine_resource.go @@ -114,6 +114,7 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource { // TODO: raise a GH issue for the broken API // availability_set_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/acctestRG-200122113424880096/providers/Microsoft.Compute/availabilitySets/ACCTESTAVSET-200122113424880096" => "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/acctestRG-200122113424880096/providers/Microsoft.Compute/availabilitySets/acctestavset-200122113424880096" (forces new resource) ConflictsWith: []string{ + "capacity_reservation_group_id", "virtual_machine_scale_set_id", "zone", }, @@ -121,6 +122,19 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource { "boot_diagnostics": bootDiagnosticsSchema(), + "capacity_reservation_group_id": { + Type: pluginsdk.TypeString, + Optional: true, + // the Compute/VM API is broken and returns the Resource Group name in UPPERCASE + // tracked by https://github.com/Azure/azure-rest-api-specs/issues/19424 + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: computeValidate.CapacityReservationGroupID, + ConflictsWith: []string{ + "availability_set_id", + "proximity_placement_group_id", + }, + }, + "computer_name": { Type: pluginsdk.TypeString, Optional: true, @@ -246,6 +260,9 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource { ValidateFunc: computeValidate.ProximityPlacementGroupID, // the Compute/VM API is broken and returns the Resource Group name in UPPERCASE :shrug: DiffSuppressFunc: suppress.CaseDifference, + ConflictsWith: []string{ + "capacity_reservation_group_id", + }, }, "secret": linuxSecretSchema(), @@ -543,6 +560,14 @@ func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface } } + if v, ok := d.GetOk("capacity_reservation_group_id"); ok { + params.CapacityReservation = &compute.CapacityReservationProfile{ + CapacityReservationGroup: &compute.SubResource{ + ID: utils.String(v.(string)), + }, + } + } + if v, ok := d.GetOk("custom_data"); ok { params.OsProfile.CustomData = utils.String(v.(string)) } @@ -687,6 +712,12 @@ func resourceLinuxVirtualMachineRead(d *pluginsdk.ResourceData, meta interface{} } d.Set("availability_set_id", availabilitySetId) + capacityReservationGroupId := "" + if props.CapacityReservation != nil && props.CapacityReservation.CapacityReservationGroup != nil && props.CapacityReservation.CapacityReservationGroup.ID != nil { + capacityReservationGroupId = *props.CapacityReservation.CapacityReservationGroup.ID + } + d.Set("capacity_reservation_group_id", capacityReservationGroupId) + licenseType := "" if props.LicenseType != nil { licenseType = *props.LicenseType @@ -944,6 +975,23 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface } } + if d.HasChange("capacity_reservation_group_id") { + shouldUpdate = true + shouldDeallocate = true + + if v, ok := d.GetOk("capacity_reservation_group_id"); ok { + update.CapacityReservation = &compute.CapacityReservationProfile{ + CapacityReservationGroup: &compute.SubResource{ + ID: utils.String(v.(string)), + }, + } + } else { + update.CapacityReservation = &compute.CapacityReservationProfile{ + CapacityReservationGroup: &compute.SubResource{}, + } + } + } + if d.HasChange("dedicated_host_id") { shouldUpdate = true diff --git a/internal/services/compute/linux_virtual_machine_resource_scaling_test.go b/internal/services/compute/linux_virtual_machine_resource_scaling_test.go index fb82ba15e7dc..10f538a46ecc 100644 --- a/internal/services/compute/linux_virtual_machine_resource_scaling_test.go +++ b/internal/services/compute/linux_virtual_machine_resource_scaling_test.go @@ -39,6 +39,57 @@ func TestAccLinuxVirtualMachine_scalingAvailabilitySet(t *testing.T) { }) } +func TestAccLinuxVirtualMachine_scalingCapacityReservationGroup(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") + r := LinuxVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.scalingCapacityReservationGroup(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccLinuxVirtualMachine_scalingCapacityReservationGroupUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") + r := LinuxVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.scalingCapacityReservationGroupInitial(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.scalingCapacityReservationGroup(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.scalingCapacityReservationGroupUpdate(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.scalingCapacityReservationGroupRemoved(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccLinuxVirtualMachine_scalingDedicatedHost(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") r := LinuxVirtualMachineResource{} @@ -325,6 +376,232 @@ resource "azurerm_linux_virtual_machine" "test" { `, r.template(data), data.RandomInteger, data.RandomInteger) } +func (r LinuxVirtualMachineResource) scalingCapacityReservationGroupInitial(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test" { + name = "acctest-ccrg-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + admin_ssh_key { + username = "adminuser" + public_key = local.first_public_key + } + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } +} +`, r.template(data), data.RandomInteger) +} + +func (r LinuxVirtualMachineResource) scalingCapacityReservationGroup(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test" { + name = "acctest-ccrg-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + admin_ssh_key { + username = "adminuser" + public_key = local.first_public_key + } + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + depends_on = [ + azurerm_capacity_reservation.test, + ] +} +`, r.template(data), data.RandomInteger) +} + +func (r LinuxVirtualMachineResource) scalingCapacityReservationGroupUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test" { + name = "acctest-ccrg-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_capacity_reservation_group" "test2" { + name = "acctest-ccrg2-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test2" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test2.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + + capacity_reservation_group_id = azurerm_capacity_reservation_group.test2.id + + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + admin_ssh_key { + username = "adminuser" + public_key = local.first_public_key + } + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + depends_on = [ + azurerm_capacity_reservation.test2, + ] +} +`, r.template(data), data.RandomInteger) +} + +func (r LinuxVirtualMachineResource) scalingCapacityReservationGroupRemoved(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test2" { + name = "acctest-ccrg2-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test2" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test2.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + admin_ssh_key { + username = "adminuser" + public_key = local.first_public_key + } + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } +} +`, r.template(data), data.RandomInteger) +} + func (r LinuxVirtualMachineResource) scalingDedicatedHostInitial(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/internal/services/compute/windows_virtual_machine_resource.go b/internal/services/compute/windows_virtual_machine_resource.go index 808b5f82876d..70f65af8692d 100644 --- a/internal/services/compute/windows_virtual_machine_resource.go +++ b/internal/services/compute/windows_virtual_machine_resource.go @@ -115,6 +115,7 @@ func resourceWindowsVirtualMachine() *pluginsdk.Resource { // TODO: raise a GH issue for the broken API // availability_set_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/acctestRG-200122113424880096/providers/Microsoft.Compute/availabilitySets/ACCTESTAVSET-200122113424880096" => "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/acctestRG-200122113424880096/providers/Microsoft.Compute/availabilitySets/acctestavset-200122113424880096" (forces new resource) ConflictsWith: []string{ + "capacity_reservation_group_id", "virtual_machine_scale_set_id", "zone", }, @@ -122,6 +123,19 @@ func resourceWindowsVirtualMachine() *pluginsdk.Resource { "boot_diagnostics": bootDiagnosticsSchema(), + "capacity_reservation_group_id": { + Type: pluginsdk.TypeString, + Optional: true, + // the Compute/VM API is broken and returns the Resource Group name in UPPERCASE + // tracked by https://github.com/Azure/azure-rest-api-specs/issues/19424 + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: computeValidate.CapacityReservationGroupID, + ConflictsWith: []string{ + "availability_set_id", + "proximity_placement_group_id", + }, + }, + "computer_name": { Type: pluginsdk.TypeString, Optional: true, @@ -262,6 +276,9 @@ func resourceWindowsVirtualMachine() *pluginsdk.Resource { ValidateFunc: computeValidate.ProximityPlacementGroupID, // the Compute/VM API is broken and returns the Resource Group name in UPPERCASE :shrug: DiffSuppressFunc: suppress.CaseDifference, + ConflictsWith: []string{ + "capacity_reservation_group_id", + }, }, "secret": windowsSecretSchema(), @@ -542,6 +559,14 @@ func resourceWindowsVirtualMachineCreate(d *pluginsdk.ResourceData, meta interfa } } + if v, ok := d.GetOk("capacity_reservation_group_id"); ok { + params.CapacityReservation = &compute.CapacityReservationProfile{ + CapacityReservationGroup: &compute.SubResource{ + ID: utils.String(v.(string)), + }, + } + } + if v, ok := d.GetOk("custom_data"); ok { params.OsProfile.CustomData = utils.String(v.(string)) } @@ -743,6 +768,12 @@ func resourceWindowsVirtualMachineRead(d *pluginsdk.ResourceData, meta interface } d.Set("availability_set_id", availabilitySetId) + capacityReservationGroupId := "" + if props.CapacityReservation != nil && props.CapacityReservation.CapacityReservationGroup != nil && props.CapacityReservation.CapacityReservationGroup.ID != nil { + capacityReservationGroupId = *props.CapacityReservation.CapacityReservationGroup.ID + } + d.Set("capacity_reservation_group_id", capacityReservationGroupId) + if err := d.Set("boot_diagnostics", flattenBootDiagnostics(props.DiagnosticsProfile)); err != nil { return fmt.Errorf("setting `boot_diagnostics`: %+v", err) } @@ -1038,6 +1069,23 @@ func resourceWindowsVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interfa update.Identity = identity } + if d.HasChange("capacity_reservation_group_id") { + shouldUpdate = true + shouldDeallocate = true + + if v, ok := d.GetOk("capacity_reservation_group_id"); ok { + update.CapacityReservation = &compute.CapacityReservationProfile{ + CapacityReservationGroup: &compute.SubResource{ + ID: utils.String(v.(string)), + }, + } + } else { + update.CapacityReservation = &compute.CapacityReservationProfile{ + CapacityReservationGroup: &compute.SubResource{}, + } + } + } + if d.HasChange("dedicated_host_id") { shouldUpdate = true diff --git a/internal/services/compute/windows_virtual_machine_resource_scaling_test.go b/internal/services/compute/windows_virtual_machine_resource_scaling_test.go index d894a67fa625..b01c3914c9b1 100644 --- a/internal/services/compute/windows_virtual_machine_resource_scaling_test.go +++ b/internal/services/compute/windows_virtual_machine_resource_scaling_test.go @@ -39,6 +39,57 @@ func TestAccWindowsVirtualMachine_scalingAvailabilitySet(t *testing.T) { }) } +func TestAccWindowsVirtualMachine_scalingCapacityReservationGroup(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") + r := WindowsVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.scalingCapacityReservationGroup(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("admin_password"), + }) +} + +func TestAccWindowsVirtualMachine_scalingCapacityReservationGroupUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") + r := WindowsVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.scalingCapacityReservationGroupInitial(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("admin_password"), + { + Config: r.scalingCapacityReservationGroup(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("admin_password"), + { + Config: r.scalingCapacityReservationGroupUpdate(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("admin_password"), + { + Config: r.scalingCapacityReservationGroupRemoved(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("admin_password"), + }) +} + func TestAccWindowsVirtualMachine_scalingDedicatedHost(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") r := WindowsVirtualMachineResource{} @@ -317,6 +368,216 @@ resource "azurerm_windows_virtual_machine" "test" { `, r.template(data), data.RandomInteger) } +func (r WindowsVirtualMachineResource) scalingCapacityReservationGroupInitial(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test" { + name = "acctest-ccrg-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_windows_virtual_machine" "test" { + name = local.vm_name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } +} +`, r.template(data), data.RandomInteger) +} + +func (r WindowsVirtualMachineResource) scalingCapacityReservationGroup(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test" { + name = "acctest-ccrg-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_windows_virtual_machine" "test" { + name = local.vm_name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } + + depends_on = [ + azurerm_capacity_reservation.test, + ] +} +`, r.template(data), data.RandomInteger) +} + +func (r WindowsVirtualMachineResource) scalingCapacityReservationGroupUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test" { + name = "acctest-ccrg-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_capacity_reservation_group" "test2" { + name = "acctest-ccrg2-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test2" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test2.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_windows_virtual_machine" "test" { + name = local.vm_name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + + capacity_reservation_group_id = azurerm_capacity_reservation_group.test2.id + + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } + + depends_on = [ + azurerm_capacity_reservation.test2, + ] +} +`, r.template(data), data.RandomInteger) +} + +func (r WindowsVirtualMachineResource) scalingCapacityReservationGroupRemoved(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_capacity_reservation_group" "test2" { + name = "acctest-ccrg2-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_capacity_reservation" "test2" { + name = "acctest-ccr-%[2]d" + capacity_reservation_group_id = azurerm_capacity_reservation_group.test2.id + sku { + name = "Standard_F2" + capacity = 1 + } +} + +resource "azurerm_windows_virtual_machine" "test" { + name = local.vm_name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } +} +`, r.template(data), data.RandomInteger) +} + func (r WindowsVirtualMachineResource) scalingDedicatedHostInitial(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/website/docs/r/linux_virtual_machine.html.markdown b/website/docs/r/linux_virtual_machine.html.markdown index ae07bfa0459c..979c8c2a3899 100644 --- a/website/docs/r/linux_virtual_machine.html.markdown +++ b/website/docs/r/linux_virtual_machine.html.markdown @@ -126,6 +126,10 @@ The following arguments are supported: * `boot_diagnostics` - (Optional) A `boot_diagnostics` block as defined below. +* `capacity_reservation_group_id` - (Optional) Specifies the ID of the Capacity Reservation Group which the Virtual Machine should be allocated to. + +~> **NOTE:** `capacity_reservation_group_id` cannot be used with `availability_set_id` or `proximity_placement_group_id` + * `computer_name` - (Optional) Specifies the Hostname which should be used for this Virtual Machine. If unspecified this defaults to the value for the `name` field. If the value of the `name` field is not a valid `computer_name`, then you must specify `computer_name`. Changing this forces a new resource to be created. * `custom_data` - (Optional) The Base64-Encoded Custom Data which should be used for this Virtual Machine. Changing this forces a new resource to be created. diff --git a/website/docs/r/windows_virtual_machine.html.markdown b/website/docs/r/windows_virtual_machine.html.markdown index e905c8c4dcfd..22726a2b3f3e 100644 --- a/website/docs/r/windows_virtual_machine.html.markdown +++ b/website/docs/r/windows_virtual_machine.html.markdown @@ -119,6 +119,10 @@ The following arguments are supported: * `boot_diagnostics` - (Optional) A `boot_diagnostics` block as defined below. +* `capacity_reservation_group_id` - (Optional) Specifies the ID of the Capacity Reservation Group which the Virtual Machine should be allocated to. + +~> **NOTE:** `capacity_reservation_group_id` cannot be used with `availability_set_id` or `proximity_placement_group_id` + * `computer_name` - (Optional) Specifies the Hostname which should be used for this Virtual Machine. If unspecified this defaults to the value for the `name` field. If the value of the `name` field is not a valid `computer_name`, then you must specify `computer_name`. Changing this forces a new resource to be created. * `custom_data` - (Optional) The Base64-Encoded Custom Data which should be used for this Virtual Machine. Changing this forces a new resource to be created.