Skip to content

Commit

Permalink
Update the linux part
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Nov 12, 2020
1 parent 982b85f commit 9dda6fb
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,16 @@ func resourceLinuxVirtualMachineUpdate(d *schema.ResourceData, meta interface{})

if d.HasChange("dedicated_host_id") {
shouldUpdate = true
update.Host = &compute.SubResource{
ID: utils.String(d.Get("dedicated_host_id").(string)),

// Code="PropertyChangeNotAllowed" Message="Updating Host of VM 'VMNAME' is not allowed as the VM is currently allocated. Please Deallocate the VM and retry the operation."
shouldDeallocate = true

if v, ok := d.GetOk("dedicated_host_id"); ok {
update.Host = &compute.SubResource{
ID: utils.String(v.(string)),
}
} else {
update.Host = &compute.SubResource{}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func TestAccLinuxVirtualMachine_scalingDedicatedHostUpdate(t *testing.T) {
Providers: acceptance.SupportedProviders,
CheckDestroy: checkLinuxVirtualMachineIsDestroyed,
Steps: []resource.TestStep{
{
Config: testLinuxVirtualMachine_scalingDedicatedHostInitial(data),
Check: resource.ComposeTestCheckFunc(
checkLinuxVirtualMachineExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testLinuxVirtualMachine_scalingDedicatedHost(data),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -87,6 +94,14 @@ func TestAccLinuxVirtualMachine_scalingDedicatedHostUpdate(t *testing.T) {
checkLinuxVirtualMachineExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testLinuxVirtualMachine_scalingDedicatedHostRemoved(data),
Check: resource.ComposeTestCheckFunc(
checkLinuxVirtualMachineExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}
Expand Down Expand Up @@ -245,6 +260,48 @@ resource "azurerm_linux_virtual_machine" "test" {
`, template, data.RandomInteger, data.RandomInteger)
}

func testLinuxVirtualMachine_scalingDedicatedHostInitial(data acceptance.TestData) string {
template := testLinuxVirtualMachine_template(data)
return fmt.Sprintf(`
%s
resource "azurerm_dedicated_host_group" "test" {
name = "acctestDHG-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
platform_fault_domain_count = 2
}
resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_D2s_v3" # NOTE: SKU's are limited by the Dedicated Host
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"
}
}
`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func testLinuxVirtualMachine_scalingDedicatedHost(data acceptance.TestData) string {
template := testLinuxVirtualMachine_template(data)
return fmt.Sprintf(`
Expand Down Expand Up @@ -355,6 +412,56 @@ resource "azurerm_linux_virtual_machine" "test" {
`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func testLinuxVirtualMachine_scalingDedicatedHostRemoved(data acceptance.TestData) string {
template := testLinuxVirtualMachine_template(data)
return fmt.Sprintf(`
%s
resource "azurerm_dedicated_host_group" "test" {
name = "acctestDHG-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
platform_fault_domain_count = 2
}
resource "azurerm_dedicated_host" "second" {
name = "acctestDH2-%d"
dedicated_host_group_id = azurerm_dedicated_host_group.test.id
location = azurerm_resource_group.test.location
sku_name = "DSv3-Type1"
platform_fault_domain = 1
}
resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_D2s_v3" # NOTE: SKU's are limited by the Dedicated Host
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"
}
}
`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func testLinuxVirtualMachine_scalingProximityPlacementGroup(data acceptance.TestData) string {
template := testLinuxVirtualMachine_template(data)
return fmt.Sprintf(`
Expand Down

0 comments on commit 9dda6fb

Please sign in to comment.