I am seeing the following error:
Failed to parse host: parse "https://"https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xx.us-east-1.eks.amazonaws.com"n": net/url: invalid control character in URL, while performing terraform apply
All I was trying to do is to use a null resource, to execute eks command, and output it to a txt file and using data "local_file", tried passing the returned value to host argument to the provider block below
resource "null_resource" "endpoint" {
//Trigger everytime
triggers = {
build_number = timestamp()
}
provisioner "local-exec" {
command = "aws eks describe-cluster --name ${var.cluster_name} --query cluster.endpoint >> ${path.module}/output.txt"
}
}
data "local_file" "output" {
filename = "${path.module}/outputtxt"
depends_on = ["null_resource.cluster_endpoint"]
}
provider "kubernetes" {
host = data.local_file.output.content
cluster_ca_certificate = base64decode(data.local_file.output.certificate)
exec {
command = "aws"
args = ["eks", "get-token", "--cluster-name", ${var.cluster_name}]
}
}
How can I make sure, to pass the cluster endpoint to the provider block using the null resource & local_file data block?
2
Answers
Instead of
it should be
or just
What you could do is use the data source that exists for EKS. That way you wouldn’t have to worry about the formatting of the file etc. So for example, this is how I would approach configuring the
kubernetes
provider:Note that you can use the new HCL syntax without the need to use quotes and
$
to reference the variable for the cluster name. One additional thing to note: the command for configuring thekubernetes
provider works with AWS CLI v2.