Error: Invalid function argument
on modules/eks/launch-template.tf line 7, in resource "aws_launch_template" "eks-cluster-launch-template":
7: user_data = base64encode(templatefile(join("", [path.module, "/userdata.tpl"]), {
8:
9:
10:
11:
12:
13:
Invalid value for "vars" parameter: vars map does not contain key
"aws_eks_cluster", referenced at modules/eks/userdata.tpl:3,47-62.
Error: Invalid function argument
on modules/eks/launch-template.tf line 7, in resource "aws_launch_template" "eks-cluster-launch-template":
7: user_data = base64encode(templatefile(join("", [path.module, "/userdata.tpl"]), {
8:
9:
10:
Invalid value for "vars" parameter: vars map does not contain key
"aws_eks_cluster", referenced at modules/eks/userdata.tpl:3,47-62.
Ah, found it. You can’t reference ‘${aws_eks_cluster.eks.endpoint}’ directly in your template file. You need to pass that in as a parameter in the same way that you’re passing ‘eks-cluster-name’ in.
Just to add further information, if you face issues regarding a variable that is created inside the template file then you have 2 solutions for that:
Escape that variable in shell script using an extra $ before it. For example, aws_eks_cluster=$${aws_eks_cluster}
Add that variable as aws_eks_cluster = "$aws_eks_cluster" under the list of variables for file in terraform script and it will replace ${aws_eks_cluster} with $aws_eks_cluster and the script will still work.