azure - terraform 中一种资源的互斥属性
问题描述
我需要一些帮助,我正在尝试为 azure ACI 容器实例编写一个模块。我发现两个属性是互斥的,dns_name_label 和 network_profile_id。如果我将ip_address_type设置为public,我想使用dns_name_label,但是network_profile_id不能来相同的脚本,反之亦然,如果我将ip_address_type设置为private,我必须定义network_profile_id,但是dns_name_label不能来脚本
如果无论如何都包含 dns_name_label 和 network_profile_id,判断 ip_address_type?
resource "azurerm_container_group" "this" {
name = var.name
location = var.location
resource_group_name = var.resource_group_name
ip_address_type = var.ip_address_type
dns_name_label = var.ip_address_type =="Public"&&length(var.dns_name_label)> 0 ? var.dns_name_label :""
os_type = var.os_type
restart_policy = var.restart_policy
network_profile_id = var.ip_address_type == "Private" ? azurerm_network_profile.this[0].id : ""
}
注意上面的代码不起作用,我得到错误
"network_profile_id": conflicts with dns_name_label
解决方案
您可以使用null而不是""
,这将消除资源中的属性null
被设置为其值:
resource "azurerm_container_group" "this" {
name = var.name
location = var.location
resource_group_name = var.resource_group_name
ip_address_type = var.ip_address_type
dns_name_label = var.ip_address_type =="Public"&&length(var.dns_name_label)> 0 ? var.dns_name_label : null
os_type = var.os_type
restart_policy = var.restart_policy
network_profile_id = var.ip_address_type == "Private" ? azurerm_network_profile.this[0].id : null
}
推荐阅读
- erlang - 将数百万条记录写入 mnesia 表会占用大量内存(RAM)并且即使这些记录被删除也不会回收
- cypress - 珀西没有在 CircleCI 球体中运行(带赛普拉斯)
- android - 如何将一种颜色从位图更改为另一种颜色
- c# - 在自定义 datetimePicker 上单击一个月后,它仍然显示日期选择窗口
- reactjs - 当屏幕最小化和工作区由两个单词组成时更改卡片的形状
- flutter - 为什么这个水平列表视图不能在颤动的 Web 上滚动?
- php - Recursively rename caps in array keys to dash and lower case
- google-chrome - 输出 console.dir 时 VS Code 中的类似 Chrome 控制台的终端
- c - 打印给定矩阵中每一行的最大值
- java - 重启android后广播接收器不工作