简体   繁体   English

如何在虚拟机规模集中使用 terraform 请求 azure 现场实例?

[英]How do I request azure spot instances using terraform, in a virtual machine scale set?

Apologies in advance if I'm posing the question poorly, but I'd appreciate some help requesting spot instances in the context of a linux vmss.如果我提出的问题很糟糕,请提前道歉,但我会很感激在 linux vmss 的上下文中请求现场实例的一些帮助。

Here is the reference: https://www.terraform.io/docs/providers/azurerm/r/linux_virtual_machine_scale_set.html#identity这是参考: https://www.terraform.io/docs/providers/azurerm/r/linux_virtual_machine_scale_set.html#identity

and the relevant piece of it:及其相关部分:

在此处输入图像描述

And here is their example json, without any indication of where the optional arguments go:这是他们的示例 json,没有任何指示可选 arguments go 的位置:

resource "azurerm_linux_virtual_machine_scale_set" "example" {
  name                = "example-vmss"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku                 = "Standard_F2"
  instances           = 1
  admin_username      = "adminuser"

  admin_ssh_key {
    username   = "adminuser"
    public_key = file("~/.ssh/id_rsa.pub")
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    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.internal.id
    }
  }
}

I want to put the following two lines somewhere:我想将以下两行放在某处:

priority            = var.spot_priority
eviction_policy     = var.spot_eviction_policy

but when I put them at the top level, I get this error:但是当我把它们放在顶层时,我得到了这个错误:

Error: expected priority to be one of [Low Regular], got Spot

(obviously I've got it set to "Spot" in the terraform.tfvars (显然我在terraform.tfvars其设置为“Spot”

I've tried inserting them in various blocks, but they give me unexpected argument errors.我尝试将它们插入到不同的块中,但它们给了我意想不到的参数错误。

Where do I tell terraform that I want spot instances??我在哪里告诉 terraform 我想要现场实例?

EDIT: The problem is solved by passing in "Low" rather than "Spot" in the top level of the vmss resource.编辑:通过在 vmss 资源的顶层传入“Low”而不是“Spot”来解决问题。

I also use the example that azurerm_linux_virtual_machine_scale_set provide and add the priority and eviction_policy like this:我还使用了azurerm_linux_virtual_machine_scale_set提供的示例,并像这样添加priorityeviction_policy

resource "azurerm_linux_virtual_machine_scale_set" "example" {
  name                = "example-vmss"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku                 = "Standard_F2"
  instances           = 1
  admin_username      = "adminuser"

  priority = "Spot"
  eviction_policy = "Deallocate"

  admin_ssh_key {
    username   = "adminuser"
    public_key = file("~/.ssh/id_rsa.pub")
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    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.internal.id
    }
  }
}

And it works fine.它工作正常。 When I try to plan it, it shows:当我尝试计划它时,它显示:

在此处输入图像描述

I use the Terraform version 0.12.19 and the azurerm version 2.20.我使用 Terraform 版本 0.12.19 和 azurerm 版本 2.20。 So you can use the same version as mine and try again.所以你可以使用与我相同的版本,然后再试一次。

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

相关问题 如何为 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? 如何将exisintg Linux VM克隆到Azure中的规模集 - How can I clone an exisintg Linux VM to a scale set in Azure 如何将文件从本地计算机传输到Azure容器内的虚拟文件夹(使用blobxfer) - How to transfer files from local machine to virtual folders within an Azure container (using blobxfer) 如何使用Azure Powershell脚本从ubuntu虚拟机下载文件 - How to download a file from ubuntu virtual machine using Azure powershell script 使用Python在Azure中从磁盘创建Linux虚拟机 - Creating a linux virtual machine from disk in azure using python 使用适用于Linux的Azure命令行工具创建虚拟机 - Creating a Virtual machine using Azure command line tool for linux 如何在Azure中连接到在Linux虚拟机上运行的mysql服务器 - how to connect to a mysql server running on a linux virtual machine in azure Azure上的Linux虚拟机 - 如何应用IP限制 - Linux Virtual Machine at Azure - how to apply IP restriction 如何判断连接到Azure虚拟机的磁盘是否已加密? - How to tell if a disk attached to an Azure Virtual Machine is encrypted? 从 Linux 虚拟机如何检测/识别 Azure 平台 - From Linux Virtual machine how to detect/identify Azure platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM