[英]Creating Azure Spot Instances with Terraform
I'm trying to create an Azure spot instance with Terraform.我正在尝试使用 Terraform 创建一个 Azure 现货实例。 I saw this discussion How do I request azure spot instances using terraform, in a virtual machine scale set?
我看到了这个讨论How do I request azure spot instances using terraform, in a virtual machine scale set?
I still couldn't figure out how provision Azure spot instances with terraform.我仍然无法弄清楚如何使用 terraform 提供 Azure 现货实例。 Then I found this repo https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/vm-scale-set/linux
然后我发现了这个仓库 https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/vm-scale-set/linux
I used the examples from the repo to come up with my own terraform code.我使用 repo 中的示例提出了我自己的 terraform 代码。 I pushed it to gitlab here's the link.. https://gitlab.com/cloud-projectz/azure-spot-terraform.git
我把它推到 gitlab 这是链接.. https://gitlab.com/cloud-projectz/azure-spot-terraform.git
Basically what I'm trying to achieve is the creation of a spot instance or spot instances with public ip and ssh access while automating network security rules.基本上,我想要实现的是创建一个或多个具有公共 ip 和 ssh 访问权限的现场实例,同时自动化网络安全规则。 When I run terraform apply everything seems to go okay.
当我运行 terraform 应用一切似乎 go 好。 Then I notice that the public IP is not attached to the spot vm.!
然后我注意到public IP 没有附加到现货vm。! I can't figure out how to access the spot vm!!
我不知道如何访问现场虚拟机! there's also a bash script in the repo that kind of outlines what I attend to accomplish with terraform.
在 repo 中还有一个 bash 脚本概述了我使用 terraform 完成的任务。
Anybody help me with this?有人帮我解决这个问题吗? Azure spot vm via terraform with public ip and ssh access?
Azure 通过 terraform 使用公共 ip 和 Z1787D7646304C53D987CF4EZA 访问?
Thank You谢谢你
Regarding the issue, please refer to the following script关于这个问题,请参考以下脚本
provider "azurerm" {
version = "~>2.0"
features {}
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "East Asia"
}
resource "azurerm_virtual_network" "example" {
name = "example-network"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_network_security_group" "example" {
name = "allow-ssh"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "<IP address>"
destination_address_prefix = "*"
}
}
resource "azurerm_public_ip_prefix" "example" {
name = "example-pip"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
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 = "azure"
eviction_policy = "Deallocate"
priority = "Spot"
max_bid_price = 0.5
admin_ssh_key {
username = "azure"
public_key = file("/root/.ssh/Azure.pub")
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
network_interface {
name = "interface"
primary = true
network_security_group_id= azurerm_network_security_group.example.id
ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.internal.id
public_ip_address {
name = "first"
public_ip_prefix_id = azurerm_public_ip_prefix.example.id
}
}
}
os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.