Skip to content

Commit

Permalink
r\linux_virtual_machine_scale_set `r\windows_virtual_machine_scale_…
Browse files Browse the repository at this point in the history
…set`: Rename `terminate_notification` to `termination_notification`
  • Loading branch information
myc2h6o committed Feb 28, 2022
1 parent 634f9d4 commit 1fcf5bf
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,32 +399,51 @@ func TestAccLinuxVirtualMachineScaleSet_otherScaleInPolicy(t *testing.T) {
})
}

func TestAccLinuxVirtualMachineScaleSet_otherTerminateNotification(t *testing.T) {
func TestAccLinuxVirtualMachineScaleSet_otherTerminationNotification(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test")
r := LinuxVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
// turn terminate notification on
{
Config: r.otherTerminateNotification(data, true),
Config: r.otherTerminationNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("terminate_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("terminate_notification.0.enabled").HasValue("true"),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("true"),
),
},
data.ImportStep("admin_password"),
// turn terminate notification off
{
Config: r.otherTerminateNotification(data, false),
Config: r.otherTerminationNotification(data, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("terminate_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("terminate_notification.0.enabled").HasValue("false"),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("false"),
),
},
data.ImportStep("admin_password"),
// turn terminate notification on again
{
Config: r.otherTerminationNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("true"),
),
},
data.ImportStep("admin_password"),
})
}

// TODO remove TestAccLinuxVirtualMachineScaleSet_otherTerminationNotificationMigration in 3.0
func TestAccLinuxVirtualMachineScaleSet_otherTerminationNotificationMigration(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test")
r := WindowsVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
// old: terminate_notification
{
Config: r.otherTerminateNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -434,6 +453,16 @@ func TestAccLinuxVirtualMachineScaleSet_otherTerminateNotification(t *testing.T)
),
},
data.ImportStep("admin_password"),
// new: termination_notification
{
Config: r.otherTerminationNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("true"),
),
},
data.ImportStep("admin_password"),
})
}

Expand Down Expand Up @@ -1847,6 +1876,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
`, r.template(data), data.RandomInteger)
}

// TODO remove otherTerminateNotification in 3.0
func (r LinuxVirtualMachineScaleSetResource) otherTerminateNotification(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -1893,6 +1923,52 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
`, r.template(data), data.RandomInteger, enabled)
}

func (r LinuxVirtualMachineScaleSetResource) otherTerminationNotification(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%s
resource "azurerm_linux_virtual_machine_scale_set" "test" {
name = "acctestvmss-%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!"
disable_password_authentication = false
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
os_disk {
disk_size_gb = 30
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}
network_interface {
name = "example"
primary = true
ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.test.id
}
}
termination_notification {
enabled = %t
}
}
`, r.template(data), data.RandomInteger, enabled)
}

func (r LinuxVirtualMachineScaleSetResource) otherAutomaticRepairsPolicy(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%[1]s
Expand Down Expand Up @@ -2045,7 +2121,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
}
}
terminate_notification {
termination_notification {
enabled = %t
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ func resourceLinuxVirtualMachineScaleSet() *pluginsdk.Resource {
}, false),
},

// TODO remove terminate_notification in 3.0
"terminate_notification": VirtualMachineScaleSetTerminateNotificationSchema(),

"termination_notification": VirtualMachineScaleSetTerminationNotificationSchema(),

"zones": func() *schema.Schema {
if !features.ThreePointOhBeta() {
return azure.SchemaZones()
Expand Down Expand Up @@ -525,10 +528,15 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
return fmt.Errorf("an `eviction_policy` must be specified when `priority` is set to `Spot`")
}

// TODO remove terminate_notification in 3.0
if v, ok := d.GetOk("terminate_notification"); ok {
virtualMachineProfile.ScheduledEventsProfile = ExpandVirtualMachineScaleSetScheduledEventsProfile(v.([]interface{}))
}

if v, ok := d.GetOk("termination_notification"); ok {
virtualMachineProfile.ScheduledEventsProfile = ExpandVirtualMachineScaleSetScheduledEventsProfile(v.([]interface{}))
}

scaleInPolicy := d.Get("scale_in_policy").(string)
automaticRepairsPolicyRaw := d.Get("automatic_instance_repair").([]interface{})
automaticRepairsPolicy := ExpandVirtualMachineScaleSetAutomaticRepairsPolicy(automaticRepairsPolicyRaw)
Expand Down Expand Up @@ -831,11 +839,17 @@ func resourceLinuxVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, meta i
}
}

// TODO remove terminate_notification in 3.0
if d.HasChange("terminate_notification") {
notificationRaw := d.Get("terminate_notification").([]interface{})
updateProps.VirtualMachineProfile.ScheduledEventsProfile = ExpandVirtualMachineScaleSetScheduledEventsProfile(notificationRaw)
}

if d.HasChange("termination_notification") {
notificationRaw := d.Get("termination_notification").([]interface{})
updateProps.VirtualMachineProfile.ScheduledEventsProfile = ExpandVirtualMachineScaleSetScheduledEventsProfile(notificationRaw)
}

if d.HasChange("encryption_at_host_enabled") {
updateProps.VirtualMachineProfile.SecurityProfile = &compute.SecurityProfile{
EncryptionAtHost: utils.Bool(d.Get("encryption_at_host_enabled").(bool)),
Expand Down Expand Up @@ -1080,12 +1094,19 @@ func resourceLinuxVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta int
d.Set("health_probe_id", healthProbeId)
}

// TODO remove terminate_notification in 3.0
if scheduleProfile := profile.ScheduledEventsProfile; scheduleProfile != nil {
if err := d.Set("terminate_notification", FlattenVirtualMachineScaleSetScheduledEventsProfile(scheduleProfile)); err != nil {
return fmt.Errorf("setting `terminate_notification`: %+v", err)
}
}

if scheduleProfile := profile.ScheduledEventsProfile; scheduleProfile != nil {
if err := d.Set("termination_notification", FlattenVirtualMachineScaleSetScheduledEventsProfile(scheduleProfile)); err != nil {
return fmt.Errorf("setting `termination_notification`: %+v", err)
}
}

extensionProfile, err := flattenVirtualMachineScaleSetExtensions(profile.ExtensionProfile, d)
if err != nil {
return fmt.Errorf("failed flattening `extension`: %+v", err)
Expand Down
28 changes: 28 additions & 0 deletions internal/services/compute/virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,33 @@ func FlattenVirtualMachineScaleSetRollingUpgradePolicy(input *compute.RollingUpg
}
}

// TODO remove VirtualMachineScaleSetTerminateNotificationSchema in 3.0
func VirtualMachineScaleSetTerminateNotificationSchema() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Deprecated: "`terminate_notification` has been renamed to `termination_notification` and will be removed in 3.0.",
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"enabled": {
Type: pluginsdk.TypeBool,
Required: true,
},
"timeout": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: azValidate.ISO8601Duration,
Default: "PT5M",
},
},
},
ConflictsWith: []string{"termination_notification"},
}
}

func VirtualMachineScaleSetTerminationNotificationSchema() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
Expand All @@ -1418,6 +1444,8 @@ func VirtualMachineScaleSetTerminateNotificationSchema() *pluginsdk.Schema {
},
},
},
// TODO remove ConflictsWith in 3.0
ConflictsWith: []string{"terminate_notification"},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,32 +516,51 @@ func TestAccWindowsVirtualMachineScaleSet_otherScaleInPolicy(t *testing.T) {
})
}

func TestAccWindowsVirtualMachineScaleSet_otherTerminateNotification(t *testing.T) {
func TestAccWindowsVirtualMachineScaleSet_otherTerminationNotification(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test")
r := WindowsVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
// turn terminate notification on
{
Config: r.otherTerminateNotification(data, true),
Config: r.otherTerminationNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("terminate_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("terminate_notification.0.enabled").HasValue("true"),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("true"),
),
},
data.ImportStep("admin_password"),
// turn terminate notification off
{
Config: r.otherTerminateNotification(data, false),
Config: r.otherTerminationNotification(data, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("terminate_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("terminate_notification.0.enabled").HasValue("false"),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("false"),
),
},
data.ImportStep("admin_password"),
// turn terminate notification on again
{
Config: r.otherTerminationNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("true"),
),
},
data.ImportStep("admin_password"),
})
}

// TODO remove TestAccWindowsVirtualMachineScaleSet_otherTerminationNotificationMigration in 3.0
func TestAccWindowsVirtualMachineScaleSet_otherTerminationNotificationMigration(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test")
r := WindowsVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
// old: terminate_notification
{
Config: r.otherTerminateNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -551,6 +570,16 @@ func TestAccWindowsVirtualMachineScaleSet_otherTerminateNotification(t *testing.
),
},
data.ImportStep("admin_password"),
// new: termination_notification
{
Config: r.otherTerminationNotification(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("termination_notification.#").HasValue("1"),
check.That(data.ResourceName).Key("termination_notification.0.enabled").HasValue("true"),
),
},
data.ImportStep("admin_password"),
})
}

Expand Down Expand Up @@ -2284,6 +2313,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" {
`, r.template(data))
}

// TODO remove otherTerminateNotification in 3.0
func (r WindowsVirtualMachineScaleSetResource) otherTerminateNotification(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -2327,6 +2357,49 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" {
`, r.template(data), enabled)
}

func (r WindowsVirtualMachineScaleSetResource) otherTerminationNotification(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%s
resource "azurerm_windows_virtual_machine_scale_set" "test" {
name = local.vm_name
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!"
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}
network_interface {
name = "example"
primary = true
ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.test.id
}
}
termination_notification {
enabled = %t
}
}
`, r.template(data), enabled)
}

func (r WindowsVirtualMachineScaleSetResource) otherAutomaticRepairsPolicy(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%[1]s
Expand Down Expand Up @@ -2476,7 +2549,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" {
}
}
terminate_notification {
termination_notification {
enabled = %t
}
}
Expand Down
Loading

0 comments on commit 1fcf5bf

Please sign in to comment.