Added subnet and other networking stuff to ec2 instance creation. Also created a firewall rule to allow incoming SSH connection and all outgoing connections.
This commit is contained in:
+30
-4
@@ -2,8 +2,34 @@ provider "aws" {
|
|||||||
region = "ap-south-1"
|
region = "ap-south-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "example" {
|
# EC2 instance
|
||||||
ami = "ami-0861f4e788f5069dd"
|
resource "aws_instance" "ec2_t2-micro" {
|
||||||
instance_type = "t2.micro"
|
ami = "ami-0861f4e788f5069dd" # Amazon Linux
|
||||||
key_name = "kshitij-personal-ed25519"
|
instance_type = "t2.micro"
|
||||||
|
key_name = "kshitij-personal-ed25519"
|
||||||
|
subnet_id = "subnet-0f2515644bbe8e603"
|
||||||
|
associate_public_ip_address = true
|
||||||
|
vpc_security_group_ids = [aws_security_group.ec2_ssh_security.id]
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "Test-EC2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Security group (firewall) for allowing incoming SSH connections
|
||||||
|
resource "aws_security_group" "ec2_ssh_security" {
|
||||||
|
name = "allow_ssh"
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
from_port = 22
|
||||||
|
to_port = 22
|
||||||
|
protocol = "tcp"
|
||||||
|
cidr_blocks = ["${var.ssh_ingress}"]
|
||||||
|
}
|
||||||
|
egress {
|
||||||
|
from_port = 0
|
||||||
|
to_port = 0
|
||||||
|
protocol = -1
|
||||||
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user