In this post, I will show you how to deploy Azure Blob Storage within an Azure Resource Group using Terraform language with the AzureRM module.

Let’s demo it

In order to follow the commands below you will only need an active Azure subscription. The tool for deployment will be Azure Cloud Shell which means you need an Internet browser.

Update Terraform if needed

Occasionally, Terraform versions in Cloud Shell might be outdated. To update, type the commands below.

# Identify the Terraform version that is currently being utilized in Cloud Shell.
terraform version

# Get the link to Terraform's download page, https://www.terraform.io/downloads.html
# Download the latest version

curl -O https://releases.hashicorp.com/terraform/1.4.6/terraform_1.4.6_linux_amd64.zip

# Unzip the file

unzip terraform_1.4.6_linux_amd64.zip

# If the directory does not already exist, make one called bin.

mkdir bin

# Move the terraform file to the bin directory.

mv terraform bin/

# Restart Azure Cloud Shell to update the Terraform version
# Verify that the version has changed

terraform version

#Info: You can read more about the above commands from the official MS documentation, which I used for this demo. {https://learn.microsoft.com/en-us/azure/developer/terraform/get-started-cloud-shell-bash?tabs=bash}

 

Deploy Azure Blob Storage

By following the below code steps, you can deploy an Azure Resource Group and Azure Blob Storage.

  1. Open the nano editor to add the Terraform configuration code.
george [ ~ ]$ nano blobstorageterraform.tf

2. Update the necessary values to the properties which are into braces.

Important:  To save the changes to the file, press Ctrl + ^ + X, then choose Y or type (Yes) and press Enter.
terraform{
        required_providers {
            azurerm = {
              source = "hashicorp/azurerm"
                }
           }
  }
provider "azurerm" {
        features {}
   }
resource "azurerm_resource_group" "{resource group}" {
        name="{resource group}"
        location = "westeurope"
  }
resource "azurerm_storage_account" "{storage account}" {
                name = "{storage account}"
                resource_group_name = azurerm_resource_group.{resource group}.name
                location = azurerm_resource_group.{resource group}.location
                account_tier = "Standard"
                account_replication_type = "LRS"
  }
resource "azurerm_storage_container" "images" {
                name = "images"
                storage_account_name = azurerm_storage_account.{storage account}.name
                container_access_type = "private"
        }

3. The next command initiates Terraform

terraform init

4. The terraform plan command creates an execution plan and lets you examine Terraforms actions to deploy your infrastructure.

terraform plan -out {name}.tfplan

5.  Terraform apply command, executes the above terraform plan and deploys the resources.

terraform apply "{name}.tfplan"

The Demo in practise

The video below includes all the above steps with the resources deployed.

 

Related Links

Share This