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

  1. Choose an approved image.
  2. Pick a small instance for a learning workload.
  3. Place it in the intended subnet.
  4. 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.