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:
- create terraform module ec2 and security need create by module
- secuirty rules
- 22, 80, 443, 8080 – inbound rules (ingress)
- all trafic outbound rule (egress)
