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

Azure virtual machine scale set interfaces are not being created and attached in the order #8154

Closed
lemontea1011 opened this issue Aug 18, 2020 · 2 comments
Labels
bug service/vmss Virtual Machine Scale Sets

Comments

@lemontea1011
Copy link

lemontea1011 commented Aug 18, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.12.28
azurerm_v2.23

Affected Resource(s)

azurerm_virtual_machine_scale_set

Terraform Configuration Files

resource "azurerm_virtual_machine_scale_set" "vtps_vmss" {
  name                = "vmss-${random_string.random.result}"
  location            = var.location
  resource_group_name = var.resource_group
  upgrade_policy_mode = "Manual"
  overprovision       = false

  identity {
    type = "SystemAssigned"
  }

  sku {
    name     = var.np_vm_size
    tier     = "Standard"
    capacity = 1
  }

  storage_profile_image_reference {
    id = var.vtps_image_id
  }

  storage_profile_os_disk {
    name              = ""
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }

  storage_profile_data_disk {
    lun           = 0
    caching       = "ReadWrite"
    create_option = "Empty"
    disk_size_gb  = 10
  }

  os_profile {
    computer_name_prefix = "vtps-${random_string.random.result}"
    admin_username       = var.username
    custom_data = data.template_file.cloudconfig.rendered
  }

  os_profile_linux_config {
    disable_password_authentication = true

    ssh_keys {
      path     = "/home/${var.username}/.ssh/authorized_keys"
      key_data = var.public_ssh_key
    }
  }

  boot_diagnostics {
    enabled     = "true"
    storage_uri = var.boot_diagnostics_uri
  }

  network_profile {
    name                      = "mgmtnetworkprofile-${random_string.random.result}"
    primary                   = true
    network_security_group_id = azurerm_network_security_group.np_mgmt.id

    ip_configuration {
      name      = "Management-${random_string.random.result}"
      subnet_id = azurerm_subnet.managementsubnet.id
      primary   = true
    }
  }

  network_profile {
    name                      = "dataportaprofile-${random_string.random.result}"
    primary                   = false
    accelerated_networking    = true
    ip_forwarding             = true
    network_security_group_id = azurerm_network_security_group.data_port_subnets_sg.id

    ip_configuration {
      name      = "DataA-${random_string.random.result}"
      subnet_id = azurerm_subnet.dataporta.id
      primary   = true
      # add portA to backend pool of load balancer
      load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.loadbalancer.id]
    }
  }

  network_profile {
    name                      = "dataportbprofile-${random_string.random.result}"
    primary                   = false
    accelerated_networking    = true
    ip_forwarding             = true
    network_security_group_id = azurerm_network_security_group.data_port_subnets_sg.id

    ip_configuration {
      name      = "DataB-${random_string.random.result}"
      subnet_id = azurerm_subnet.dataportb.id
      primary   = true
    }
  }
}

Debug Output

Panic Output

Expected Behavior

In above code, I've set up 3 network interfaces for VMSS.
Network interfaces should be set up in the order same as the order of VMSS's network_profile in main.tf.

Actual Behavior

Network interfaces will be generated randomly in creating VMSS.
Can be verified by Azure portal > VMSS > Networking
Above page will show all network interfaces by sequence. Every time Terraform is executed, there will be different sequence.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

This issue also existed in creating VM, please refer to
#99
#426

The above PR only fixed the issue in creating VM. Same method should also fixed this issue, I've tested and verified.

diff --git a/azurerm/internal/services/compute/virtual_machine_scale_set_resource.go b/azurerm/internal/services/compute/virtual_machine_scale_set_resource.go
index ebfcb8429..738a9a3b4 100644
--- a/azurerm/internal/services/compute/virtual_machine_scale_set_resource.go
+++ b/azurerm/internal/services/compute/virtual_machine_scale_set_resource.go
@@ -389,7 +389,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
 
 			// lintignore:S018
 			"network_profile": {
-				Type:     schema.TypeSet,
+				Type:     schema.TypeList,
 				Required: true,
 				Elem: &schema.Resource{
 					Schema: map[string]*schema.Schema{
@@ -523,7 +523,6 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
 						},
 					},
 				},
-				Set: resourceArmVirtualMachineScaleSetNetworkConfigurationHash,
 			},
 
 			"boot_diagnostics": {
@@ -1743,7 +1742,7 @@ func expandAzureRmRollingUpgradePolicy(d *schema.ResourceData) *compute.RollingU
 }
 
 func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *compute.VirtualMachineScaleSetNetworkProfile {
-	scaleSetNetworkProfileConfigs := d.Get("network_profile").(*schema.Set).List()
+	scaleSetNetworkProfileConfigs := d.Get("network_profile").([]interface{})
 	networkProfileConfig := make([]compute.VirtualMachineScaleSetNetworkConfiguration, 0, len(scaleSetNetworkProfileConfigs))
 
 	for _, npProfileConfig := range scaleSetNetworkProfileConfigs {
@mybayern1974 mybayern1974 added the service/vmss Virtual Machine Scale Sets label Aug 18, 2020
@tombuildsstuff
Copy link
Contributor

hi @lemontea1011

Thanks for opening this issue.

At this point in time the azurerm_virtual_machine and azurerm_virtual_machine_scale_set resources have been superseded by the azurerm_(linux|windows)_virtual_machine and azurerm_(linux|windows)_virtual_machine_scale_set resources and are feature-frozen to maintain compatibility.

Taking a look through the new resources, it appears these use a List instead of a Set so this appears to be fixed there - however it appears that you'd be blocked from adopting these new resources by #6117 (which whilst states just the VM resource, is tracking this for the new VMSS resources too).

As this functionality is available in the new resources I'm going to close this issue for the moment - however I'd recommend subscribing to #6117 to confirm when data disks are supported on these resources which'll unblock you here.

Thanks!

@ghost
Copy link

ghost commented Sep 17, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug service/vmss Virtual Machine Scale Sets
Projects
None yet
Development

No branches or pull requests

4 participants