How one can Create an AWS EC2 Occasion in Terraform


The next Terraform code snippet creates an EC2 occasion for you.

supplier "aws" {
  area = "us-west-2"
}

useful resource "aws_instance" "instance" {
  ami           = "ami-0c94855ba95c71c99"  # Amazon Linux 2 AMI
  instance_type = "t2.micro"
  key_name      = "example-keypair"

  tags = {
    Identify = "example-instance"
  }
}

On this instance, we’re utilizing the aws_instance useful resource sort to create an EC2 occasion within the us-west-2 area. We’re utilizing the ami parameter to specify the Amazon Linux 2 AMI ID, and the instance_type parameter to specify a t2.micro occasion sort. We’re additionally specifying a key pair to make use of for SSH entry with the key_name parameter.

Lastly, we’re including a tags block to specify a Identify tag for the occasion. You’ll be able to customise this block with any extra tags that you simply’d like so as to add.

Leave a Reply