简体   繁体   English

如何为 VM 资源 azurerm_virtual_machine_scale_set 的每个实例执行具有不同参数的脚本?

[英]How can I execute a script with different params for each instance of the VM resource azurerm_virtual_machine_scale_set?

After terraform apply it creates an azurerm_virtual_machine_scale_set resource with N instances, but then I need to execute some script with different params for each VM instance.在 terraform apply 之后,它会创建一个带有 N 个实例的 azurerm_virtual_machine_scale_set 资源,但随后我需要为每个 VM 实例执行一些具有不同参数的脚本。 Could you please help me with this issue?你能帮我解决这个问题吗? Thanks a lot!非常感谢!

For your issue, I think you should be better to take a knowledge of the Azure VM Scale Set.对于您的问题,我认为您最好了解 Azure VM 规模集。 Generally, scale sets are useful for deploying the highly available infrastructure where a set of machines has the similar configuration.通常,规模集对于部署具有相似配置的一组机器的高可用性基础架构很有用。

There are some features are only available in scale sets while other features are only available in VMs.有些功能仅在规模集中可用,而其他功能仅在 VM 中可用。 See When to use scale sets instead of virtual machines?请参阅何时使用规模集而不是虚拟机? So you should think about which service that you really want.所以你应该考虑一下你真正想要哪种服务。

Also, take a look at the Argument of VM scale set that you can set in Terraform.此外,请查看您可以在 Terraform 中设置的 VM 规模集的参数 You just can set the extension to execute the script in the scale set, but it seems the extension would apply to the whole scale set not the individual instance with different parameters.您只需设置扩展以执行规模集中的脚本,但似乎扩展将应用于整个规模集,而不是具有不同参数的单个实例。 Hope this helps.希望这可以帮助。

you can just use a loop to create multiple copies of anything in terraform:您可以使用循环在 terraform 中创建任何内容的多个副本:

resource "azurerm_virtual_machine" "vm" {
  name                             = "${var.reference["name"]}-${var.vmName}-vm-${count.index}"
  location                         = "${var.reference["location"]}"
  resource_group_name              = "${var.reference["name"]}"
  network_interface_ids            = ["${element(azurerm_network_interface.nic.*.id, count.index)}"]
  vm_size                          = "Standard_B1ms"
  availability_set_id              = "${azurerm_availability_set.av.id}"
  delete_os_disk_on_termination    = true
  delete_data_disks_on_termination = true
  count                            = "${var.reference["${var.vmName}Count"]}"

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

  storage_os_disk {
    name              = "${var.reference["name"]}-${var.vmName}-vm-${count.index}-osDisk"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }

  os_profile {
    computer_name  = "${var.reference["name"]}-${var.vmName}-vm-${count.index}"
    admin_username = "${var.reference["name"]}"
    admin_password = "!Q2w3e4r5t6y"
  }

  os_profile_linux_config {
    disable_password_authentication = false
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将exisintg Linux VM克隆到Azure中的规模集 - How can I clone an exisintg Linux VM to a scale set in Azure 如何在虚拟机规模集中使用 terraform 请求 azure 现场实例? - How do I request azure spot instances using terraform, in a virtual machine scale set? 如何在虚拟机(VM)中崩溃/注入故障? - How to crash/inject fault in a Virtual Machine(VM)? 如何在虚拟机上将Jboss作为守护程序运行? - How can I run Jboss as a daemon on a virtual machine? 虚拟规模集升级时自定义脚本扩展失败 - Custom Script Extension failing on Virtual Scale Set upgrade 如何检测脚本是否在虚拟机上运行? - How to detect if the script is running on a virtual machine? 如何使用Java在远程计算机上执行Linux命令? - How can I execute Linux commands on a remote machine using Java? 如何在脚本中执行grep? - How Can i Execute grep in a Script? 如何在远程计算机上异步执行bash脚本 - How to execute bash script on a remote machine asynchronously 我想在启动时执行脚本(.sh文件),以便可以设置鼠标的灵敏度。 我怎样才能做到这一点? - I want to execute a script (.sh file) on startup so that I can set the sensitivity of my mouse. How can I do this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM