Example reference for ec2 instance creation: https://jhooq.com/terraform-ssh-into-aws-ec2/
Create a pem file in aws portal ec2 section and enter in the template below.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.71.0"
}
}
}
provider "aws" {
region = "us-west-2"
access_key = ""
secret_key = ""
}
resource "aws_instance" "myec2" {
ami = "ami-066333d9c572b0680" #region specific,last 4 digits are region specific.
instance_type = "t2.micro"
##
key_name = "satya"
vpc_security_group_ids = [aws_security_group.main.id]
tags = {
Name = "HelloWorld",
Owner = "user@email.com"
}
}
resource "aws_security_group" "main" {
egress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 0
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "-1"
security_groups = []
self = false
to_port = 0
}
]
ingress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 22
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "tcp"
security_groups = []
self = false
to_port = 22
}
]
}
No comments:
Post a Comment