Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make update of allow_extensions_operations independent from provision_vm_agent. #8001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,8 @@ func resourceLinuxVirtualMachineUpdate(d *schema.ResourceData, meta interface{})
}

if d.HasChange("allow_extension_operations") {
provisionVMAgent := d.Get("provision_vm_agent").(bool)
allowExtensionOperations := d.Get("allow_extension_operations").(bool)

if !provisionVMAgent && allowExtensionOperations {
return fmt.Errorf("`allow_extension_operations` cannot be set to `true` when `provision_vm_agent` is set to `false`")
}

shouldUpdate = true

if update.OsProfile == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ func TestAccLinuxVirtualMachine_otherAllowExtensionOperationsUpdated(t *testing.
})
}

func TestAccLinuxVirtualMachine_otherAllowExtensionOperationsUpdatedWithoutVmAgent(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: checkLinuxVirtualMachineIsDestroyed,
Steps: []resource.TestStep{
{
Config: testLinuxVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data),
Check: resource.ComposeTestCheckFunc(
checkLinuxVirtualMachineExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "false"),
),
},
data.ImportStep(),
{
Config: testLinuxVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data),
Check: resource.ComposeTestCheckFunc(
checkLinuxVirtualMachineExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "true"),
),
},
data.ImportStep(),
},
})
}

func TestAccLinuxVirtualMachine_otherBootDiagnostics(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")

Expand Down Expand Up @@ -425,6 +453,80 @@ resource "azurerm_linux_virtual_machine" "test" {
`, template, data.RandomInteger)
}

func testLinuxVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data acceptance.TestData) string {
template := testLinuxVirtualMachine_template(data)
return fmt.Sprintf(`
%s

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_F2"
admin_username = "adminuser"
allow_extension_operations = false
provision_vm_agent = false
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)
}

func testLinuxVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data acceptance.TestData) string {
template := testLinuxVirtualMachine_template(data)
return fmt.Sprintf(`
%s

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_F2"
admin_username = "adminuser"
allow_extension_operations = true
provision_vm_agent = false
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)
}

func testLinuxVirtualMachine_otherBootDiagnostics(data acceptance.TestData) string {
template := testLinuxVirtualMachine_otherBootDiagnosticsTemplate(data)
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ func TestAccWindowsVirtualMachine_otherAllowExtensionOperationsUpdated(t *testin
})
}

func TestAccWindowsVirtualMachine_otherAllowExtensionOperationsUpdatedWithoutVmAgent(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: checkWindowsVirtualMachineIsDestroyed,
Steps: []resource.TestStep{
{
Config: testWindowsVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data),
Check: resource.ComposeTestCheckFunc(
checkWindowsVirtualMachineExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "false"),
),
},
data.ImportStep(
"admin_password",
),
{
Config: testWindowsVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data),
Check: resource.ComposeTestCheckFunc(
checkWindowsVirtualMachineExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "true"),
),
},
data.ImportStep(
"admin_password",
),
},
})
}

func TestAccWindowsVirtualMachine_otherBootDiagnostics(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test")

Expand Down Expand Up @@ -683,6 +715,72 @@ resource "azurerm_windows_virtual_machine" "test" {
`, template)
}

func testWindowsVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data acceptance.TestData) string {
template := testWindowsVirtualMachine_template(data)
return fmt.Sprintf(`
%s

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!"
allow_extension_operations = false
provision_vm_agent = false
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"
}
}
`, template)
}

func testWindowsVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data acceptance.TestData) string {
template := testWindowsVirtualMachine_template(data)
return fmt.Sprintf(`
%s

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!"
allow_extension_operations = true
provision_vm_agent = false
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"
}
}
`, template)
}

func testWindowsVirtualMachine_otherBootDiagnostics(data acceptance.TestData) string {
template := testWindowsVirtualMachine_otherBootDiagnosticsTemplate(data)
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,8 @@ func resourceWindowsVirtualMachineUpdate(d *schema.ResourceData, meta interface{
}

if d.HasChange("allow_extension_operations") {
provisionVMAgent := d.Get("provision_vm_agent").(bool)
allowExtensionOperations := d.Get("allow_extension_operations").(bool)

if !provisionVMAgent && allowExtensionOperations {
return fmt.Errorf("`allow_extension_operations` cannot be set to `true` when `provision_vm_agent` is set to `false`")
}

shouldUpdate = true

if update.OsProfile == nil {
Expand Down