So, basically I want to be able to iterate in my Bash script template file over the array, that I initialise in Terraform.
The template file is used as user_data for AWS instance:
resource "aws_instance" "my_instance" {
...
user_data = templatefile("${path.module}/${var.template_file}",
{
my_array = ["item1", "item2"]
})
...
}
Here is my template file:
#!/usr/bin/env bash
printf "%s\n" "$${my_array[@]}" > my_array.txt
And when I execute cat my_array.txt it gives me no content.
I can know that workaround might be to define my_array as a string and after that parse it in Bash to an array, but I curios whether is it possible to avoid that and get kinda native variable interpolation here.
Any help or hints will be appreciated. Thanks!