Skip to main content

Tools you need before you start using Terraform for orchestration infrastructure in cloud

Terraform one of the famous open source tool used for planning, deploying and maintaining infrastructure as a code and the beauty of this tool is that it works across various cloud service providers.

Even though I personally like the AWS Cloudformation, it is AWS only and most probably it will always remain limited to Amazon Web Services. It has few advantages over other tools when using with AWS and will be the first to have new AWS features incorporated before other tools and APIs catch up.

However if you are not limiting yourself to AWS only or have hybrid environment you may want to use a 3rd party tool compatible for all cloud infrastructures. Terraform being one of them is youngest client only tool and this article will help you setting up your desktop environment and give you understanding of how it works before you can start to code.

Prerequisites:

Computer running Windows, Linux, Solaris or MacOS operating system.

Downloads:
Download Terraform directly from the creator HashiCorpp 
Download open source code editor - Visual Studio Code from Microsoft

You could also adopt the Chocolatey to install packages using Linux like commands. 

Setting up Windows desktop:

Using Chocolatey you can run following command to install Terraform and it will set environment variables for you automatically.

c:\choco install terraform

Alternatively you download Terraform executable and place it in a folder such as C:\Terraform\Terraform.exe. Essentially the executable is all you need but you'll have to manually set up environment variable to execute it from anywhere in console by adding path to environment variable %path%. In order to add path you'll have to go to Control Panel to System and Security > System > Advanced System Settings > Environment Variables. You then open path for user only or system variables and add path to Terraform.exe to the list.

Code editing can be performed by any editor such as Notepad, Notepad++ or for better editor you could choose to install downloaded code editor from Microsoft called Visual Studio Code.

You then need to write a Terraform format file and using the executable you can plan, apply or destroy your infrastructure defined within your terraform file with .tf extension and variables in file named terraform.tfvars available within same folder.

So your project will look like below;
.ProjectName
└──mainproject.tf
└──terraform.tfvars

You need to go to Command Prompt or use terminal within Visual Studio Code which uses powershell and change your working directory to ProjectName.

cd c:\users\username\documents\projectname

Once you are in your working folder and have your first project with variables, providers and resources defined you need to get the provider api or executables downloaded which can be done simply by typing following command.

terraform.exe init

You can also check list of providers by using the command bellow.

terraform.exe providers

With your sample project ready you can see what the implementation will look like by using command below. This will tell you what terraform will do including number of resources to be added, changed or destroyed.

terraform.exe plan

If you are happy with the plan you can run the plan by executing command below.

terraform.exe apply

Changes to the original plan can be implemented by executing above command again after modifying your main project .tf file. However please ensure that you do not make any changes to other system generated files.

Please pay attention to the full output.

Once you have finished with your project you can destroy everything that was created using this project by executing below.

terraform.exe destroy

The sample project to create a single web server is available in this blog.



Popular posts from this blog

Useful website performance and load testing tools

http://tsung.erlang-projects.org/ http://httpd.apache.org/docs/2.0/programs/ab.html http://phantomjs.org/ https://developers.google.com/speed/pagespeed/ http://servermonitoringhq.com/blog/how_to_quickly_stress_test_a_web_server https://code.google.com/p/httperf/ http://loadimpact.com/ http://www.paessler.com/webstress http://loaduiweb.org/ http://en.wikipedia.org/wiki/Web_server_benchmarking http://en.wikipedia.org/wiki/Load_testing http://www.loadui.org/ http://www.loadtestingtool.com/index.shtml http://www.appdynamics.com/blog/devops/load-testing-tools-explained-the-server-side/

Copy files and folders using SCP with spaces in path

Copying data from one system to other with file or folder names that contain spaces in path can be achieved using this guide. In this case I am copying data from Macbook to Windows 10 computer. In order to copy the data easily it is better to use bash commands. Windows computer can support WSL (Windows subsystem for Linux) and you can run one of few linux distributions to use shell commands. I have Ubuntu set up within my Windows 10 using WSL. If you do not have WSL, you can set it up using my guide here . The copy can be performed in two ways: 1) Using SCP Source (MacOs) path: /home/Users/username/Documents/data extract from 2020/ First of all you add escape sequence to the path so it will become:  /home/Users/me/Documents/data\ extract\ from\ 2020/ . While this works on local system for SCP you'll have to double the escape sequences by replacing \ with \\, as below. Figure out your source computer IP address using "ifconfig" command. Now using scp command on target syst...

TrueCrypt on macOS X Mojave 10.14

If you have updated your macOS recently to Mojave otherwise known as verison 10.14 you may not be able to install the last version of Truecrypt in order to access your old volumes encrypted with Truecrypt software. This article will guide you to get this working on your MacOS v10.14 (Mjoave) . Download the package from  https://truecrypt.ch/downloads/  or  https://www.truecrypt71a.com/downloads/ . Find downloaded package using Finder in your HDD/Users/username/Downloads folder and will look like  TrueCrypt 7.1a Mac OS X.dmg . Open file location in Finder and open or double click on  TrueCrypt 7.1a Mac OS X.dmg . This will mount Truecrypt 7.1a and will have Truecrypt 7.1a.mpkg in it. Drag the package T rueCrypt 7.1a.mpkg and drop in your Downloads folder. From Locations in Finder you can eject your TrueCrypt mount. Now go to your Downloads location, find the file  TrueCrypt 7.1a.mpkg , right click and select Show Package Contents . Find the ...