Skip to content

saif-resources / storage

Blob, queue, and file storage module. Wraps iac-azure-modules storageaccount (blob) with native azurerm_storage_queue/azurerm_storage_share resources for queue and file services, plus private endpoints and RBAC via App Registration SP.

Usage

module "storage" {
  source  = "tf.pulumi.com/saif-corp/resources/saif//modules/storage"
  version = "~> 3.10.0"

  context  = module.environment.context
  identity = module.identity.identity

  resource_group_name     = module.resource_group.resource_group_name
  resource_group_location = module.resource_group.location

  containers             = ["documents", "uploads"]
  connection_string_name = "storage"

  # Optional — queue/file are independently opt-in.
  queues      = ["document-intake"]
  file_shares = [{ name = "shared-config", quota_gb = 50 }]
}

# Compose app_settings
module "api" {
  app_settings = merge(
    module.storage.app_settings,
    # ...
  )
}

Inputs

Name Description Required
context Platform context from environment module yes
identity Identity bundle from identity module. Required unless only enable_static_website is set and no queues or file_shares are requested conditional
resource_group_name Resource group for the storage account yes
resource_group_location Azure region yes
containers List of blob container names to create no
connection_string_name App settings key suffix (default: storage) no
queues List of storage queue names to create no
queue_connection_string_name App settings key suffix (default: storagequeue) no
file_shares List of { name, quota_gb } file shares to create no
file_connection_string_name App settings key suffix (default: storagefile) no
account_replication_type Replication type (default: LRS) no

Outputs

Name Description
account_name Storage account name
account_id Storage account resource ID
primary_blob_endpoint Primary blob endpoint URL
container_names Names of created containers
queue_names Names of created storage queues
primary_queue_endpoint Primary queue endpoint URL
file_share_names Names of created file shares
primary_file_endpoint Primary file endpoint URL
app_settings { "ConnectionStrings__{name}" = endpoint } per enabled service

What it creates

  • Storage account (Standard LRS, shared key disabled, OAuth default)
  • Blob containers (private access)
  • Storage queues and file shares (only when requested — each is independently opt-in)
  • Private endpoints (services subnet): one per service that has resources requested (blob unless explicitly disabled via enable_blob = false; queue/file only when non-empty)
  • RBAC, granted only for services that are used:
  • Storage Blob Data Contributor → App Registration SP, deployer_principal_ids, and the identity running Terraform (current_client) (blob)
  • Storage Queue Data Contributor → App Registration SP (queue)
  • Storage File Data Privileged Contributor → App Registration SP (file — the only built-in file-share role that authorizes OAuth/AAD REST calls; the SMB Share roles only cover SMB-mounted access)

Known Limitations

  • Storage tables are not supported by this module. azurerm_storage_table always authenticates with a shared account key regardless of resource addressing or RBAC on the azurerm provider versions this module targets (>= 4.46, < 5.0; see providers.tf), but this module disables shared keys (shared_access_key_enabled = false) on every account it creates, unless storage_secret_keyvault_name is set to publish key1 to Key Vault. Table support was removed rather than kept dormant behind a flag; it can be reintroduced once the module is upgraded to azurerm >= 5.0 and the resource can move onto the same Resource Manager addressing already used for queues and shares.

RBAC notes

The App Registration service principal receives the Contributor role for each data-plane service it uses (Blob, Queue, File) to enable data-plane operations (no connection strings, no SAS tokens, no shared keys). At runtime the platform pins DefaultAzureCredential to EnvironmentCredential (AZURE_TOKEN_CREDENTIALS=environmentcredential, AZURE_CLIENT_ID = app registration), so the SP — not the UAMI — is the identity making data-plane calls. The UAMI covers platform concerns only (ACR pull, Key Vault reference resolution). This matches the cosmosdb module, which grants its data-plane role to the SP.

Contributor rather than Owner follows least privilege and matches Aspire's default role assignment for AddAzureStorage (StorageBlobDataContributor); Owner only adds ADLS Gen2 POSIX ACL operations, which Forge apps don't use. Queue Contributor is the standard Azure data-plane role for that service. File Data Privileged Contributor is required (rather than the SMB Share roles) because forge apps access file shares over REST via the Azure SDK, not by mounting the share over SMB.

Storage queues vs. Service Bus queues

Storage queues are a low-cost, high-throughput option for app-internal messaging without the operational overhead of a Service Bus namespace, at the cost of no native ordering or dead-lettering. See the per-service guides for provisioning steps and SDK usage: Queue Storage and File Share Storage.

Providers

Name Version
azurerm >= 4.46, < 5.0
azurerm.shared-services >= 4.46, < 5.0

Inputs

Name Description Type Default Required
account_replication_type Storage account replication type (LRS, ZRS, GRS, etc.) string "LRS" no
connection_string_name Key suffix for the app_settings connection string: ConnectionStrings__{name} string "storage" no
containers List of blob container names to create list(string) [] no
context Platform context from the environment module any n/a yes
deployer_principal_ids Map of identity keys to principal IDs granted Blob Data Contributor for CI/CD deployments. The key current_client is reserved for the identity running Terraform and cannot be used. map(string) {} no
enable_blob Explicitly enable/disable blob provisioning (RBAC, private endpoint, app setting). Defaults to true when null; set to false to opt out for queue/file-only accounts. bool null no
enable_static_website Enable static website hosting on the storage account bool false no
file_connection_string_name Key suffix for the app_settings file endpoint: ConnectionStrings__{name} string "storagefile" no
file_deployer_principal_ids Map of identity keys to principal IDs granted Storage File Data Privileged Contributor for CI/CD deployments map(string) {} no
file_shares File shares to create. quota_gb defaults to 100 GiB when unspecified.
list(object({
name = string
quota_gb = optional(number, 100)
}))
[] no
identity Identity bundle from the identity module. Required when enable_static_website is false (blob access via the App Registration SP), or whenever queues or file_shares are non-empty (queue/file data-plane RBAC is also SP-backed). any null no
name Override storage account name (bypasses namer). Use for migrations where the existing name differs from the namer convention. string null no
network_rules_enabled Enable storage account network rules (deny by default) bool true no
network_rules_ip_rules Additional public IP ranges to allow through the storage firewall. SAIF corporate/colocation ranges are always included. list(string) [] no
private_endpoint_enabled Create private endpoints for blob access and for any requested queue/file services. Disable for static websites where FD Private Link provides connectivity. bool true no
queue_connection_string_name Key suffix for the app_settings queue endpoint: ConnectionStrings__{name} string "storagequeue" no
queue_deployer_principal_ids Map of identity keys to principal IDs granted Storage Queue Data Contributor for CI/CD deployments map(string) {} no
queues List of storage queue names to create for app-internal producer/consumer messaging list(string) [] no
resource_group_location The Azure region for the storage account string n/a yes
resource_group_name The resource group for the storage account string n/a yes
storage_secret_keyvault_name Name of an existing Azure RBAC Key Vault in the shared services subscription. When set, shared key access is enabled on the account and key1 is stored there as a secret. Empty (default) keeps data-plane access OAuth-only. Requires the azurerm.shared-services provider, and the principal running Terraform must already hold Key Vault Secrets Officer on the vault. string "" no

Outputs

Name Description
account_id The storage account resource ID
account_name The storage account name
app_settings App settings map for web app configuration
container_names Names of the created containers
file_share_names Names of the created file shares
primary_blob_endpoint The primary blob endpoint URL
primary_file_endpoint The primary file endpoint URL
primary_queue_endpoint The primary queue endpoint URL
queue_names Names of the created storage queues
static_website_host The primary web host for the static website (null when static website is disabled)

Resources

  • resource.azurerm_key_vault_secret.storage_account_key (/terraform-docs/modules/storage/storage_key_secret.tf#40)
  • resource.azurerm_role_assignment.file_data_contributor (/terraform-docs/modules/storage/main.tf#156)
  • resource.azurerm_storage_queue.this (/terraform-docs/modules/storage/main.tf#120)
  • resource.azurerm_storage_share.this (/terraform-docs/modules/storage/main.tf#136)
  • data source.azurerm_client_config.current (/terraform-docs/modules/storage/main.tf#22)
  • data source.azurerm_key_vault.storage_keys (/terraform-docs/modules/storage/storage_key_secret.tf#23)

View source on GitHub