Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views13 pages

CloudInfra 6.1

This document provides a step-by-step guide for setting up AWS infrastructure using Terraform, an open-source infrastructure as code tool. It covers prerequisites, AWS credential setup, Terraform installation, infrastructure definition, initialization, application, and destruction of resources. The objective is to create a basic AWS environment including a VPC, subnet, route table, security groups, and an EC2 instance running a web server.

Uploaded by

Arun Nair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

CloudInfra 6.1

This document provides a step-by-step guide for setting up AWS infrastructure using Terraform, an open-source infrastructure as code tool. It covers prerequisites, AWS credential setup, Terraform installation, infrastructure definition, initialization, application, and destruction of resources. The objective is to create a basic AWS environment including a VPC, subnet, route table, security groups, and an EC2 instance running a web server.

Uploaded by

Arun Nair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Module-6: Cloud Infrastructure for AI

AI Lab Practice 6.1

Title: Building AWS Infrastructure with Terraform:

A Step-by-Step Guide

Problem Statement:

This exercise provides a hands-on guide for setting up AWS infrastructure using
Terraform. Terraform is an opensource infrastructure as code (IaC) tool that allows
users to define and provision data center infrastructure using a high-level configuration
language. By following this guide, you will learn how to configure AWS credentials,
install and set up Terraform, and define AWS resources through Terraform configuration
files. The objective is to create a basic AWS environment including a VPC, subnet,
route table, security groups, network interface, elastic IP, and an EC2 instance running
a web server.

Prerequisites

Before we begin, make sure you have the following:

 An AWS account
 Terraform installed on your local machine
 AWS CLI installed and configured

The Architecture to be performed using Terraform:


Step 1: Set Up AWS Credentials

The first step in building an AWS infrastructure with Terraform is to configure your AWS
credentials. This is crucial for Terraform to interact with your AWS account.

To set up your AWS credentials, follow these steps:

 1. Open the AWS Management Console.


 2. Go to the IAM (Identity and Access Management) dashboard.
 3. Create a new IAM user and assign the necessary permissions.
 4. Generate an access key and secret access key for the IAM user.

Step 2: Terraform installed on your local machine:


a. Choose the binary to download. Select 386 for 32-bit systems or AMD64 for 64-bit
systems. Choose the download location for the zip file if the download does not start
automatically.

b. Unzip the downloaded file.

3. Go the System properties and set the environment variables


a. Select the Path variable in the System variables section to add terraform for all
accounts. Alternatively, select Path in the User variables section to add terraform for the
currently logged-in user only. Click Edit once you select a Path.
a. Click New in the edit window and enter the location of the Terraform folder.
b. Select the file and click ok
4. Verify Windows Terraform Installation

 a. Open a new command-prompt window.


 b. Enter the command to check the Terraform version: terraform –version
 c. The output shows the Terraform version you downloaded and installed on your
Windows machine.
Step 3: Define Your Infrastructure

Now that your environment is set up, it’s time to define the infrastructure you want to
create. This involves writing Terraform configuration files (usually with a .tf extension)
that describes the AWS resources you want to provision.

For example, to create an AWS EC2 instance, you can create a main.tf file with the
following content:
Step 4: Initialize and Apply
Once your configuration files are ready, you need to initialize your working directory and
apply the configuration to create the infrastructure. Navigate to your Terraform project
folder and run the following commands:

terraform init

terraform apply

Step 5: Review Infrastructure

After applying your configuration, Terraform will provide you with information about the
created resources. Review this information and ensure everything is as expected.

Go to the AWS console to check if the instance is created and copy the public ip of the
instance.
Step 6: Destroying the Infrastructure

Always remember to destroy the resources you have created while doing hands-on to
avoid any unwanted costs. Go to the VS code editor and run the terraform destroy
command to destroy the resources that we have created in this hands-on. You can also
use terraform destroy -auto-approve to not get the yes prompt

You might also like