Score:0

Install apache2 on ubuntu aws EC2 instance via scripit (useing terraform)

am flag

I try to create an ubuntu instance via terraform after install I want to execute the script which is referred to install apache2 here is my script

app1-install.sh

#! /bin/bash
sudo apt update
sudo apt install apache2-bin
# sudo systemctl enable apache2
# sudo service apache2 start  
sudo echo '<h1>Welcome to my terraform demo - APP-1</h1>' | sudo tee /var/www/html/index.html
sudo mkdir /var/www/html/app1
sudo echo '<!DOCTYPE html> <html> <body style="background-color:rgb(250, 210, 210);"> <h1>Welcome to ubuntu apache2 - APP-1</h1> <p>Terraform Demo</p> <p>Application Version: V1</p> </body></html>' | sudo tee /var/www/html/app1/index.html

but the instance is created but those scripts are not executed may I know how can install apche2 via script

more info

resource "aws_instance" "myec2new" {
   ami = data.aws_ami.amzlinux2.id
   instance_type = var.instance_type 
   user_data = file("${path.module}/app1-install.sh")
   key_name = var.instance_keypair
   vpc_security_group_ids = [ aws_security_group.vpc-ssh.id , aws_security_group.vpc-web.id]
   tags = {
     "Name" = "Ec2 Demo 2"
   }
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.