What is the difference between `file` and `templatefile`?
IntermediateConceptLoops, Conditionals, Dynamic Blocks and Functions
Answer
file(path) reads content verbatim. templatefile(path, vars) renders a template with ${var} interpolation and directives like %{ for x in list }...%{ endfor }. Use it for user data and config files.
user_data = templatefile("${path.module}/init.sh.tpl", { app_port = var.port })
More on Loops, Conditionals, Dynamic Blocks and Functions
How does `count` work?BeginnerHow does `for_each` work?BeginnerWhen should you choose `for_each` over `count`?IntermediateHow do you use `for_each` with a list of objects?IntermediateWhat does "The for_each value depends on resource attributes that cannot be determined until apply" mean?AdvancedHow do you create a resource conditionally?Beginner