[SOLVED] User_data parameter for EC2 AWS instances does not work for freebsd?


I have a quite strange problem, when i try to create Freebsd EC2 instance in AWS with user_data parameter defined, terraform “applies” without errors, but commands in user_data seems to be getting ignored. As an example:
user_data = "echo what > /home/ec2-user/what.txt" does not produce anything inside of the created instance, but it also does not produce any error… so im a bit confused, what is the issue?

Thank you.

Hi @OneOfTheJohns,

From the perspective of the EC2 API and therefore from Terraform’s perspective, user_data is just an opaque block of bytes with no meaning. When EC2 starts your instance it makes that raw data available to the instance’s network interface via the instance metadata and user data API. Setting user_data won’t achieve anything at all unless there’s some software running in your EC2 instance that retrieves the data and acts on it.

Official images for common Linux distributions tend to be configured to run cloud-init on boot, and configure it to retrieve the user_data blob and try to interpret it as one of cloud-init’s supported user data formats.

If you want your FreeBSD instance to behave in a similar way then you could try to arrange for your AMI to include cloud-init and run it on boot. I don’t have any direct experience doing that, but I notice that FreeBSD is listed as one of the supported “distributions”, which suggests that there might be some official FreeBSD AMIs available that already have cloud-init installed and configured to run.

If you find that your AMI does already have cloud-init installed, then I suggest referring to How to debug user data for information on how to debug cloud-init’s behavior. That behavior is entirely driven by software running in your AMI, so if you are relying on cloud-init then this is a cloud-init debugging question rather than a Terraform question, and so you might get a more detailed answer from a cloud-init-focused help forum, such as those discussed in the cloud-init readme.

1 Like