简体   繁体   English

在 terraform 的 for_each 中添加多个变量类型?

[英]Adding multiple variable types in for_each in terraform?

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?我想添加多个 ip 地址以在 azure 中为应用服务配置访问限制,而且这应该只在少数环境中完成,我正在使用动态块来实现这一点,只要只有一个它就可以工作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"]
   }
 }

This works perfect but I want to add the environment restriction as well.这很完美,但我也想添加环境限制。 something like就像是

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

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:你真的很接近,你只需要将这个数组: [1]更改为实际的 IP 地址数组,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM