Terraform – the next step

      No Comments on Terraform – the next step

Its no secret to people that know me that I a closet coder and have been for years. Always willing to script anything that I can, not missing any opportunity to use Powershell, be it to automate, gather information or just to carry out a task. I find coding fascinating.

After passing AZ-103 I started looking at AZ-400 as I am quite keen on DevOps (someone said you could do a lot of it from the CLI and code). Studying AZ-400 highlighted I needed to improve my knowledge of the tools that devops uses. Doing this has given me a real appreciation for IAC (Infrastructure as Code). So Ive been looking at a couple of the tools fo IAC for a while now which includes Terraform. It high lights an issue that I need to show that I understand how Terraform works and performs, hence the Repo which at the moment only has one project in it, but more are coming. It’s a fascinating tool, to be able to build environments and then be able to make sure that they are staying as intended. Very powerful especially as the application platform agnostic meaning a company can adopt Terraform and can be utilised on whatever platform employed. As long as theres a provider it will build whatever you want.

So with the background bit over into the code.

The idea behind this first project was to create a small environment, to present something that illustrates a capability that Azure has and a way of testing that capability. The capability chosen is the ability to connect two Virtual Networks together simply so that computers on one vNet can communicate to computers on the a different vNet. This is called vNet Peering. The purpose of the project is not to explain vNet Peering but to give a quick and easy way of building an environment that will illustrate the premise. To learn more about vNet Peering please click right here.

The project is called Connect_Vnets and is contained at the Repository listed at the end of this post.

There are certain pre reqs that you will need to run this project and they are.
1. An Azure Subscription.
2. Terraform installed, installation for all flavours of operating systems can be found on the Hashicorp website, please click here.
3. I also use Visual Studio Code as an IDE to create and view the code.
4. AZ Cli installed to be able login to Azure from the command line

The steps are:

  • Configure the Computer with Terraform
  • Clone the Repository
  • Open Code in the folder in Visual Studio Code
  • Log into Azure
  • At the command line move into the folder Connect_Vnets
  • First command > Terraform init
  • Second Command > Terraform plan
  • Third Command > Terraform apply at the end of this command there should be two outputs, two IPs, one to connect too and one to ping, if the first IP is not visible, rerun Terraform plan, Terraform has been eager and the server is not fully booted before terraform reports its all finished to yourself.
  • Connect to IP using SSH the user name and password are in the code.
  • Ping the second IP, do you get a return?
  • last command > Terraform destroy doing this to the environment is the best course of action as its not very secure and has served it purpose.

Logging into Azure
This is very straight forward once, you have the repository open and are in the correct folder at the command line, remembering that you need AZ CLI installed, type the follwoing command > az login it will open a browser window and ask you to authenticate against Azure, then you can carry out the rest of the steps above.

Comments are welcome, I am aiming to improve each time I post, getting comments is one of the best ways to do that so all are welcome.

About VNet Peering https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-peering-overview
Install Terraform https://learn.hashicorp.com/terraform/getting-started/install.html
Repository https://github.com/RobinSnelson/using_terraform

Leave a Reply

Your email address will not be published. Required fields are marked *