在Terraform中添加多种变量类型?

发布于 2025-01-31 08:53:02 字数 475 浏览 4 评论 0原文

我想添加多个IP地址以在Azure中为App Service配置访问限制,并且仅在几个环境中才能实现这一目标,我使用动态块来实现此目的,只要只有一个IP,但是现在我想允许更多的IP地址,有没有办法实现这一目标?

dynamic "ip_restriction" {
  for_each = var.ip_addresses
   content {
     ip_address = ip_restriction.value["ip_address"]
     priority   = ip_restriction.value["priority"]
     name       = ip_restriction.value["name"]
   }
 }

这很完美,但我也想添加环境限制。类似

for_each = var.env == "dev" || var.env == "qa" ? [1] : []

I want to add multiple ip addresses to configure access restrictions in azure for an app service and also this should be accomplished only for a few environments, I'm using the dynamic block to achieve this, it was working as long as there was only one IP, but now I want to allow more ip addresses, is there a way to achieve this?

dynamic "ip_restriction" {
  for_each = var.ip_addresses
   content {
     ip_address = ip_restriction.value["ip_address"]
     priority   = ip_restriction.value["priority"]
     name       = ip_restriction.value["name"]
   }
 }

This works perfect but I want to add the environment restriction as well. something like

for_each = var.env == "dev" || var.env == "qa" ? [1] : []

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜无邪 2025-02-07 08:53:02

这很好,但我想将环境限制添加为
好。

您真的很接近,您只需要更改此数组:[1]即可成为IP地址的实际数组,例如:

for_each = var.env == "dev" || var.env == "qa" ? var.ip_addresses : []

This works perfect but I want to add the environment restriction as
well.

You are really close, you just need to change this array: [1] to be the actual array of IP addresses, like so:

for_each = var.env == "dev" || var.env == "qa" ? var.ip_addresses : []
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文