Azure + Terraform和多个堡垒实例

时间:2017-12-12 02:19:07

标签: azure terraform terraform-provider-azure

想知道,如果可以使用Terraform在Azure上设置多个Bastion服务器+可用性集。我想在给定的可用性集中枚举堡垒节点,但不想使用负载均衡器。任何一个例子,可以分享吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

回答我的问题:

是的,可以有多个具有公共IP地址的堡垒节点。

示例配置:

档案:nic.tf

resource "azurerm_network_interface" "bastion_nic" {   name           
= "bastionnic${count.index + 1}"   location                  = "${azurerm_resource_group.rg.location}"   resource_group_name       = "${azurerm_resource_group.rg.name}"   network_security_group_id = "${azurerm_network_security_group.broker_nsg.id}"   count             
= "${var.bastion_instance_count}"

  ip_configuration {
    name                          = "bastionip${count.index + 1}"
    subnet_id                     = "${azurerm_subnet.broker_subnet.id}"
    private_ip_address_allocation = "Dynamic"
    public_ip_address_id          = "${element(azurerm_public_ip.bastion_pip.*.id, count.index + 1)}"    } }

档案:ip.tf

resource "azurerm_public_ip" "bastion_pip" {
  name                         = "bastionpip${ count.index + 1}"
  resource_group_name          = "${azurerm_resource_group.rg.name}"
  location                     = "${azurerm_resource_group.rg.location}"
  public_ip_address_allocation = "Static"
  domain_name_label            = "${var.kafka_cluster_prefix}-bastion${ count.index + 1}"
  count                          = "${var.bastion_instance_count}"
}

文件:bastion.tf

resource "azurerm_virtual_machine" "bastion" {
  name                             = "bastion${count.index + 1}"
  count                            = "${var.bastion_instance_count}"
  location                         = "${azurerm_resource_group.rg.location}"
  availability_set_id              = "${azurerm_availability_set.bastion.id}"
  resource_group_name              = "${azurerm_resource_group.rg.name}"
  network_interface_ids            = ["${element(azurerm_network_interface.bastion_nic.*.id, count.index + 1)}"]
  vm_size                          = "${var.bastion_vm_size}"
  delete_os_disk_on_termination    = true
  delete_data_disks_on_termination = true
}

文件:availability.tf

resource "azurerm_availability_set" "bastion" {
  name                = "bastionavailabilityset"
  managed             = "true"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  location            = "${azurerm_resource_group.rg.location}"
}

如果您按照示例操作,则可以在可用性集中部署具有公共IP地址的多个堡垒节点。您需要定义以下内容:

variables.tf

中的

变量“bastion_instance_count

干杯。如果你需要帮助,请给我打电话。