This module provides unified, version-aware Azure Storage Account constructs using the VersionedAzapiResource framework.
- Automatic Version Management: Defaults to the latest stable API version (2024-01-01)
- Version Pinning: Explicitly specify API versions for stability
- Schema Validation: Automatic validation of properties against API schemas
- Multi-Language Support: Full JSII compliance for TypeScript, Python, Java, and .NET
- Type Safety: Complete TypeScript type definitions
2023-01-01- Stable release2023-05-01- Enhanced security features2024-01-01- Latest (default)
import { StorageAccount } from '@cdktf/tf-constructs-azure/azure-storageaccount';
import { ResourceGroup } from '@cdktf/tf-constructs-azure/azure-resourcegroup';
// Create a resource group first
const resourceGroup = new ResourceGroup(this, 'rg', {
name: 'my-resource-group',
location: 'eastus',
});
// Create a storage account with automatic version resolution
const storageAccount = new StorageAccount(this, 'storage', {
name: 'mystorageaccount',
location: 'eastus',
resourceGroupId: resourceGroup.id,
sku: { name: 'Standard_LRS' },
tags: {
environment: 'production',
project: 'myapp',
},
});const storageAccount = new StorageAccount(this, 'storage', {
name: 'mystorageaccount',
location: 'eastus',
resourceGroupId: resourceGroup.id,
sku: { name: 'Standard_LRS' },
apiVersion: '2023-05-01', // Pin to specific version
});const storageAccount = new StorageAccount(this, 'storage', {
name: 'mystorageaccount',
location: 'eastus',
resourceGroupId: resourceGroup.id,
sku: { name: 'Standard_LRS' },
enableHttpsTrafficOnly: true,
minimumTlsVersion: 'TLS1_2',
allowBlobPublicAccess: false,
networkAcls: {
defaultAction: 'Deny',
bypass: 'AzureServices',
ipRules: [
{ value: '1.2.3.4' },
],
},
});const storageAccount = new StorageAccount(this, 'storage', {
name: 'mystorageaccount',
location: 'eastus',
resourceGroupId: resourceGroup.id,
sku: { name: 'Standard_LRS' },
identity: {
type: 'SystemAssigned',
},
});const storageAccount = new StorageAccount(this, 'storage', {
name: 'mystorageaccount',
location: 'eastus',
resourceGroupId: resourceGroup.id,
sku: { name: 'Premium_LRS' },
kind: 'BlockBlobStorage',
});name- Storage account name (3-24 lowercase alphanumeric characters, globally unique)location- Azure regionresourceGroupId- Resource group ID where the storage account will be createdsku- SKU configuration withnameproperty
apiVersion- API version to use (defaults to latest)kind- Storage account kind (default: 'StorageV2')accessTier- Access tier for blob storage (default: 'Hot')enableHttpsTrafficOnly- Allow only HTTPS traffic (default: true)minimumTlsVersion- Minimum TLS version (default: 'TLS1_2')allowBlobPublicAccess- Allow public blob access (default: false)networkAcls- Network ACL configurationidentity- Managed identity configurationencryption- Encryption settingstags- Resource tagsignoreChanges- Properties to ignore during updates
Standard_LRS- Locally redundant storageStandard_GRS- Geo-redundant storageStandard_RAGRS- Read-access geo-redundant storageStandard_ZRS- Zone-redundant storagePremium_LRS- Premium locally redundant storagePremium_ZRS- Premium zone-redundant storage
StorageV2- General-purpose v2 (recommended)Storage- General-purpose v1BlobStorage- Blob-only storageBlockBlobStorage- Premium block blob storageFileStorage- Premium file storage
The StorageAccount construct provides the following outputs:
id- The resource IDname- The storage account namelocation- The storage account locationtags- The storage account tagsprimaryBlobEndpoint- Primary blob endpoint URLprimaryFileEndpoint- Primary file endpoint URLprimaryQueueEndpoint- Primary queue endpoint URLprimaryTableEndpoint- Primary table endpoint URL
addTag(key, value)- Add a tag to the storage accountremoveTag(key)- Remove a tag from the storage account
This module uses the VersionedAzapiResource framework to provide:
- Single Implementation: One class handles all API versions
- Schema-Driven: TypeScript schemas define version-specific properties
- Automatic Validation: Properties validated against API schemas
- Version Resolution: Automatic latest version detection
- JSII Compliance: Full multi-language support
If you're migrating from version-specific storage account classes, simply:
- Import from the unified module
- Optionally specify
apiVersionif you need version pinning - All other properties remain the same
// Old approach (version-specific)
import { Group as StorageAccount } from './v2023-01-01';
// New approach (unified)
import { StorageAccount } from '@cdktf/tf-constructs-azure/azure-storageaccount';
// Optionally pin version for compatibility
const storage = new StorageAccount(this, 'storage', {
apiVersion: '2023-01-01',
// ... rest of props
});
## Monitoring
The Storage Account construct provides built-in monitoring capabilities through the `defaultMonitoring()` static method.
### Default Monitoring Configuration
```typescript
import { StorageAccount } from '@cdktf/azure-storageaccount';
import { ActionGroup } from '@cdktf/azure-actiongroup';
import { LogAnalyticsWorkspace } from '@cdktf/azure-loganalyticsworkspace';
const actionGroup = new ActionGroup(this, 'alerts', {
// ... action group configuration
});
const workspace = new LogAnalyticsWorkspace(this, 'logs', {
// ... workspace configuration
});
const storageAccount = new StorageAccount(this, 'storage', {
name: 'mystorageaccount',
location: 'eastus',
resourceGroupName: resourceGroup.name,
// ... other properties
monitoring: StorageAccount.defaultMonitoring(
actionGroup.id,
workspace.id
)
});The default monitoring configuration includes:
-
Availability Alert
- Metric:
Availability - Threshold: 99.9% (default)
- Severity: Error (1)
- Triggers when storage account availability drops below threshold
- Metric:
-
Egress Alert
- Metric:
Egress - Threshold: 10GB per hour (default)
- Severity: Warning (2)
- Triggers when outbound data transfer exceeds threshold
- Metric:
-
Transactions Alert
- Metric:
Transactions - Threshold: 100,000 per 15 minutes (default)
- Severity: Warning (2)
- Triggers when transaction count exceeds threshold
- Metric:
-
Deletion Alert
- Tracks storage account deletion via Activity Log
- Severity: Informational
Customize thresholds and severities:
const storageAccount = new StorageAccount(this, 'storage', {
name: 'mystorageaccount',
location: 'eastus',
resourceGroupName: resourceGroup.name,
monitoring: StorageAccount.defaultMonitoring(
actionGroup.id,
workspace.id,
{
availabilityThreshold: 99.5, // Custom availability threshold
egressThreshold: 5368709120, // 5GB in bytes
transactionsThreshold: 50000, // 50k transactions
availabilityAlertSeverity: 0, // Critical
enableEgressAlert: false, // Disable egress monitoring
}
)
});All available options:
| Option | Type | Default | Description |
|---|---|---|---|
availabilityThreshold |
number | 99.9 | Availability percentage threshold |
egressThreshold |
number | 10737418240 | Egress bytes threshold (10GB) |
transactionsThreshold |
number | 100000 | Transaction count threshold |
enableAvailabilityAlert |
boolean | true | Enable/disable availability alert |
enableEgressAlert |
boolean | true | Enable/disable egress alert |
enableTransactionsAlert |
boolean | true | Enable/disable transactions alert |
enableDeletionAlert |
boolean | true | Enable/disable deletion tracking |
availabilityAlertSeverity |
0|1|2|3|4 | 1 | Availability alert severity (0=Critical, 4=Verbose) |
egressAlertSeverity |
0|1|2|3|4 | 2 | Egress alert severity |
transactionsAlertSeverity |
0|1|2|3|4 | 2 | Transactions alert severity |