noscript

Introduction

With Terraform, you can define and manage cloud resources using configuration files through infrastructure-as-code. In this Project we used Terraform and its integration with AWS by creating a Virtual Private Cloud VPC. In this project, we will use Terraform on a Linux machine, install and configure it, and create an AWS VPC.

Terraform is the Infrastructure as a code IAAC tool which is used to provide resources by writing a code.

Step 1: Go to AWS Account

logging into your AWS account. If you donʼt have an account yet, go ahead and create one.

Step 2: Configure EC2 Instance

Create an EC2 instance to act as your working environment. You can follow this guide to create an EC2 instance.

Step 3: Connect to the Instance

Once your EC2 instance is up and running, connect to it using EC2 Instance Connect. Navigate to the AWS console, find your instance, and click the “Connect” button.

Step 4: Installing Terraform

Now, letʼs install Terraform on your EC2 instance.

Download the Terraform package:

wget <https://releases.hashicorp.com/terraform/1.0.1/terra form_1.0.1_linux_amd64.zip>

Unzip the package and move it to your systemʼs binary folder:

sudo unzip terraform_1.0.1_linux_amd64.zip -d /usr/local/b in/

Remove the downloaded zip file:

rm terraform_1.0.1_linux_amd64.zip

Verify that Terraform was installed correctly:

terraform version

Step 5: Configuring the AWS Provider in Terraform

Create a working directory for Terraform:

mkdir infra && cd infra

Create a Terraform configuration file (            ):

cat > main.tf <<EOF terraform {

required_providers { aws = {

source = “hashicorp/aws” version = “3.48.0”

}

}

}

provider “aws” {

region = “us-west-2” # Oregon

} EOF

Initialize the working directory:

terraform init

List the directories to see what the init command has created:

ls -A

Step 6: Creating an AWS Resource with Terraform

To create an AWS resource, you need to define it in the configuration file.

Append an aws_vpc  esource block to your main.tf  file:

cat >> main.tf <<EOF

resource “aws_vpc” “web_vpc” {

cidr_block = “192.168.100.0/24” enable_dns_hostnames = true tags = {

Name = “Web VPC”

}

} EOF

Run the  Apply   command to generate a plan and review the output:

terraform apply

Accept and apply the plan by typing “yes” at the prompt.

Verify that the VPC has been created:

aws ec2 describe-vpcs –region us-west-2 –filter “Name=ta g:Name,Values=Web VPC”

Check if DNS hostnames are enabled for the VPC

aws ec2 describe-vpc-attribute –region us-west-2 –attrib ute enableDnsHostnames –vpc-id <VPC_ID>

Summary

Congratulations! You have successfully created an AWS VPC using Terraform. This project gave you hands-on experience with Terraformʼs core features, such as providers and resource declarations, and allowed you to automate infrastructure setup on AWS. Keep exploring Terraformʼs capabilities to build more complex and scalable cloud environments!

                                                                       For Information & classes Call02048553009
                                                                                    Registration Link: Click Here!

Author:- Trupti Mane

AWS Trainer

IT Education Centre Placement & Training Institute

© Copyright 2024 | IT Education Centre.