Added EC2 instance creation under TestSubnet1 subnet (in TestVPC VPC)

This commit is contained in:
K
2025-09-08 10:28:59 +05:30
parent 06a2480a09
commit b73088c14d
+16 -2
View File
@@ -2,6 +2,7 @@ provider "aws" {
region = "ap-south-1"
}
# VPC
resource "aws_vpc" "TestVPC" { # Create a VPC
cidr_block = "172.16.0.0/16" # Specify CIDR block (IP range)
enable_dns_support = true # DNS support
@@ -11,6 +12,7 @@ resource "aws_vpc" "TestVPC" { # Create a VPC
}
}
# Subnet -> Associated w/ TestVPC
resource "aws_subnet" "TestSubnetOne" { # Create subnet
vpc_id = aws_vpc.TestVPC.id # Specify VPC under which subnet should be created
cidr_block = "172.16.1.0/24" # Specify segment of IP range (from VPC) for this subnet
@@ -22,5 +24,17 @@ resource "aws_subnet" "TestSubnetOne" { # Create subnet
# Internet gateway
# Route table
# Route
# Table association
# |_ Route
# |_ Table association
# EC2 under TestVPC in TestSubnet1 IP
resource "aws_instance" "name" {
ami = "ami-0861f4e788f5069dd"
instance_type = "t2.micro"
key_name = "kshitij-personal-ed25519"
subnet_id = aws_subnet.TestSubnetOne.id
tags = {
Name = "EC2-TestSubnet1"
}
}