Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-yechenwei committed Aug 30, 2022
1 parent 5bef688 commit 676fab0
Showing 1 changed file with 98 additions and 4 deletions.
102 changes: 98 additions & 4 deletions internal/services/compute/managed_disk_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,16 @@ func TestAccManagedDisk_zeroGbFromPlatformImage(t *testing.T) {
func TestAccManagedDisk_import(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test")
r := ManagedDiskResource{}
vm := LinuxVirtualMachineResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
// need to create a vm and then delete it so we can use the vhd to test import
Config: vm.authSSH(data),
Config: r.legacyVM(data),
Destroy: false,
ExpectNonEmptyPlan: true,
Check: acceptance.ComposeTestCheckFunc(
check.That("azurerm_linux_virtual_machine.test").ExistsInAzure(vm),
data.CheckWithClientForResource(r.destroyVirtualMachine, "azurerm_linux_virtual_machine.test"),
// NOTE: using the legacy vm resource since this test requires an unmanaged disk
data.CheckWithClientForResource(r.destroyVirtualMachine, "azurerm_virtual_machine.test"),
),
},
{
Expand Down Expand Up @@ -2151,3 +2150,98 @@ resource "azurerm_managed_disk" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (ManagedDiskResource) legacyVM(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_network_interface" "test" {
name = "acctni-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
ip_configuration {
name = "testconfiguration1"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_storage_account" "test" {
name = "accsa%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "LRS"
tags = {
environment = "staging"
}
}
resource "azurerm_storage_container" "test" {
name = "vhds"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
resource "azurerm_virtual_machine" "test" {
name = "acctvm-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
network_interface_ids = [azurerm_network_interface.test.id]
vm_size = "Standard_D1_v2"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
disk_size_gb = "45"
}
os_profile {
computer_name = "hn%d"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = "Production"
cost-center = "Ops"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

0 comments on commit 676fab0

Please sign in to comment.