Lesson 2 of 4 ยท AWS with Terraform
EC2 and security groups
An EC2 instance needs a machine image, an instance type, and usually a subnet. Security groups define allowed traffic. Keep application access narrow and manage administrative access separately.
Example
resource "aws_instance" "app" {
ami = "ami-0123456789abcdef0"
instance_type = "t3.micro"
subnet_id = aws_subnet.private.id
}Step by step
- Choose an approved image.
- Pick a small instance for a learning workload.
- Place it in the intended subnet.
- Attach security controls that match its role.
Common mistakes to avoid
- Exposing SSH to the whole internet.
- Using a public subnet because it seems easier to test.