DevOps Classroom notes 18/Aug/2026

Terraform ec2 user data

1. userdata

user_data = <<-EOF
        #!/bin/bash
        sudo apt-get update
        sudo apt-get install apache2 -y 
        sudo systemctl enable apache2
        sudo systemctl start apache2
    EOF

2. local variables

locals {
  environment = "dev"
  user_data = <<-EOT
    #!/bin/bash
    echo "Starting deployment..."
    apt-get update -y
    apt-get install -y nginx
    echo "Welcome to our ${local.environment} server" > /var/www/html/index.html
    systemctl start nginx
  EOT
}

3. template

create file user_data.sh.tpl

#!/bin/bash
sudo apt-get update
sudo apt-get install apache2 -y 
sudo systemctl enable apache2
sudo systemctl start apache2

task:

  1. create terraform module ec2 and security need create by module
  2. secuirty rules
    1. 22, 80, 443, 8080 – inbound rules (ingress)
    2. all trafic outbound rule (egress)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube