I have a user-data file attached to the main.tf. Whenever I make changes to the user-data file, and then run the terraform apply, the changes do not reflect on the server until I destroy and recreate the resources. Please is this the default operation or am I missing something. Thank you for answers.
After making the changes on the user date file, I expect that terraform apply will create a new instance with the updated user-data file content, but that is not happening.
As documented on the aws_instance resource on terraform, you need to set the user_data_replace_on_change attribute to true. It is false by default.
Also note that by default user_data is only applied at the time of instance creation so terraform will destroy and create the resource again when this flag is set.