Azure

Terraform On Azure – Creating A Storage Account, Blob Container And Queue

Introduction

Azure Storage Account is a broadly used storage service. It’s a handy information retailer for any sort of software whether or not operating on Azure or on-premises or some other cloud. It gives Blobs, Information, Queues, and Desk companies. Moreover, the Azure Blob service is so strong that it’s used as Technology 2 Information Lake within the Azure setting. On this article, we’ll learn to create an Azure Storage Account with a Blob service and a Queue service.

Within the earlier articles we discovered the fundamentals of Terraform, we created an Azure WebApp utilizing Terraform, after which we created Azure Digital Machine. The next are the hyperlinks to the earlier articles.

Create Azure Storage Account utilizing Terraform 

Allow us to create a Useful resource Group and inside it, we are able to create an Azure Storage Account. Then we are able to add a Blob service and a Queue service to the Storage Account.

Log in to the Azure portal. Allow us to use Azure Cloud Shell to create sources utilizing Terraform. Azure Cloud Shell has Terraform put in and you needn’t do any set up or configuration to work with Terraform. 

As soon as the Azure Cloud Shell opens up, choose Bash. Allow us to begin creating scripts to create an Azure Storage Account. We are able to use a nano editor to create the Infrastructure as a Code script for the Storage Account utilizing Terraform. 

Terraform On Azure

Execute the next command to open a nano editor and create a file named myterraformscript.tf.

nano myterraformscript.tf

Add the next code to the nano editor. This could create a Useful resource Group. Change {ResourceGroup} with the identify of your Useful resource Group that you’re planning to create.

terraform {  
  required_providers {  
    azurerm = {  
      supply = "hashicorp/azurerm"  
    }  
  }  
}  
supplier "azurerm" {  
  options {}  
}  
useful resource "azurerm_resource_group" "{ResourceGroup}" {  
  identify = "{ResourceGroup}"  
  location = "eastus"  
} 

Add the next code in nano editor to create a Storage Account. Change {ResourceGroup} with the identify of your Useful resource Group and {StorageAccount} with the identify of your Storage Account. 

useful resource "azurerm_storage_account" "{StorageAccount}" {
  identify                     = "{StorageAccount}"
  resource_group_name      = azurerm_resource_group.{ResourceGroup}.identify
  location                 = azurerm_resource_group.{ResourceGroup}.location
  account_tier             = "Normal"
  account_replication_type = "LRS"
}

Add the next code to create a Blob service contained in the Storage Account. Change {ResourceGroup} with the identify of your Useful resource Group, {StorageAccount} with the identify of your Storage Account, and {Blob} with the identify of your Blob container.

useful resource "azurerm_storage_container" "{Blob}" {
  identify                  = "{Blob}"
  storage_account_name  = azurerm_storage_account.{StorageAccount}.identify
  container_access_type = "personal"
}

Add the next code to create a Queue contained in the Storage Account. Change {ResourceGroup} with the identify of your Useful resource Group, {StorageAccount} with the identify of your Storage Account and {Queue} with the identify of your Queue.

useful resource "azurerm_storage_queue" "{Queue}" {
  identify                 = "{Queue}"
  storage_account_name = azurerm_storage_account.{StorageAccount}.identify
}

The next is the script file that you simply created. You possibly can consult with the hooked up script file and check out the pattern.

terraform {  
  required_providers {  
    azurerm = {  
      supply = "hashicorp/azurerm"  
    }  
  }  
}  
supplier "azurerm" {  
  options {}  
}  
useful resource "azurerm_resource_group" "{ResourceGroup}" {  
  identify = "{ResourceGroup}"  
  location = "eastus"  
} 

useful resource "azurerm_storage_account" "{StorageAccount}" {
  identify                     = "{StorageAccount}"
  resource_group_name      = azurerm_resource_group.{ResourceGroup}.identify
  location                 = azurerm_resource_group.{ResourceGroup}.location
  account_tier             = "Normal"
  account_replication_type = "LRS"
}

useful resource "azurerm_storage_container" "{Blob}" {
  identify                  = "{Blob}"
  storage_account_name  = azurerm_storage_account.{StorageAccount}.identify
  container_access_type = "personal"
}

useful resource "azurerm_storage_queue" "{Queue}" {
  identify                 = "{Queue}"
  storage_account_name = azurerm_storage_account.{StorageAccount}.identify
}

Run the next command to provoke Terraform. This could fetch all dependencies wanted to execute the Terraform script.

terraform init

Now allow us to create an execution plan for Terraform. Allow us to present the identify of the execution plan within the out parameter.

terraform plan -out mysa.tfplan

Execute the execution plan utilizing the next command. The Storage Account will get created.

terraform apply "mysa.tfplan"

Conclusion

On this article, we discovered easy methods to create an Azure Storage Account. Within the subsequent article, we’ll learn to create an Azure Perform utilizing Terraform scripts. 

Show More

Related Articles

Leave a Reply

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

Back to top button