EC2

resource "aws_instance" "test" {
  ami           = "ami-0fa3fe0fa7920f68e"
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.public.id
  associate_public_ip_address = true
  vpc_security_group_ids      = [aws_security_group.example_sg.id]
  key_name                    = "test"  
  disable_api_termination = false

  root_block_device {
    volume_size           = 8
    volume_type           = "gp2"
    delete_on_termination = false
    tags = {
      Name        = "dev-ec2-root"
      Environment = "dev"
    }
  }

  tags = {
    Name        = "dev-ec2"
    Environment = "dev"
  }

  depends_on = [aws_vpc.main, aws_subnet.public]
}

output "ec2_public_ip" {
  value = aws_instance.test.public_ip
}

output "ec2_id" {
  value = aws_instance.test.id
}

output "ec2_volume_type" {
  value = aws_instance.test.root_block_device[0].volume_type
}