Provider Block

In Terraform, the “provider” block is a fundamental construct used to define and configure the provider responsible for managing the resources in a specific cloud or infrastructure environment. Providers are plugins in Terraform that interface with APIs of various services or platforms to create, read, update, and delete resources.

Step 5: terraform script for aws provider

  • inside this created terraform directory , create a new file to write the terraform scripts for Route table and define the Terraform aws configuration for your route table.
vi provider.tf

#provider

provider “aws” {

region = “us-east-1” # Specify your desired AWS region

}

provider file

Step 6: Terraform scripts for VPC & IGW

before configure the route table we have to configure the terraform code for creating VPC (virtual private code) and internet gateway(IGW).

  • For this create a file for VPC
  • create a file for IGW
vi vpc.tf
resource "aws_vpc" "demo-vpc" {
cidr_block = "10.0.0.0/16" # Define your VPC CIDR block
instance_tenancy = "default"
tags = {
Name = "demo-vpc"
}
}

Terraform code for VPC creation

 vi igw.tf

resource “aws_internet_gateway” “demo-igw” {

vpc_id = aws_vpc.demo-vpc.id

}

Terraform code for IGW creation

Step 7: Terraform code for Route table

  • Inside this directory, create a new file to write the terraform code for Route table and define the Terraform configuration for your route table.
vi Routetable.tf

resource “aws_route_table” “demo-route” {

vpc_id = aws_vpc.demo-vpc.id

route {

cidr_block = “0.0.0.0/0”

gateway_id = aws_internet_gateway.demo-igw.id # Reference the ID of the internet gateway

}

tags = {

Name = “route to internet”

}

}

Terraform code for Route table creation

Step 8: Execute terraform files i.e., provider.tf,vpc.tf,igw.tf,route-table.tf

  • we should initialize the terraform in backend.
  • firstly, we make ensure the terraform files shoube in declarative manner.
  • secondly, we have to check the validation of terraform code doesn’t have any syntax and resources errors.
  • then plan these terraform code and terraform files i mean check the cloud resources we are going to create.
  • finally,apply the the terraform code. this is the most important step we are going to execute because this is the step terraform will create the cloud resources we want
terraform init

terraform init

  • execute the below commands to format,validate and plan the terraform scripts
terraform fmt
terraform validate
terraform plan

terraform fmt,validate,plan

  • now,execute these below command to apply terraform scripts with auto approve.
  • When we execute this command then automatically our infrastructure will build automatically.
terraform apply --auto-approve

terraform apply –auto-approve

resources are created and added

  • see the terraform apply is complete Resources: 3 added,0 changed,0 destroyed

How To Create Route Table In AWS Using Terraform ?

Terraform is a popular IAAC (Infrastructure as a Code) tool used in automation to create, manage, modify, update, and destroy any cloud resources and cloud environment. Terraform supports any cloud provider, including AWS, Microsoft Azure, GCP, Oracle, Alibaba, IBM, Salesforce, etc.

Here, in this guide, I am going to discuss the AWS Route Table first, and I will discuss deeply what Terraform is. After that, I will walk you through different steps to write a Terraform script and execute the scripts. By using these Terraform scripts, we can create our custom route table and associate this route table with the AWS subnet.

Similar Reads

Understanding Of Primary Terminologies

What is the AWS Route Table?...

What is Terraform?

Terraform is an Infrastructure as Code (IaC) tool that allows users to define and provision infrastructure resources in a declarative manner using Hashicorp language, also called HCL (Hashicorp Configure Language).When working with AWS, Terraform enables you to create, manage, and update resources such as EC2 instances, Security groups, VPCs, route tables, internet gateways (IGW), S3 buckets, and relational databases efficiently and consistently....

Terraform has two types of flows

Workflow: In workflow we have three stages, first one is write the terraform code for what cloud resources we want and second one is plan it gives a blueprint of cloud resources which we desired to create and finally third one is apply it simply starts building the terraform code....

Step-By-Step Process To Create To Create AWS Route table Using Terraform

Here, i am going to create a aws Route table by launching AWS ec2 instance....

Terraform Scripts

In Terraform, the terraform block is used to configure settings related to the Terraform execution environment itself. This block allows you to define various options and configurations that affect how Terraform behaves when executing your infrastructure code....

Provider Block

In Terraform, the “provider” block is a fundamental construct used to define and configure the provider responsible for managing the resources in a specific cloud or infrastructure environment. Providers are plugins in Terraform that interface with APIs of various services or platforms to create, read, update, and delete resources....

Resources Block

In Terraform, the “resources” block is not a specific construct like the provider or terraform blocks. Instead, it’s a common terminology used to refer to the section of a Terraform configuration where you define the infrastructure resources what you want to desire....

Route table in aws using terraform – FAQ’s

What is a Route Table in AWS?...