gpt4 book ai didi

azure - Terraform 中一种资源的互斥属性

转载 作者:行者123 更新时间:2023-12-02 07:43:12 25 4
gpt4 key购买 nike

我在这里需要一些帮助,我正在尝试为 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
}

关于azure - Terraform 中一种资源的互斥属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68887263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com