我正在使用 Terraform azurerm 提供程序版本 1.19 创建 AKS 群集。我想在创建集群时指定网络安全组规则,但我不知道如何引用创建的安全组,因为生成的安全组的名称是随机数。
就像是:
aks-agentpool-33577837-nsg
有没有办法引用创建的 nsg 或至少输出名称中使用的随机数?
创建集群的配置:
resource "azurerm_resource_group" "k8s" {
name = "${var.resource_group_name}"
location = "${var.location}"
}
resource "azurerm_kubernetes_cluster" "k8s" {
name = "${var.cluster_name}"
location = "${azurerm_resource_group.k8s.location}"
resource_group_name = "${azurerm_resource_group.k8s.name}"
dns_prefix = "${var.dns_prefix}"
kubernetes_version = "${var.kubernetes_version}"
linux_profile {
admin_username = "azureuser"
ssh_key {
key_data = "${file("${var.ssh_public_key}")}"
}
}
agent_pool_profile {
name = "default"
count = "${var.agent_count}"
vm_size = "${var.vm_size}"
os_type = "Linux"
}
service_principal {
client_id = "${var.client_id}"
client_secret = "${var.client_secret}"
}
tags {
source = "terraform"
environment = "${var.environment}"
}
}
这会生成一个安全组,我想向其中添加其他规则。这是我想添加的一条规则,以便可以检查 nginx-controller 的 liveness 探针。
resource "azurerm_network_security_rule" "nginx_liveness_probe" {
name = "nginx_liveness"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "${var.nginx_liveness_probe_port}"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_kubernetes_cluster.k8s.node_resource_group}"
network_security_group_name = How do I reference the auto-generated nsg ?
description = "Allow access to nginx liveness probe"
}