Terraform Kubernetes Server Version

157 views Asked by At

Is there a way to get Kubernetes Server Version in Terraform Kubernetes provider? I would like to have the same information provided by kubectl version or kubectl version --short with Major and Minor server versions.

1

There are 1 answers

3
Kranthiveer Dontineni On

External data source blocks in Terraform will come in handy for this case. External data source allows users to execute a piece of code or commands of external sources such as python, databases or bash etc.

This is the example block taken from the official terraform documentation use it for reference

data "external" "example" {
  program = ["python", "${path.module}/example-data-source.py"]

  query = {
    # arbitrary map from strings to strings, passed
    # to the external program as the data query.
    id = "abc123"
  }
}

In the above snippet you can replace the python script with shell script and write your kubernetes commands inside the script and make sure to give executable permissions to the script.