如何在虚拟机比例尺集中使用terraform请求天蓝色竞价型实例? [英] How do I request azure spot instances using terraform, in a virtual machine scale set?
问题描述
如果我提出的问题不好,请提前道歉,但我希望在Linux vmss的环境中为请求现货实例提供一些帮助.
这里是参考:
这是他们的示例json,没有任何说明可选参数的位置:
资源"azurerm_linux_virtual_machine_scale_set";示例"{名称="example-vmss"resource_group_name = azurerm_resource_group.example.name位置= azurerm_resource_group.example.locationsku ="Standard_F2";实例= 1admin_username =" adminuser"admin_ssh_key {用户名="adminuser"public_key = file(〜/.ssh/id_rsa.pub")}source_image_reference {发布者=规范"offer ="UbuntuServer"sku ="16.04-LTS";版本=最新"}os_disk {storage_account_type ="Standard_LRS";缓存="ReadWrite";}network_interface {名称=示例"小学=真ip_configuration {名称=内部"小学=真subnet_id = azurerm_subnet.internal.id}}}
我想将以下两行放在某处:
priority = var.spot_priorityeviction_policy = var.spot_eviction_policy
但是当我将它们放在顶层时,会出现此错误:
错误:预期优先级为[低常规]之一,获得竞价
(显然,我已经在 terraform.tfvars
我尝试将它们插入各种块中,但是它们给了我意外的参数错误.
我在哪里告诉terraform我想要竞价型实例?
通过传递"Low"来解决该问题.而不是现货"在vmss资源的顶层.
我还使用 azurerm_linux_virtual_machine_scale_set
提供并添加 priority
和 eviction_policy 的示例像这样的代码:
资源"azurerm_linux_virtual_machine_scale_set";示例"{名称="example-vmss"resource_group_name = azurerm_resource_group.example.name位置= azurerm_resource_group.example.locationsku ="Standard_F2";实例= 1admin_username =" adminuser"优先级=现货"eviction_policy =取消分配";admin_ssh_key {用户名="adminuser"public_key = file(〜/.ssh/id_rsa.pub")}source_image_reference {发布者=规范"offer ="UbuntuServer"sku ="16.04-LTS";版本=最新"}os_disk {storage_account_type ="Standard_LRS";缓存="ReadWrite";}network_interface {名称=示例"小学=真ip_configuration {名称=内部"小学=真subnet_id = azurerm_subnet.internal.id}}}
它工作正常.当我尝试进行规划时,它会显示:
我使用Terraform版本0.12.19和Azurerm版本2.20.因此,您可以使用与我相同的版本,然后重试.
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.
Here is the reference: 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:
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
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??
EDIT: The problem is solved by passing in "Low" rather than "Spot" in the top level of the vmss resource.
I also use the example that azurerm_linux_virtual_machine_scale_set
provide and add the priority
and eviction_policy
like this:
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. So you can use the same version as mine and try again.
这篇关于如何在虚拟机比例尺集中使用terraform请求天蓝色竞价型实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!