Easy methods to 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 = {
    Title = "example-instance"

On this instance, we’re utilizing the aws_instance useful resource kind 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 kind. 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 Title tag for the occasion. You possibly can customise this block with any extra tags that you just’d like so as to add.