Share:
Twitter
LinkedIn
Facebook
Google+
Reddit
Whatsapp
Follow by Email

The more I am using Azure the more I want to make my life easier. Terraform to the rescue it seems. Below you will find my first look at Terraform with the Azure Cloud Shell. I have written as a how to guide so hopefully it helps.

Let’s get to it!

Open the Azure Cloud Shell from within the Azure Portal. 

Microsoft was kind enough to install Terraform for us in the Clod Shell so you will not have to install it.

Allow Terraform access to Azure

For this you will need to create an Azure AD service principal. This service principal grants your Terraform scripts the permissions they need to provision Azure resources for the given subscription.

First, you need to make sure you are in the right subscription. (Only needed if you have multiple subscriptions). In the Cloud Shell use the following to get a list of your Azure subscription and Tenant ID’s.

Now you need to select the subscription you want to use to create the service principal on. To do that just use the following, but make sure you change to your subscription ID.

Now you are ready to create a service principal for use with Terraform. Use the following, but make sure you change the scope to yours.

<strong>Note</strong>

Make sure you take a copy of the appID, password and tenant. You will need them.

Time to configure some Terraform environment variables

For Terraform to be able to use the new service principle you need to set some environment variables. Luckily this is easy with the below shell script. You will need to fill in some details here such as subscription ID, appID, Password, and tenant ID from before.

Time to test!

To test we need to create a simple Terraform file from within the Cloud Shell. To do this open up Nano by using the following command.

Copy the following code into the window and press Ctrl O to save and then Ctrl X to exit.

Now you can use the following command to download the Azure modules needed to create the Resource in the test file. In this case a resource group.

To make sure your Terraform file will work use the following.

As you can see it will create a resource group in ukwest and it will be called Pixel-Terraform.

To create the resources from the Terraform file use the following.

Now if you go to Resource Groups in the Portal you will see your newly created Resource group.

There you have it you have created your first Terraform file and applied it to create an Azure resource group.

Going forward I am going to start looking at building an AKS cluster that will host a RabbitMQ cluster and hopefully will deploy this using Terraform, so look out for that article.

I hope you found this helpful, if you have any questions please reach out.

Share:
Twitter
LinkedIn
Facebook
Google+
Reddit
Whatsapp
Follow by Email
Categories: AzureTerraform

Pixel Robots.

I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.

Leave a Reply

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

*

I agree