How to pass argument from tfvars.tf to the templatefile function

Hello,
I’m tired to utilize terraform as used on this website Terraform Create Multiple EC2 with different Configs - for_each and count together
Terraform Create Multiple EC2 with different Configs – for_each and count together.
Instead of using the HereDocument, I’m trying to use The Terraform templatefile function.
However, I received the following errors:

``` on main.tf line 36, in resource "aws_instance" "web":
```36:  user_data = templatefile(${each.value.appl_name}","${each.value.appl_version}")
```     each.value.appl_name is tuple with 1 element
```	...
```	...
```	...
I have included the config files below. Please advise.

Thanks Michael

``` #variables.tf
``` variable "configuration" {
``` description = "The total configuration, List of Objects/Dictionary"
```  default = [{}]
```}

```#dev.tfvars
```configuration = [
``` {
```    "application_name" : "GritfyApp-dev",
```   "ami" : "ami-09e67e426f25ce0d7",
```    "no_of_instances" : "2",
```    "instance_type" : "t2.medium",
```    "subnet_id" : "subnet-0f4f294d8404946eb",
```    "vpc_security_group_ids" : ["sg-0d15a4cac0567478c","sg-0d8749c35f7439f3e"],
```	"appl_version" : [{ appl_1_version = "1.0" }],
```	"appl_name"     : [/app_dir/appl_1_script.tpl"]
``` },
```  {
```    "application_name" : "GrityWeb-dev",
```    "ami" : "ami-0747bdcabd34c712a",
```    "instance_type" : "t2.micro",
```    "no_of_instances" : "1"
```    "subnet_id" : "subnet-0f4f294d8404946eb",
```    "vpc_security_group_ids" : ["sg-0d15a4cac0567478c"],
```	"appl_version" : [{ appl_2_version = "5.0" }],
```	"appl_name"     : [/app_dir/appl_2_script.tpl"]
```  },
```  {
```    "application_name" : "OpsGrit-dev",
```    "ami" : "ami-0747bdcabd34c712a",
```    "instance_type" : "t3.micro",
```    "no_of_instances" : "3",
```    "subnet_id" : "subnet-0f4f294d8404946eb",
```    "vpc_security_group_ids" : ["sg-0d15a4cac0567478c"],
```	"appl_version" : [{ appl_2_version = "5.1.0" }],
```	"appl_name"     : [/app_dir/fixit_script.tpl"]	
```  }
 
```]

```#main.tf
```provider "aws" {
``` region = "us-east-1"
```  profile = "personal"

```}

```locals {
```  serverconfig = [
```    for srv in var.configuration : [
```      for i in range(1, srv.no_of_instances+1) : {
```        instance_name = "${srv.application_name}-${i}"
```        instance_type = srv.instance_type
```        subnet_id   = srv.subnet_id
```        ami = srv.ami
```        security_groups = srv.vpc_security_group_ids
```		appl_version = "${srv.appl_version}"
```		appl_name = "${srv.appl_name}"
```      }
```    ]
```  ]
```}

```// We need to Flatten it before using it
```locals {
```  instances = flatten(local.serverconfig)
```}

```resource "aws_instance" "web" {

``` for_each = {for server in local.instances: server.instance_name =>  server}
``` instance_type = each.value.instance_type
``` vpc_security_group_ids = each.value.security_groups
``` user_data = templatefile(${each.value.appl_name}","${each.value.appl_version}")
 ```subnet_id = each.value.subnet_id
 ```tags = {
 ```  Name = "${each.value.instance_name}"
 ```}
```}

```output "instances" {
```  value       = "${aws_instance.web}"
```  description = "All Machine details"
```})

Please check your own post - you’ll see the forum software has messed up the formatting of your error message and config files by interpreting various characters as formatting markup.

Use preformatted text markers (``` on a line by itself before and after) whenever you paste any form of code or error message so that it doesn’t get mangled.

Thanks for your reply, I’ve added the preformatted text makers. Is there an FAQ or instructions on how to submit a post. I looked under the FAQ.

Please review your post again. The formatting is still messy to the point of being too hard to read comfortably.

You need three backticks on a line by themselves to start or end a code section.

I’m not aware of a FAQ covering how to post, but really it comes down to this: You’re asking people to help you - if you make it easy for them to understand your questions, you chances of good responses are increased. Make it hard for people to read what you wrote, and they will be discouraged from responding.

Thanks again, per your recommendation I’ve added the 3 back ticks to every line of the errors and code.

Although it is a partial improvement, it’s still not good.

The three backticks are only supposed to appear on a line by themselves, and they have the function of starting or ending a code section.

You’re not supposed to put them on every line.

If you view the formatted preview of your post as you are writing it, you will be able to check for things looking wrong before you actually post.

I can also see clearly invalid syntax in your tfvars file, with what looks like " characters missing.

As for the error:

If you review the documentation for templatefile: templatefile - Functions - Configuration Language | Terraform by HashiCorp you will see the first parameter is supposed to be a path to a file on disk - i.e. a string. Not a tuple/list as you seem to be passing it on some cases.