Trying to run a bash script using user_data on an Ubuntu 18.04 server deployed on aws using terraform

Hey guys! I have successfully deployed an EC2 instance using terraform and now working on installing a Bookstacks wiki onto the server. The purpose is to have bookstacks automatically installed when the instance has been deployed. I am using the script that was provided by Bookstacks and have manually tested the script, it works.
Here is the script in the user_data section that i want to run automatically.

resource "aws_instance" "web-server-instance" {
  ami = "ami-0e472ba40eb589f49"
  instance_type ="t2.micro"
  availability_zone = "us-east-1a"
  key_name = "Main-key"

network_interface {

  device_index = 0
 network_interface_id =

user_data= <<-EOF


       # Ensure you have read the above information about what this script does before executing these commands.

      sudo apt install wget

      # Download the script


      # Make it executable

      chmod a+x

      # Run the script with admin permissions

      sudo ./  



tags ={

  Name ="bookstacks_terraform"


Unfortunately, This is not working and I am not sure how to fix this. Any help would be appreciate. Thanks:)

Were there any error messages? (e.g., in /var/log/cloud-init-output.log on the created instance)

I recommend reading through their official guide though:

There are some caveats you should check. You generally don’t need to use sudo in that context, for instance.

Thanks for getting back! I checked the logs and found that the script was running okay however, I was not sending the domain argument that the script required.

1 Like