Terraform - 在 Azure 上提供静态 IP 地址 [英] Terraform - provision static ip addresses on Azure

查看:37
本文介绍了Terraform - 在 Azure 上提供静态 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Terraform 有一段时间了,并且对 VMware 和 Azure 提供商的使用感到满意.

目前我需要使用静态 IP 地址在 Azure 中配置 VM.试图说服他们摆脱静电,但我用了安全锤,我无法偏转.

虽然我可以在子网中分配一些并将它们提供给 Terraform(我使用 ansible 来驱动 Terraform),但我想知道是否还有其他人在 Azure 中解决了这个问题并且可能有好的想法.

在我看来,主要问题是并发性.我需要一种方法来原子地分配"子网中的 IP,并确保即使构建 VM 并开始使用该地址需要一段时间,也不会同时运行的其他配置请求得到相同的请求.

在私有数据中心,我会使用 IPAM 解决方案.在 Azure 中,我没有可用的.寻找使用 Azure+Terraform+Ansible 严格实施的想法

解决方案

实现此目的的一种方法是在 Terraform 中使用 cidrhost 插值.

您可以使用它每次创建相同的私有 IP 地址.一个例子如下:

资源azurerm_network_interface"network_interface"{名称 = "开发网络接口"location = "西欧"resource_group_name = "dev-rg"ip_configuration {name = "dev-nic-ipconfig"subnet_id = "${subnet_id}"private_ip_address_allocation = "静态"private_ip_address = "${cidrhost(10.100.0.56/27, 4)}"public_ip_address_id = "${publicip_id}"}

上面的例子应该给你一个 10.100.0.60 的私有 IP

I've been using Terraform for some time and am comfortable with its use with VMware and Azure providers.

Currently I have a requirement to provision VMs in Azure with static IP addresses. Tried to talk them out of static, but a Security hammer was used on me that I cannot deflect.

While I can allocate some in a subnet and provide them to Terraform (i use ansible to drive Terraform), i wondered if anyone else had tackled this problem in Azure and might have good ideas.

As i see it, the main problem is concurrency. I need a way to atomically "allocate" an IP in a subnet and be sure that even if it takes a while for a VM to be built and start using that address, no other provisioning request running concurrently will get the same one.

In a private datacenter I would use an IPAM solution. In Azure I do not have one available. Looking for ideas at implementing strictly with Azure+Terraform+Ansible

解决方案

One way of achieving this is by using the cidrhost interpolation within Terraform.

You can use it to create the same private IP address each time. One example of this could be as follows:

resource "azurerm_network_interface" "network_interface" {
name                = "dev-network-interface"
location            = "WestEurope"
resource_group_name = "dev-rg"

ip_configuration {
name                          = "dev-nic-ipconfig"
subnet_id                     = "${subnet_id}"
private_ip_address_allocation = "static"
private_ip_address            = "${cidrhost(10.100.0.56/27, 4)}"
public_ip_address_id          = "${publicip_id}"
}

The above example should give you a private IP of 10.100.0.60

这篇关于Terraform - 在 Azure 上提供静态 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆