[英]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.