<block><parameter> {
<argument>
}
resource "aws_key_pair" "deployer" {
key_name = "tws-terra-key"
public_key = file("C:/Users/Jyotindra/Desktop/My Projects/Devops/terraform-infra/terra-key.pub")
}
# Default VPC
resource "aws_default_vpc" "default" {
}
# Security Group
resource "aws_security_group" "terrasecurity" {
name = "allow ports"
description = "This SG is to open ports for ec2 instances"
vpc_id = aws_default_vpc.default.id #interpolation
# Incoming traffic
ingress {
description = "This is for SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "Outgoing traffic"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# EC2 Instance
resource "aws_instance" "my_instance" {
ami = "ami-084568db4383264d4"
instance_type = "t2.micro"
key_name = aws_key_pair.deployer.key_name
security_groups = [aws_security_group.terrasecurity.name]
tags = {
Name = "terra-automate"
}
}