Click here to Skip to main content
15,070,233 members
Articles / Hosted Services / Azure
Article
Posted 23 Apr 2019

Stats

3.9K views
3 bookmarked

Configuring Terraform Development Environment

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
23 Apr 2019CPOL3 min read
How to configure Terraform Development Environment

I’ve been doing a lot of work with a set of open source tools lately, specifically TerraForm and Packer. TerraForm at its core is a method of implementing truly Infrastructure as Code, and does so by providing a simple function style language where you can create basic implementations for the cloud, and then leverage resource providers to deploy. These resource providers allow you to deploy to variety of cloud platforms (the full list can be found here). It also provides robust support for debugging, targeting, and supports a desired state configuration approach that makes it much easier to maintain your environments in the cloud.

Now that being said, like most open source tools, it can require some configuration for your local development environment and I wanted to put this post together to describe it. Below are the steps to configure your environment.

Step 1: Install Windows SubSystem on your Windows 10 Machine

To start with, you will need to be able to leverage bash as part of the Linux Subsystem. You can enable this on a Windows 10 machine, by following the steps outlined in this guide:

Once you’ve completed this step, you will be able to move forward with VS Code and the other components required.

Step 2: Install VS Code and Terraform Plugins

For this guide, we recommend VS Code as your editor, VS code works on a variety of operating systems, and is a very light-weight code editor.

You can download the VS Code from this link:

Once you’ve downloaded and installed VS code, we need to install the VS Code Extension for Terraform.

Then click “Install” and “Reload” when completed. This will allow you to have intelli-sense and support for the different terraform file types.

Step 3: Opening Terminal

You can then perform the remaining steps from the VS Code application. Go to the “View” menu and select “integrated terminal”. You will see the terminal appear at the bottom:

By default, the terminal is set to “powershell”, type in “Bash” to switch to Bash Scripting. You can default your shell following this guidance:

Step 4: Install Unzip on Subsystem

Run the following command to install “unzip” on your linux subsystem, this will be required to unzip both terraform and packer.

sudo apt-get install unzip

Step 5: Install TerraForm

You will need to execute the following commands to download and install Terraform, we need to start by getting the latest version of terraform.

Go to this link:

And copy the link for the appropriate version of the binaries for TerraForm.

Go back to VS Code, and enter the following command:

czoyNDpcIndnZXQge3VybCBmb3IgdGVycmFmb3JtfVwiO3tbJiomXX0=

Then run the following commands in sequence:

czozMTpcInVuemlwIHt0ZXJyYWZvcm0uemlwIGZpbGUgbmFtZX1cIjt7WyYqJl19 
czo0MjpcInN1ZG8gbXYgdGVycmFmb3JtIC91c3IvbG9jYWwvYmluL3RlcnJhZm9ybVwiO3tbJiomXX0= 
czoyODpcInJtIHt0ZXJyYWZvcm0uemlwIGZpbGUgbmFtZX1cIjt7WyYqJl19

Confirm the installation by typing the following command:

czoxOTpcInRlcnJhZm9ybSAtLXZlcnNpb25cIjt7WyYqJl19

Step 6: Install Packer

To start with, we need to get the most recent version of packer. Go to the following URL, and copy the URL of the appropriate version.

Go back to VS Code and execute the following commands:

czoxNzpcIndnZXQge3BhY2tlciB1cmx9XCI7e1smKiZdfQ==
czoyODpcInVuemlwIHtwYWNrZXIuemlwIGZpbGUgbmFtZX1cIjt7WyYqJl19
czozNjpcInN1ZG8gbXYgcGFja2VyIC91c3IvbG9jYWwvYmluL3BhY2tlclwiO3tbJiomXX0=
czoyNTpcInJtIHtwYWNrZXIuemlwIGZpbGUgbmFtZX1cIjt7WyYqJl19

Step 7: Install Azure CLI 2.0

Go back to VS code again, and download / install Azure CLI. To do so, execute the steps and commands found here:

Step 8: Authenticating against Azure

Once this is done, you are in a place where you can run terraform projects, but before you do, you need to authenticate against Azure. This can be done by running the following commands in the bash terminal (see link below):

Once that is completed, you will be authenticated against Azure and will be able to update the documentation for the various environments.

NOTE: Your authentication token will expire, should you get a message about an expired token, enter the command, to refresh:

czoyNzpcImF6IGFjY291bnQgZ2V0LWFjY2Vzcy10b2tlblwiO3tbJiomXX0=

Token lifetimes can be described here:

After that, you are ready to use Terraform on your local machine.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Kevin Mack
Software Developer (Senior)
United States United States
My name is Kevin Mack, I'm a software developer in the Harrisburg Area. I have been a software developer since 2005, and in that time have worked on a large variety of projects. Everything from small applications, to mobile and Enterprise solutions. I love technology and enjoy my work and am always looking to learn something new. In my spare time I love spending time with my family, and learning new ways to leverage technology to make people's lives better. If you ask me what I do, I'll probably tell you I can paid to solve problems all-day-every-day.

Check out my blog at https://kmack.azurewebsites.net/ and https://totalalm.azurewebsites.net/

Comments and Discussions

 
QuestionInteresting start, but really incomplete Pin
Marc Clifton24-Apr-19 3:22
mvaMarc Clifton24-Apr-19 3:22 
They're website says:

Quote:
HashiCorp Terraform enables you to safely and predictably create, change, and improve infrastructure. It is an open source tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.


Would be great if you could expand this article to demonstrate how it works to achieve those goals.
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802

AnswerRe: Interesting start, but really incomplete Pin
Kevin Mack24-Apr-19 7:27
MemberKevin Mack24-Apr-19 7:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.