Terraform - lansare instante EC2

Postat la Wed 29 June 2022 in howto

In a doua parte am prezentat configurarea unui Security Group in AWS.

Acum vom lansa si o instanta EC2. Inainte vom incarca o cheie publica pentru a ne permite accessul SSH:

resource "aws_key_pair" "Cristi" {
  key_name   = "Cristi public"
  public_key = "ssh-rsa AAAAB3N ..... == cristi@cristi"
}

resource "aws_instance" "ter-worker" {
  ami                       = "ami-05b44291810dff0b2"
  instance_type             = "t3.micro"
  key_name                  = "Cristi public"
  subnet_id                 = aws_subnet.ter-1a.id
  security_groups           = [ aws_security_group.ter-sg.id ]
  count                     = 2

  root_block_device {
    volume_size             = 25
    volume_type             = "gp3"
    delete_on_termination   = true

    tags = {
      Name = "ter-worker-root-${count.index}"
    }
  }

  ebs_block_device {
    device_name            = "/dev/xvdba"
    volume_size             = 100
    volume_type             = "gp3"
    delete_on_termination   = true

    tags = {
      Name = "ter-worker-data-${count.index}"
    }
  }

  tags = {
    Name = "ter-worker-${count.index}"
  }

}

Putem specifica tipul instantei, marimea si tipul discurilor ce vor fi utilizate, precum si numarul instantelor dorite.

Nota: parametrii suplimentari gasiti in documentatia aws instance .