[英]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
提供的示例,并像这样添加priority
和eviction_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.