This is my first time to use terraform to create ec2 in aws. I am using free tier account and performed init, plan, apply in terraform, however, no ec2 was created. i just copied the below script to test in creating ec2. Kindly enlighten me what seems to be missing or reason why ec2 is not created.
main.tf
Define the provider (AWS)
provider “aws” {
region = “us-east-1” # Specify your desired region
}
Define an EC2 instance resource
resource “aws_instance” “example” {
ami = “ami-01816d07b1128cd2d” # Replace with the AMI ID you want to use (Ubuntu, Amazon Linux, etc.)
instance_type = “t2.micro” # Instance type (free tier eligible)
Optional: Define key pair for SSH access
key_name = “your-key-name” # Ensure this key exists in your AWS account
Optional: Define a security group
vpc_security_group_ids = [“your-security-group-id”] # Specify your security group ID
Optional: Set a tag
tags = {
Name = “MyFirstEC2Instance”
}
}