Microsoft Azure made easy

Terraform in Azure Made Easy

1048 VIEWS

· ·

This blog provides some basic examples of templated infrastructure for Microsoft Azure and how to deploy said infrastructure into Azure using their CLI/API authentication processes.

Terraform and Microsoft Azure

This basic compute demo will consist of the orchestration of blank Basic_A1 Azure instances into Microsoft Azure.

Pre-requisites:

  • It is assumed that this demo is being run from a UNIX based machine and that basic existing experience with UNIX based systems has been acquired
  • You have a Microsoft Azure account – Sign up here
  • You have Azure API authentication credentials for your account stored locally – Download them here
  • This repository cloned locally (install Git here)
  • You have Terraform installed (install it here)

Instructions:

  1. From the command-line, change directory into:
  1. In this directory, open ‘terraform.tfvars‘  with your editor of choice and enter a value for variable ‘ssh_username‘, ‘ssh_password‘, ‘storage_name‘ and save the file
    • A file with all of the populated variables will look something similar to the code below:
  • The storage_name variable is the name of the storage service to attach to the instance, it is blob storage service in Azure that serves as the backend to the instance. If you don’t already have a storage service to use, a storage service can be built using this repository by making a module declaration within an environment for the “storage_service” module at “./modules/compute/storage/storage_service” and pass the appropriate variables in the “terraform.tfvars” file of the specified environment. It’s important to note that each storage service requires a unique name.
  1. From the command-line, run the command
    • This command is exporting the credentials that will be used to authenticate with the Azure API as environment variables, ready to be used by Terraform
  1. Then run the command
    • This command will pull all of the modules declared within the current environment into the current environment’s directory from the modules directory (they can be seen in the.terraform directory of the current directory)
  1. Then run the command
    • This command will demonstrate what Terraform is about to deploy into Azure, also demonstrating any existing resources that may be affected (if there are any) by the upcoming terraform apply. The variable file to be used has been explicitly stated pointed to using the path, however it is not required if the command is ran from within the same directory as the variable file.
  1. Then run the command
    • This command will build all of the templated infrastructure that was shown in the terraform plan above. Again, the explicit paths to the variable and state files are not required if the command is ran from the same directory, this is to provide an example of how the command could be ran from a different directory should it be required.
  1. To destroy the infrastructure you have built, run command
    • Be careful, running this command will destroy all of the resources you have built into Azure!

Do you think you can beat this Sweet post?

If so, you may have what it takes to become a Sweetcode contributor... Learn More.

Jordan Taylor is a DevOps Practitioner. His goal is to learn every DevOps tool and technology, developing an arsenal of knowledge that covers every aspect of the DevOps space. With a specialization in automation, configuration management, cloud orchestration and CI/CD, Jordan is always looking to implement forward-thinking ideas that result in ultimate efficiency and value, while up-skilling and enabling those around him in the technologies used to innovate. Jordan's current favorite tools are Terraform, Docker and Vault.


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

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

Menu