I'm trying to use Terraform to update the kubernetes version for an Azure Kubernetes Service (AKS) cluster. The Terraform configuration for the cluster looks like this:
resource "azurerm_kubernetes_cluster" "dev-k8s" {
name = "my-cluster"
... etc
kubernetes_version = "1.22.1"
linux_profile {
admin_username = var.admin_username
ssh_key {
key_data = file(var.k8s_public_key)
}
}
When I try running terraform plan
from my local linux terminal (when logged into Azure via the Azure CLI) the variable var.k8s_public_key
resolves to ~/.ssh/my-k8s.pub
, and I get the following error message :
Error: Invalid function argument
on k8s.tf line 22, in resource "azurerm_kubernetes_cluster" "dev-k8s":
22: key_data = file(var.k8s_public_key)
|----------------
| var.k8s_public_key is "~/.ssh/my-k8s.pub"
Invalid value for "path" parameter: no file exists at
/home/myuser/.ssh/my-k8s.pub; this function works only with files that
are distributed as part of the configuration source code, so if this file will
be created by a resource in this configuration you must instead obtain this
result from an attribute of that resource.
I have a private key, but no public key. If the public key is required, I need to create a new one. The error is confusing me though, as I thought that the public key needs to be on the server side, not on my client side. Also the guides I've looked at show how to generate a public/private key pair then create the cluster using those credentials. I'm unsure of how to update the cluster without the public key. If I generate a new public key, then how will that be linked to the cluster, and how does that work to allow me to access the cluster? Do I even need the public key if I'm only updating the cluster? I'm looking for any advice on what's going on or how to resolve this, as I don't clearly understand the issue.
If I remove the linux_profile
section from the Terraform configuration, terraform plan
succeeds, but it then wants to create an entirely new cluster with the same name. I'm not sure what's going on, or what I need to do to just update the kubernetes version.
0 Answers