Create Azure File Share With Terraform

This blog post focuses on using Terraform to create an Azure File Share, which is a convenient and powerful way to store and share files in the cloud.

Azure File Shares are part of the Azure Storage Account service, which is a fully managed service that offers scalable, secure, and highly available storage solutions. By using Terraform, you can automate the process of creating an Azure File Share, making it more efficient, reliable, and easier to manage.

Before we begin, make sure you have the following set up:

  • An Azure account with an active subscription
  • Terraform installed (version 0.12 or later)
  • Azure CLI installed and configured with your account

Main.tf

Create a new directory for your Terraform project and create a new file named “main.tf” inside the directory. The main.tf file will contain the following configuration:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "filesharedemo"
  location = "southeastasia"
}

resource "azurerm_storage_account" "storage" {
  name                     = "ntweeklydemo"
  resource_group_name      = azurerm_resource_group.rg.name
  location                 = azurerm_resource_group.rg.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_share" "fileshare" {
  name                 = "ntweeklyshare"
  storage_account_name = azurerm_storage_account.storage.name
  quota                = 20
}

Output.tf

To create an output file that displays information about the created Azure File Share, add an “output.tf” file to the same directory as your “main.tf” file. In the “output.tf” file, include the following content.

output "resource_group_name" {
  value = azurerm_resource_group.rg.name
}

output "storage_account_name" {
  value = azurerm_storage_account.storage.name
}

output "file_share_name" {
  value = azurerm_storage_share.fileshare.name
}

output "file_share_url" {
  value = "${azurerm_storage_account.storage.primary_file_host}/${azurerm_storage_share.fileshare.name}"
}

Terraform will prompt you to confirm the creation of the resources. Type “yes” and press enter to proceed. Once the resources are created, you will see the output variables displaying the relevant information about your Azure File Share.

Example output

resource_group_name = "example-resources"
storage_account_name = "examplestorageacct"
file_share_name = "examplefileshare"
file_share_url = "https://examplestorageacct.file.core.windows.net/examplefileshare"

Processing…
Success! You're on the list.


Posted

in

,

by

Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.