Using the templatefile module for user_data files

I’m using Terraform to deploy an asg deployment config which employs user_data to provide some launch pre-config to scaled instances.

Previously I’ve just being passing text files via the file() module, but in trying to reduce repetition across the user-data scripts I have experimented using the templatefile module introduced in 0.12.

Unfortunately this doesn’t seem to be working, and I suspect it’s could be because AWS is expecting a file with a txt extension. Is there anyway I can do this using templatefile()?

Thanks

Max

Hi,

How are you using the templatefile() function ?

I’m using it on a project with terraform 0.12.x + aws provider for the same purpose (launch configuration user data) and it works as expected.
The only difference with your description, is that I’m using it for the user_data_base64 attribute.

resource "aws_launch_configuration" "node" {
  //...
  user_data_base64 = base64encode(templatefile("${path.module}/template/node-user_data.sh", {}))
  // ...
}

Arnaud

Thanks for your response @VEBERArnaud. I think the problem could be the template I am using has the tmpl extension rather than txt.

I’m guessing the extension doesn’t matter, as the templatefile() module will parse any text as if it’s a template. I’ll try that