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

azurerm_windows_virtual_machine_scale_set | azurerm_linux_virtual_machine_scale_set | azurerm_orchestrated_virtual_machine_scale_set - expose the action attribute in the automatic_instance_repair code block #26227

Merged
merged 27 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8cee6b0
Initial Check-in...
WodansSon Jun 4, 2024
a679690
Fix lint errors...
WodansSon Jun 4, 2024
34d5f01
Fix test case steps...
WodansSon Jun 5, 2024
ed60f89
Address PR comment...
WodansSon Jun 5, 2024
9fdc6f6
Remove default value from action and update expand and flatten functi…
WodansSon Jun 6, 2024
822706a
Update documentation...
WodansSon Jun 6, 2024
68a8649
Make otherAutomaticRepairsPolicy test cases consistent across resourc…
WodansSon Jun 6, 2024
3bb3657
terrafmt...
WodansSon Jun 6, 2024
877edb4
Fix tests...
WodansSon Jun 8, 2024
649abef
Update test config...
WodansSon Jun 8, 2024
40f6ebb
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
WodansSon Jun 10, 2024
3016340
Update linux vmms test...
WodansSon Jun 11, 2024
6943fd0
Revert test case change...
WodansSon Jun 11, 2024
ec94f1d
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
WodansSon Jul 16, 2024
22833eb
Progress on 4.0 changes...
WodansSon Jul 19, 2024
a5429aa
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
WodansSon Jul 24, 2024
e6226f1
Fix lint error...
WodansSon Jul 24, 2024
7d1dbcd
Fix normalise doc...
WodansSon Jul 24, 2024
63c422b
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
WodansSon Jul 31, 2024
cf3e451
Revert v4.0 scale_in field to be o+c...
WodansSon Jul 31, 2024
7dcf0b1
Update 'azurerm_public_ip' resources 'sku' fields default value field…
WodansSon Jul 31, 2024
48b91c6
Add default value for automatic_upgrade_enabled field...
WodansSon Aug 1, 2024
cfe52c6
Wrap default values in feature flag...
WodansSon Aug 1, 2024
4180dda
Address PR comments...
WodansSon Aug 3, 2024
aa985a8
Address PR comments...
WodansSon Aug 8, 2024
3c1f910
Update documentation note to be more clear...
WodansSon Aug 8, 2024
20077fa
fix typos in note
stephybun Aug 9, 2024
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 @@ -89,7 +89,7 @@ func dataSourceDiskEncryptionSetRead(d *pluginsdk.ResourceData, meta interface{}
keyVaultURI := props.ActiveKey.KeyUrl
isHSMURI, err, _, _ := managedHsmHelpers.IsManagedHSMURI(env, keyVaultURI)
if err != nil {
return fmt.Errorf("Parshing key vault URI: %+v", err)
return fmt.Errorf("parsing key vault URI: %+v", err)
}
if isHSMURI {
d.Set("managed_hsm_key_id", keyVaultURI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func resourceDiskEncryptionSetUpdate(d *pluginsdk.ResourceData, meta interface{}
func getManagedHsmKeyUrl(ctx context.Context, managedkeyBundleClient *keyvault.BaseClient, managedHsmKeyId string, rotationToLatestKeyVersionEnabled bool, env environments.Environment) (string, error) {
domainSuffix, ok := env.ManagedHSM.DomainSuffix()
if !ok {
return "", fmt.Errorf("Managed HSM is not supported in this Environment")
return "", fmt.Errorf("managed HSM is not supported in this Environment")
}
managedHsmVersionedKey, err := managedHsmParse.ManagedHSMDataPlaneVersionedKeyID(managedHsmKeyId, domainSuffix)
if err == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,16 +502,15 @@ func flattenGalleryApplicationVersionManageAction(input *galleryapplicationversi
}

output := make([]ManageAction, 0)
if input != nil {
obj := ManageAction{
Install: input.Install,
Remove: input.Remove,
}
if input.Update != nil {
obj.Update = *input.Update
}
output = append(output, obj)

obj := ManageAction{
Install: input.Install,
Remove: input.Remove,
}
if input.Update != nil {
obj.Update = *input.Update
}
output = append(output, obj)

return output
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
automaticRepairsPolicyRaw := d.Get("automatic_instance_repair").([]interface{})
automaticRepairsPolicy := ExpandVirtualMachineScaleSetAutomaticRepairsPolicy(automaticRepairsPolicyRaw)

if automaticRepairsPolicy != nil && healthProbeId == "" && !hasHealthExtension {
return fmt.Errorf("`automatic_instance_repair` can only be set if there is an application Health extension or a `health_probe_id` defined")
}

props := virtualmachinescalesets.VirtualMachineScaleSet{
ExtendedLocation: expandEdgeZone(d.Get("edge_zone").(string)),
Location: location,
Expand Down Expand Up @@ -730,7 +734,28 @@ func resourceLinuxVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, meta i

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

if automaticRepairsPolicy != nil {
// we need to know if the VMSS has a health extension or not
hasHealthExtension := false

if v, ok := d.GetOk("extension"); ok {
var err error
_, hasHealthExtension, err = expandOrchestratedVirtualMachineScaleSetExtensions(v.(*pluginsdk.Set).List())
if err != nil {
return err
}
}

_, hasHealthProbeId := d.GetOk("health_probe_id")

if !hasHealthProbeId && !hasHealthExtension {
return fmt.Errorf("`automatic_instance_repair` can only be set if there is an application Health extension or a `health_probe_id` defined")
}
}

updateProps.AutomaticRepairsPolicy = automaticRepairsPolicy
}

if d.HasChange("identity") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
)

func TestAccLinuxVirtualMachineScaleSet_otherBootDiagnostics(t *testing.T) {
Expand Down Expand Up @@ -432,6 +433,10 @@ func TestAccLinuxVirtualMachineScaleSet_otherVMAgentDisabledWithExtensionDisable
}

func TestAccLinuxVirtualMachineScaleSet_otherScaleInPolicy(t *testing.T) {
if features.FourPointOhBeta() {
t.Skipf("Skipped the 'scale_in_policy' property has been deprecated in the 4.0 provider.")
}

data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test")
r := LinuxVirtualMachineScaleSetResource{}

Expand Down Expand Up @@ -541,25 +546,35 @@ func TestAccLinuxVirtualMachineScaleSet_otherTerminationNotificationMigration(t
func TestAccLinuxVirtualMachineScaleSet_otherAutomaticRepairsPolicy(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test")
r := LinuxVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
// turn automatic repair on
{
Config: r.otherAutomaticRepairsPolicyEnabled(data),
Config: r.otherAutomaticRepairsPolicy(data, "Restart"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
{
Config: r.otherAutomaticRepairsPolicyDisabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
{
Config: r.otherAutomaticRepairsPolicy(data, "Reimage"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
// turn automatic repair off
{
Config: r.otherAutomaticRepairsPolicyDisabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
// turn automatic repair on again
{
Config: r.otherAutomaticRepairsPolicyEnabled(data),
Check: acceptance.ComposeTestCheckFunc(
Expand Down Expand Up @@ -2337,7 +2352,6 @@ resource "azurerm_lb" "test" {
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
Expand Down Expand Up @@ -2379,21 +2393,20 @@ resource "azurerm_lb_rule" "test" {
}

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

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 = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

Expand All @@ -2412,7 +2425,6 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
network_interface {
name = "example"
primary = true

ip_configuration {
name = "internal"
primary = true
Expand All @@ -2424,15 +2436,15 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {

automatic_instance_repair {
enabled = true
grace_period = "PT1H"
grace_period = "PT30M"
}

depends_on = [azurerm_lb_rule.test]
}
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineScaleSetResource) otherAutomaticRepairsPolicyDisabled(data acceptance.TestData) string {
func (r LinuxVirtualMachineScaleSetResource) otherAutomaticRepairsPolicy(data acceptance.TestData, action string) string {
return fmt.Sprintf(`
%[1]s

Expand All @@ -2450,7 +2462,6 @@ resource "azurerm_lb" "test" {
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
Expand Down Expand Up @@ -2492,21 +2503,19 @@ resource "azurerm_lb_rule" "test" {
}

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

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 = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

Expand All @@ -2525,7 +2534,6 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
network_interface {
name = "example"
primary = true

ip_configuration {
name = "internal"
primary = true
Expand All @@ -2535,6 +2543,104 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
}
}

automatic_instance_repair {
enabled = true
grace_period = "PT30M"
action = "%[3]s"
}

depends_on = [azurerm_lb_rule.test]
}
`, r.template(data), data.RandomInteger, action)
}

func (r LinuxVirtualMachineScaleSetResource) otherAutomaticRepairsPolicyDisabled(data acceptance.TestData) string {
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"
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" {
loadbalancer_id = azurerm_lb.test.id
name = "acctest-lb-probe"
port = 22
protocol = "Tcp"
}
resource "azurerm_lb_rule" "test" {
name = "AccTestLBRule"
loadbalancer_id = azurerm_lb.test.id
probe_id = azurerm_lb_probe.test.id
backend_address_pool_ids = [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 = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r LinuxVirtualMachineScaleSetResource) template(data acceptance.TestData)
%s

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-vmss-%d"
location = "%s"
}

Expand All @@ -70,7 +70,7 @@ func (r LinuxVirtualMachineScaleSetResource) templateWithLocation(data acceptanc
%s

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-vmss-%d"
location = "%s"
}

Expand Down
Loading
Loading