Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Day-5/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,21 @@ resource "aws_instance" "server" {
destination = "/home/ubuntu/app.py" # Replace with the path on the remote instance
}

provisioner "remote-exec" {
inline = [
"echo 'Hello from the remote instance'",
"sudo apt update -y", # Update package lists (for ubuntu)
provisioner "remote-exec" {
inline = [
"sudo apt update -y",
"sudo apt install -y python3 python3-venv python3-pip",

# create virtual environment
"python3 -m venv /home/ubuntu/myenv",

# activate and install flask
"bash -c 'source /home/ubuntu/myenv/bin/activate && pip install flask'",

# run app in background properly
"nohup /home/ubuntu/myenv/bin/python /home/ubuntu/app.py > /home/ubuntu/app.log 2>&1 &"
]
}
"sudo apt-get install -y python3-pip", # Example package installation
"cd /home/ubuntu",
"sudo pip3 install flask",
Expand Down