gpt4 book ai didi

azure - 从 Terraform 中的 map 列表中输出特定值

转载 作者:行者123 更新时间:2023-12-03 05:38:50 25 4
gpt4 key购买 nike

我正在尝试使用 terraform 配置 Azure AKS。当我使用 LoadBalancer 配置文件创建 AKS 时,它将创建一个具有静态公共(public) IP 的负载均衡器。我需要这些 IP 来传递到 Nginx Controller

我想做的是使用数据 block 来获取 Terraform 创建的 IP,并将其传递给 terraform helm 模板以配置 Nginx 入口 Controller

当我使用数据 block 时

data "azurerm_public_ips" "example" {
resource_group_name = azurerm_kubernetes_cluster.aks.node_resource_group
attached = true
allocation_type = "Static"
name_prefix = "kubernetes"
depends_on = [
azurerm_kubernetes_cluster.aks]
}

output "ip" {
value = data.azurerm_public_ips.example.public_ips
}

我将得到如下输出

 ip = [
{
"domain_name_label" = ""
"fqdn" = ""
"id" = "/subscriptions/xxxx/resourceGroups/xx/providers/Microsoft.Network/publicIPAddresses/kubernetesxx"
"ip_address" = "00.00.00.00"
"name" = "kubernetes-xxxxx"
},
]


我想要实现的是将 ip_address 的值传递到我的 Helm Chart

data "helm_repository" "incubator" {
name = "stable"
url = "https://kubernetes-charts.storage.googleapis.com"
}
resource "helm_release" "ingress" {
repository = data.helm_repository.incubator.url
chart = "nginx-ingress"
name = "test"
set {
name = "controller.service.loadBalancerIP"
value =data.azurerm_public_ips.example.public_ips[ip_address]
}
depends_on = [
data.azurerm_public_ips.example
]
}

当我尝试使用上述方法时,它抛出一个错误

 Error: Invalid reference
on aks.tf , in output "ip":
value = data.azurerm_public_ips.example.public_ips[ip_address]
A reference to a resource type must be followed by at least one attribute access, specifying
the resource name.

最佳答案

你应该这样做:

element(data.azurerm_public_ips.example.public_ip, 1).ip_address

https://www.terraform.io/docs/configuration/functions/element.html

注意这是针对 0.12 的,针对 0.11 检查 this文章

关于azure - 从 Terraform 中的 map 列表中输出特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60403861/

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