Deploy Azure Blob Storage using Terraform AzureRM module

George Grammatikos Azure Solutions Architect
Published:
In this article, I'll demonstrate how to use the Terraform language and the AzureRM module to deploy Azure Blob Storage within an Azure Resource Group.
An active Azure subscription is all you need to follow the commands below. Deployment will be done using Azure Cloud Shell, which requires an Internet browser.

Update Terraform (if needed)

There is a possibility that Terraform versions in Cloud Shell may be outdated. Here are the commands you need to type to update.

# 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

Here are the steps for deploying an Azure Resource Group and Azure Blob Storage.

Step 1. Open the nano editor to add the Terraform configuration code.

george [ ~ ]$ nano blobstorageterraform.tf

Step 2. Add the necessary values to the properties inside braces.

Important : Using Ctrl + ^ + X, press Y or enter (Yes) to save the changes.
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"
        }

Step 3. Next, Terraform is initiated

terraform init

Step 4.  You can examine Terraform's actions to deploy your infrastructure with the terraform plan command.

terraform plan -out {name}.tfplan

Step 5. Terraform's apply command executes the above plan and deploys the resources.

terraform apply "{name}.tfplan"

The above terraform code in action

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

0
595 Views

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.