Author : Ahmed Raidhan
![](https://i0.wp.com/myfuturehub.com/wp-content/uploads/2022/08/Screenshot_20220226-235304_WhatsAppBusiness.jpg?resize=1024%2C527&ssl=1)
Introduction
This is an MFH Bitesize Lab, the aim of this document is to give the reader a quick and direct demonstration of the TERRAFORM technology. This is to supplement the online teaching sessions and to provide students with an online hands-on experience of taught technologies.
The Aim
At the end of this document, students would have:
- Installed Terraform
- Written and Executed some terraform scripts
- Publish a Vm on AWS using Terraform
- Built experience with IDE.
Terraform Installation
Pre -reqs
Windows PC – that you have admin rights to
Connected to the internet
AWS Account setup – with user access key
Terrform install
Goto to https://www.terraform.io/downloads – Download the correct Terraform zip file for your environment.
Extract Zip file to C:\Terraform – In c:\Terraform the file terraform.exe should be there!
Edit your Windows Environment variables and add c:\terraform to the path variable
ATTENTION !!!!! Do not remove what is already there, only append
Installation Check
On the Command Prompt – terraform version
You should get the following:
![](https://i0.wp.com/myfuturehub.com/wp-content/uploads/2022/08/4_20210905_111259_0003-edited.png?w=196&ssl=1)
This indicates Terraform is installed successfully.
My First Terraform Scripts
Directory Setup
Mkdir terraform-scripts
Inside terraform-scripts mkdir Proj1
Create Scripts
Inside Proj1 create the two following scripts:
Main.tf
variable “myvariable” {
type = string
default = “Welome to Terraform”
}
Main2.tf
variable "myvariable1" {
type = string
default = "Welome to Terraform again"
}
Excute first script
At the command prompt, type: (inside Proj1 folder)
Terraform console
This takes you into terraform console and the following:
“Welcome to Terraform” should be displayed.
The type the following:
“Welcome to Terraform again” should be displayed.
ATTENTION – This shows that terraform compiles all tf files in a folder!
My Second Terraform Script
Create Directory
Mkdir AWS-PROJ1
Create Scripts (inside AWS-PROJ1)
Create aws-connection.tf
provider "aws" {
access_key = "GET AWS ACCESS KEY"
secret_key = "GET AWS SECRET KEY"
region = "us-east-1"
}
Create aws_instance.tf
resource "aws_instance" "Ubuntu" {
ami = "ami-08d4ac5b634553e16"
instance_type = "t2.micro"
tags = {
Name = "AWS_Ubuntu_box1"
}
}
Create AWS VM
Inside the AWS-PROJ1 directory, type the following:
Terraform init (output should be live below:
Terraform deploy
This will connect to AWS and create the VM AWS_Ubuntu_box1.
Check instances on AWS.
![](https://i0.wp.com/myfuturehub.com/wp-content/uploads/2022/08/MFH_DevOps-1.png?resize=724%2C1024&ssl=1)