I created an Azure Kubernetes cluster using Terraform. I used the recommanded azurerm_kubernetes_cluster
resource, which create the nodes under the hood. As a consequence, I don't have access to the nodes as Kubernetes object.
I now want to Terraform the alerting related to thoses nodes. But in order to do it, I need to have the nodes as a Terraform object (Terraform alert rule resource
requires the id of the node: https://www.terraform.io/docs/providers/azurerm/r/monitor_metric_alertrule.html).
So I tried to access the nodes as Terraform data
: https://www.terraform.io/docs/providers/azurerm/d/virtual_machine.html.
As stated in the previous link, we need two infos for that: the resource_group
and the name
of the virtual machine. The output of the azurerm_kubernetes_cluster
resource gives us the resource_group
, so that part is ok. But the nodes have a name generated randomly (to be more precised, one part of the name is generated randomly, the other part can be guessed from Terraform objects that we have). But as the previous link shows, there is no possibility to use a filter
functionnality (such as in https://www.terraform.io/docs/providers/aws/d/ami.html) or to use a regex to match the nodes names.
So the following is not possible (with the *
in place of the random generated part and where part1
and part2
are known):
data "azurerm_virtual_machine" "nodes" {
name = "part1-*-part2"
resource_group_name = "${azurerm_kubernetes_cluster.this.node_resource_group}"
}
Does anyone have an id on how to unlock one of the following:
- I can't find any explanation in the Azure AKS documentation on how the random generate part of the node name is generated (is it that random are can it be predicted?) and can't find myself by experimentation or wild guess. Does someone knows that?
- Can we get the a list of virtual machines of a
resource_group
using datas in a way I didn't think of yet? - I can't seem to find any blog post or videos where AKS nodes alerting is done using Terraform, even with dirty tricks. Can someone provide me a link I missed to work on?
Terraform Azure provider version: 1.23.0
Terraform version: 0.10.x (required by the Azure provider 1.23.0)