Saturday, November 21, 2026
HomeSoftware EngineeringTips on how to Create an AWS EC2 Occasion in Terraform

Tips on how to Create an AWS EC2 Occasion in Terraform

[ad_1]

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 may customise this block with any extra tags that you just’d like so as to add.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments