Saturday, November 21, 2026
HomeSoftware EngineeringHow you can create Public and Non-public Subnets in Terraform

How you can create Public and Non-public Subnets in Terraform

[ad_1]

To create private and non-private subnets in Terraform, you should utilize the AWS supplier to outline your community configuration. Right here’s an instance configuration that demonstrates find out how to create private and non-private subnets inside a Digital Non-public Cloud (VPC) in AWS:

# Outline your AWS supplier configuration
supplier "aws" {
  area = "us-west-2"  # Replace along with your desired area
}

# Create the VPC
useful resource "aws_vpc" "my_vpc" {
  cidr_block = "10.0.0.0/16"  # Replace along with your desired VPC CIDR block

  tags = {
    Title = "my-vpc"
  }
}

# Create the general public subnet
useful resource "aws_subnet" "public_subnet" {
  vpc_id            = aws_vpc.my_vpc.id
  cidr_block        = "10.0.0.0/24"  # Replace along with your desired public subnet CIDR block
  availability_zone = "us-west-2a"  # Replace along with your desired availability zone

  tags = {
    Title = "public-subnet"
  }
}

# Create the personal subnet
useful resource "aws_subnet" "private_subnet" {
  vpc_id            = aws_vpc.my_vpc.id
  cidr_block        = "10.0.1.0/24"  # Replace along with your desired personal subnet CIDR block
  availability_zone = "us-west-2b"  # Replace along with your desired availability zone

  tags = {
    Title = "private-subnet"
  }
}

On this instance, the aws_vpc useful resource creates a VPC with the required CIDR block. The aws_subnet assets create the private and non-private subnets inside the VPC, utilizing completely different CIDR blocks and availability zones.

Ensure you have the AWS CLI configured with acceptable credentials and the required permissions for creating VPCs and subnets. You may then run the Terraform instructions (terraform init, terraform plan, and terraform apply) within the listing the place you’ve saved your Terraform configuration recordsdata to create the infrastructure.

This instance assumes you’ve already initialized Terraform with the AWS supplier and have the mandatory plugins put in.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments