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
+24 -10
View File
@@ -2,19 +2,21 @@ provider "aws" {
region = "ap-south-1" region = "ap-south-1"
} }
resource "aws_vpc" "TestVPC" { # Create a VPC # VPC
cidr_block = "172.16.0.0/16" # Specify CIDR block (IP range) resource "aws_vpc" "TestVPC" { # Create a VPC
enable_dns_support = true # DNS support cidr_block = "172.16.0.0/16" # Specify CIDR block (IP range)
enable_dns_hostnames = true # Hostname support enable_dns_support = true # DNS support
enable_dns_hostnames = true # Hostname support
tags = { tags = {
Name = "TestVPC" # Name for VPC (on AWS) Name = "TestVPC" # Name for VPC (on AWS)
} }
} }
resource "aws_subnet" "TestSubnetOne" { # Create subnet # Subnet -> Associated w/ TestVPC
vpc_id = aws_vpc.TestVPC.id # Specify VPC under which subnet should be created resource "aws_subnet" "TestSubnetOne" { # Create subnet
cidr_block = "172.16.1.0/24" # Specify segment of IP range (from VPC) for this subnet vpc_id = aws_vpc.TestVPC.id # Specify VPC under which subnet should be created
availability_zone = "ap-south-1a" # Set availability zone cidr_block = "172.16.1.0/24" # Specify segment of IP range (from VPC) for this subnet
availability_zone = "ap-south-1a" # Set availability zone
tags = { tags = {
Name = "TestSubnet1" # Name for subnet (on AWS) Name = "TestSubnet1" # Name for subnet (on AWS)
} }
@@ -22,5 +24,17 @@ resource "aws_subnet" "TestSubnetOne" { # Create subnet
# Internet gateway # Internet gateway
# Route table # Route table
# Route # |_ Route
# Table association # |_ 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"
}
}