AWS Private VPC + Terraform
Public Subnet
A public subnet is a subnet that is associated with a route table that has a route to an Internet gateway. This connects the VPC to the Internet and to other AWS services.
Private Subnet
A private subnet is a subnet that is associated with a route table that doesn’t have a route to an internet gateway. Instances in the private subnet are backend servers they don’t accept the traffic from the internet.
I am going to create a private subnet via AWS console and refer that subnet IP in the terraform file to launch an EC2 Instance.
# Terraform Block
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
# Provider Block
provider "aws" {
profile = "default" # AWS Credentials configured via AWS CLI.
region = "us-east-1"
}
# Resource Block
resource "aws_instance" "ec2demo" {
ami = "ami-0b5eea76982371e91" # Amazon Linux in us-east-1
instance_type = "t2.micro"
subnet_id = "subnet-0ce1a2e3f8f5bd851"
tags = {
"Name" = "webserver"
}
}
Comments
Post a Comment