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

Update r/azurerm_(linux|windows)_virtual_machine_scale_set: add support for automatic instance repair #6346

Merged
merged 3 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -94,6 +94,8 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource {

"automatic_os_upgrade_policy": VirtualMachineScaleSetAutomatedOSUpgradePolicySchema(),

"automatic_instance_repair": VirtualMachineScaleSetAutomaticRepairsPolicySchema(),

"boot_diagnostics": bootDiagnosticsSchema(),

"computer_name_prefix": {
Expand Down Expand Up @@ -429,6 +431,8 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i
}

scaleInPolicy := d.Get("scale_in_policy").(string)
automaticRepairsPolicyRaw := d.Get("automatic_instance_repair").([]interface{})
automaticRepairsPolicy := ExpandVirtualMachineScaleSetAutomaticRepairsPolicy(automaticRepairsPolicyRaw)

props := compute.VirtualMachineScaleSet{
Location: utils.String(location),
Expand All @@ -444,6 +448,7 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i
Tags: tags.Expand(t),
VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{
AdditionalCapabilities: additionalCapabilities,
AutomaticRepairsPolicy: automaticRepairsPolicy,
DoNotRunExtensionsOnOverprovisionedVMs: utils.Bool(d.Get("do_not_run_extensions_on_overprovisioned_machines").(bool)),
Overprovision: utils.Bool(d.Get("overprovision").(bool)),
SinglePlacementGroup: utils.Bool(d.Get("single_placement_group").(bool)),
Expand Down Expand Up @@ -680,6 +685,11 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i
updateProps.VirtualMachineProfile.ScheduledEventsProfile = ExpandVirtualMachineScaleSetScheduledEventsProfile(notificationRaw)
}

if d.HasChange("automatic_instance_repair") {
automaticRepairsPolicyRaw := d.Get("automatic_instance_repair").([]interface{})
updateProps.AutomaticRepairsPolicy = ExpandVirtualMachineScaleSetAutomaticRepairsPolicy(automaticRepairsPolicyRaw)
}

if d.HasChange("identity") {
identityRaw := d.Get("identity").([]interface{})
identity, err := ExpandVirtualMachineScaleSetIdentity(identityRaw)
Expand Down Expand Up @@ -791,6 +801,10 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int
return fmt.Errorf("Error setting `additional_capabilities`: %+v", props.AdditionalCapabilities)
}

if err := d.Set("automatic_instance_repair", FlattenVirtualMachineScaleSetAutomaticRepairsPolicy(props.AutomaticRepairsPolicy)); err != nil {
return fmt.Errorf("Error setting `automatic_instance_repair`: %+v", err)
}

d.Set("do_not_run_extensions_on_overprovisioned_machines", props.DoNotRunExtensionsOnOverprovisionedVMs)
d.Set("overprovision", props.Overprovision)
proximityPlacementGroupId := ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource {

"automatic_os_upgrade_policy": VirtualMachineScaleSetAutomatedOSUpgradePolicySchema(),

"automatic_instance_repair": VirtualMachineScaleSetAutomaticRepairsPolicySchema(),

"boot_diagnostics": bootDiagnosticsSchema(),

"computer_name_prefix": {
Expand Down Expand Up @@ -455,6 +457,8 @@ func resourceArmWindowsVirtualMachineScaleSetCreate(d *schema.ResourceData, meta
}

scaleInPolicy := d.Get("scale_in_policy").(string)
automaticRepairsPolicyRaw := d.Get("automatic_instance_repair").([]interface{})
automaticRepairsPolicy := ExpandVirtualMachineScaleSetAutomaticRepairsPolicy(automaticRepairsPolicyRaw)

props := compute.VirtualMachineScaleSet{
Location: utils.String(location),
Expand All @@ -470,6 +474,7 @@ func resourceArmWindowsVirtualMachineScaleSetCreate(d *schema.ResourceData, meta
Tags: tags.Expand(t),
VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{
AdditionalCapabilities: additionalCapabilities,
AutomaticRepairsPolicy: automaticRepairsPolicy,
DoNotRunExtensionsOnOverprovisionedVMs: utils.Bool(d.Get("do_not_run_extensions_on_overprovisioned_machines").(bool)),
Overprovision: utils.Bool(d.Get("overprovision").(bool)),
SinglePlacementGroup: utils.Bool(d.Get("single_placement_group").(bool)),
Expand Down Expand Up @@ -710,6 +715,12 @@ func resourceArmWindowsVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta
updateProps.VirtualMachineProfile.ScheduledEventsProfile = ExpandVirtualMachineScaleSetScheduledEventsProfile(notificationRaw)
}

if d.HasChange("automatic_instance_repair") {
automaticRepairsPolicyRaw := d.Get("automatic_instance_repair").([]interface{})
automaticRepairsPolicy := ExpandVirtualMachineScaleSetAutomaticRepairsPolicy(automaticRepairsPolicyRaw)
updateProps.AutomaticRepairsPolicy = automaticRepairsPolicy
}

if d.HasChange("identity") {
identityRaw := d.Get("identity").([]interface{})
identity, err := ExpandVirtualMachineScaleSetIdentity(identityRaw)
Expand Down Expand Up @@ -821,6 +832,10 @@ func resourceArmWindowsVirtualMachineScaleSetRead(d *schema.ResourceData, meta i
return fmt.Errorf("Error setting `additional_capabilities`: %+v", props.AdditionalCapabilities)
}

if err := d.Set("automatic_instance_repair", FlattenVirtualMachineScaleSetAutomaticRepairsPolicy(props.AutomaticRepairsPolicy)); err != nil {
return fmt.Errorf("Error setting `automatic_instance_repair`: %+v", err)
}

d.Set("do_not_run_extensions_on_overprovisioned_machines", props.DoNotRunExtensionsOnOverprovisionedVMs)
d.Set("overprovision", props.Overprovision)
proximityPlacementGroupId := ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,38 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherTerminateNotification(t *tes
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
// turn automatic repair on
{
Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherAutomaticRepairsPolicy(data, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName),
),
},
data.ImportStep(
"admin_password",
),
// turn automatic repair off
{
Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherAutomaticRepairsPolicy(data, false),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName),
),
},
data.ImportStep(
"admin_password",
),
},
ArcturusZhang marked this conversation as resolved.
Show resolved Hide resolved
})
}

func testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(data acceptance.TestData) string {
template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data)
return fmt.Sprintf(`
Expand Down Expand Up @@ -1293,21 +1325,21 @@ func testAccAzureRMLinuxVirtualMachineScaleSet_updateLoadBalancerHealthProbeSKUB

resource "azurerm_public_ip" "test" {
name = "acctestpip-%[2]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Dynamic"
idle_timeout_in_minutes = 4
}

resource "azurerm_lb" "test" {
name = "acctestlb-%[2]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Basic"

frontend_ip_configuration {
name = "internal"
public_ip_address_id = "${azurerm_public_ip.test.id}"
public_ip_address_id = azurerm_public_ip.test.id
}
}

Expand Down Expand Up @@ -1358,8 +1390,6 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
admin_password = "P@ssword1234!"
health_probe_id = azurerm_lb_probe.test.id

depends_on = ["azurerm_lb_rule.test"]

disable_password_authentication = false

source_image_reference {
Expand Down Expand Up @@ -1393,6 +1423,8 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
load_balancer_inbound_nat_rules_ids = [azurerm_lb_nat_pool.test.id]
}
}

depends_on = [azurerm_lb_rule.test]
}
`, template, data.RandomInteger)
}
Expand All @@ -1404,22 +1436,22 @@ func testAccAzureRMLinuxVirtualMachineScaleSet_updateLoadBalancerHealthProbeSKUS

resource "azurerm_public_ip" "test" {
name = "acctestpip-%[2]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Static"
idle_timeout_in_minutes = 4
sku = "Standard"
}

resource "azurerm_lb" "test" {
name = "acctestlb-%[2]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Standard"

frontend_ip_configuration {
name = "internal"
public_ip_address_id = "${azurerm_public_ip.test.id}"
public_ip_address_id = azurerm_public_ip.test.id
}
}

Expand Down Expand Up @@ -1470,8 +1502,6 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
admin_password = "P@ssword1234!"
health_probe_id = azurerm_lb_probe.test.id

depends_on = ["azurerm_lb_rule.test"]

disable_password_authentication = false

source_image_reference {
Expand Down Expand Up @@ -1505,6 +1535,8 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
load_balancer_inbound_nat_rules_ids = [azurerm_lb_nat_pool.test.id]
}
}

depends_on = [azurerm_lb_rule.test]
}
`, template, data.RandomInteger)
}
Expand Down Expand Up @@ -1600,3 +1632,118 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
}
`, template, data.RandomInteger, enabled)
}

func testAccAzureRMLinuxVirtualMachineScaleSet_otherAutomaticRepairsPolicy(data acceptance.TestData, enabled bool) string {
template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data)
return fmt.Sprintf(`
%[1]s

resource "azurerm_public_ip" "test" {
name = "acctestpip-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Dynamic"
idle_timeout_in_minutes = 4
}

resource "azurerm_lb" "test" {
name = "acctestlb-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Basic"

frontend_ip_configuration {
name = "internal"
public_ip_address_id = azurerm_public_ip.test.id
}
}

resource "azurerm_lb_backend_address_pool" "test" {
name = "test"
resource_group_name = azurerm_resource_group.test.name
loadbalancer_id = azurerm_lb.test.id
}

resource "azurerm_lb_nat_pool" "test" {
name = "test"
resource_group_name = azurerm_resource_group.test.name
loadbalancer_id = azurerm_lb.test.id
frontend_ip_configuration_name = "internal"
protocol = "Tcp"
frontend_port_start = 80
frontend_port_end = 81
backend_port = 8080
}

resource "azurerm_lb_probe" "test" {
resource_group_name = azurerm_resource_group.test.name
loadbalancer_id = azurerm_lb.test.id
name = "acctest-lb-probe"
port = 22
protocol = "Tcp"
}

resource "azurerm_lb_rule" "test" {
name = "AccTestLBRule"
resource_group_name = azurerm_resource_group.test.name
loadbalancer_id = azurerm_lb.test.id
probe_id = azurerm_lb_probe.test.id
backend_address_pool_id = azurerm_lb_backend_address_pool.test.id
frontend_ip_configuration_name = "internal"
protocol = "Tcp"
frontend_port = 22
backend_port = 22
}

resource "azurerm_linux_virtual_machine_scale_set" "test" {
name = "acctestvmss-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "Standard_F2"
instances = 1
admin_username = "adminuser"
admin_password = "P@ssword1234!"
health_probe_id = azurerm_lb_probe.test.id

disable_password_authentication = false

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}

data_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
disk_size_gb = 10
lun = 10
}

network_interface {
name = "example"
primary = true

ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.test.id
load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.test.id]
load_balancer_inbound_nat_rules_ids = [azurerm_lb_nat_pool.test.id]
}
}

automatic_instance_repair {
enabled = %[3]t
}

depends_on = [azurerm_lb_rule.test]
}
`, template, data.RandomInteger, enabled)
}
Loading