Azure Storage Blob
This page shows how to write Terraform for Storage Blob and write them securely.
azurerm_storage_blob (Terraform)
The Blob in Storage can be configured in Terraform with the resource name azurerm_storage_blob
. The following sections describe 7 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_storage_blob" "tab-projects" {
name = "Tab_Projects.csv"
storage_account_name = azurerm_storage_account.terraform-demo.name
storage_container_name = azurerm_storage_container.terraform-demo.name
type = "Block"
source = "./data-factory-datasets/Tab_Projects.csv"
resource "azurerm_storage_blob" "scalingscripts1" {
name = "appserver_setup.sh"
storage_account_name = azurerm_storage_account.scalingstorageaccount.name
storage_container_name = azurerm_storage_container.scalingartifacts.name
type = "Block"
source = "./scalingartifacts/SAPSetupScripts/appserver_setup.sh"
resource "azurerm_storage_blob" "dev" {
name = "diabetes.csv"
storage_account_name = azurerm_storage_account.dev.name
storage_container_name = azurerm_storage_container.dev.name
type = "Block"
source_uri = "https://raw.githubusercontent.com/MicrosoftDocs/mslearn-aml-labs/master/data/diabetes.csv"
resource "azurerm_storage_blob" "export" {
name = "export-function.zip"
storage_account_name = azurerm_storage_account.primary.name
storage_container_name = azurerm_storage_container.primary.name
type = "Block"
source = "export-function.zip"
resource "azurerm_storage_blob" "script" {
name = "script.sh"
storage_account_name = azurerm_storage_account.storage.name
storage_container_name = azurerm_storage_container.codigo.name
type = "Block"
source = "./script/shell.sh"
resource "azurerm_storage_blob" "sinequa_primary_nodes" {
name = join("",[var.data_storage_root, "var/sinequa-primary-nodes"])
storage_account_name = azurerm_storage_account.sinequa_st.name
storage_container_name = azurerm_storage_container.sinequa_st_container.name
type = "Block"
content_type = "text/plain"
resource "azurerm_storage_blob" "initialize_vm" {
name = "Initialize-VirtualMachine.ps1"
storage_account_name = azurerm_storage_account.public.name
storage_container_name = azurerm_storage_container.public.name
type = "Block"
source = "resources/Initialize-VirtualMachine.ps1"
Parameters
-
access_tier
optional computed - string -
content_md5
optional - string -
content_type
optional - string -
id
optional computed - string -
metadata
optional computed - map from string to string -
name
required - string -
parallelism
optional - number -
size
optional - number -
source
optional - string -
source_content
optional - string -
source_uri
optional - string -
storage_account_name
required - string -
storage_container_name
required - string -
type
required - string -
url
optional computed - string -
timeouts
single block
Explanation in Terraform Registry
Manages a Blob within a Storage Container.
Tips: Best Practices for The Other Azure Storage Resources
In addition to the azurerm_storage_account, Azure Storage has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_storage_account
Ensure to use HTTPS connections
It is better to use HTTPS instead of HTTP, which could be vulnerable to person-in-the-middle attacks.
azurerm_storage_account_network_rules
Ensure to allow Trusted Microsoft Services to bypass
It is better to allow Trusted Microsoft Services to bypass. They are not able to access storage account unless rules are set to allow them explicitly.
Azure Resource Manager Example
Azure Resource Manager code does not have the related resource.
Frequently asked questions
What is Azure Storage Blob?
Azure Storage Blob is a resource for Storage of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Storage Blob?
For Terraform, the gersta/az-data-factory-terraform-demo, karthikvenkat17/sapautoscaling and ErnstRoell/devops-adf source code examples are useful. See the Terraform Example section for further details.