Skip to content

Commit

Permalink
r/virtual_machine_data_disk_attachment: removing the identity block f…
Browse files Browse the repository at this point in the history
…or a delta update (#4538)
  • Loading branch information
tombuildsstuff authored and katbyte committed Oct 10, 2019
1 parent 896461b commit e9c229c
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions azurerm/resource_arm_virtual_machine_data_disk_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func resourceArmVirtualMachineDataDiskAttachmentCreateUpdate(d *schema.ResourceD

virtualMachine.StorageProfile.DataDisks = &disks

// fixes #2485
virtualMachine.Identity = nil
// fixes #1600
virtualMachine.Resources = nil

Expand Down Expand Up @@ -277,6 +279,8 @@ func resourceArmVirtualMachineDataDiskAttachmentDelete(d *schema.ResourceData, m

virtualMachine.StorageProfile.DataDisks = &dataDisks

// fixes #2485
virtualMachine.Identity = nil
// fixes #1600
virtualMachine.Resources = nil

Expand Down
116 changes: 116 additions & 0 deletions azurerm/resource_arm_virtual_machine_data_disk_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,35 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_updatingWriteAccelerator(t *
})
}

func TestAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(t *testing.T) {
resourceName := "azurerm_virtual_machine_data_disk_attachment.test"
ri := tf.AccRandTimeInt()
location := testLocation()
config := testAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(ri, location)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDataDiskAttachmentDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "virtual_machine_id"),
resource.TestCheckResourceAttrSet(resourceName, "managed_disk_id"),
resource.TestCheckResourceAttr(resourceName, "lun", "0"),
resource.TestCheckResourceAttr(resourceName, "caching", "None"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtension(t *testing.T) {
resourceName := "azurerm_virtual_machine_data_disk_attachment.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -325,6 +354,93 @@ resource "azurerm_virtual_machine_data_disk_attachment" "import" {
`, template)
}

func testAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(rInt int, location string) string {
return fmt.Sprintf(`
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_prefix = "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_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_F2"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "hn%d"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
identity {
type = "SystemAssigned"
}
}
resource "azurerm_managed_disk" "test" {
name = "%d-disk1"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = 10
}
resource "azurerm_virtual_machine_data_disk_attachment" "test" {
managed_disk_id = "${azurerm_managed_disk.test.id}"
virtual_machine_id = "${azurerm_virtual_machine.test.id}"
lun = "0"
caching = "None"
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(rInt int, location string) string {
template := testAccAzureRMVirtualMachineDataDiskAttachment_template(rInt, location)
return fmt.Sprintf(`
Expand Down

0 comments on commit e9c229c

Please sign in to comment.