in the aws_ecs_task_definition resource there is the container_definitions parameter. is there a way to pass a json with variables, how the variables declaration and syntax of the json should be written?

Just pass it as an escaped string. Per the TF documentation here:

I would probably use the built-in “file” to do anything larger:

with the built it “file”, how do you use variables inside the json? it did not work for me.
I managed to overcome this with the “templatefile”