StorageBuilder Class OverviewThe StorageBuilder class is designed to build and configure an Azure Storage Account with specific configurations such as containers, queues, file shares, CDN, network settings, and policies.
Initializes the StorageBuilder with the provided arguments.
const storageBuilder = new StorageBuilder({
name: 'myStorageAccount',
group: { resourceGroupName: 'myResourceGroup' },
// other necessary arguments
});
asStorageConfigures the storage account as a regular storage account with optional features.
storageBuilder.asStorage({
// StorageFeatureBuilderType properties
});
asStaticWebStorageConfigures the storage account as a static web storage account.
storageBuilder.asStaticWebStorage();
withCdnSets the CDN properties for the storage account.
storageBuilder.withCdn({
// StorageCdnType properties
});
withContainerAdds a container to the storage account.
storageBuilder.withContainer({
name: 'myContainer',
// other ContainerProps properties
});
withQueueAdds a queue to the storage account.
storageBuilder.withQueue('myQueue');
withFileShareAdds a file share to the storage account.
storageBuilder.withFileShare('myFileShare');
withPoliciesSets the policies for the storage account.
storageBuilder.withPolicies({
// StoragePolicyType properties
});
A storage.BlobServiceProperties resource (blob service default) is created for every storage account this builder makes — it is no longer created only when you pass policies.blobProperties. It turns on soft delete for both blobs and containers so an accidental delete is recoverable.
| Setting | Non-production default | Production default |
|---|---|---|
deleteRetentionPolicy.enabled (blobs) |
true |
true |
deleteRetentionPolicy.days |
1 |
7 |
containerDeleteRetentionPolicy.enabled |
true |
true |
containerDeleteRetentionPolicy.days |
1 |
7 |
isVersioningEnabled |
false |
false |
“Production” is the library-wide isPrd flag — true when the Pulumi stack name contains prd (src/Common/AzureEnv/index.ts). No other environment gets the 7-day retention.
Blob versioning is off by default on purpose. The builder hard-codes isHnsEnabled: true on the storage account (Data Lake Gen2 hierarchical namespace), and Azure does not support blob versioning on hierarchical-namespace accounts — enabling it is rejected at deployment time. Only opt in when you know versioning is valid for the account you are building.
Everything you pass in policies.blobProperties is applied after the defaults, so any field you set wins field-by-field while the ones you omit keep the default above:
storageBuilder.withPolicies({
blobProperties: {
// keeps container soft delete at the default, overrides blob soft delete only
deleteRetentionPolicy: { enabled: true, days: 30 },
},
});
Upgrading an existing stack: the first
pulumi upafter taking this version will show a newBlobServicePropertiesresource being created for every storage account, including accounts that never configuredblobProperties. This is expected — it is a create, not a replacement of the storage account.
policies.isBlobVersioningEnabledStoragePolicyType.isBlobVersioningEnabled was declared but never read, so setting it had no effect. It is now honoured, and deprecated at the same time — it will be removed in the next major. Move to blobProperties.isVersioningEnabled, which is applied last and therefore wins over the old flag:
// before — silently did nothing
storageBuilder.withPolicies({ isBlobVersioningEnabled: true });
// after
storageBuilder.withPolicies({
blobProperties: { isVersioningEnabled: true },
});
If you were relying on the old flag, note that it now actually reaches Azure — read the hierarchical-namespace limitation above before keeping it on.
withNetworkSets the network properties for the storage account.
storageBuilder.withNetwork({
// StorageNetworkType properties
});
lockEnables or disables locking of the storage account.
storageBuilder.lock(true);
buildStorageCreates the storage account with the specified configurations.
This method is called internally by the build method and is not typically called directly.
buildCDNConfigures the CDN for the storage account.
This method is called internally by the build method and is not typically called directly.
buildBuilds the storage account and returns the resource information.
const resourceInfo = storageBuilder.build();
console.log(resourceInfo);
Here is a full example demonstrating how to use the StorageBuilder class:
import StorageBuilder from './Builder/StorageBuilder';
import { StorageBuilderArgs } from './types';
const args: StorageBuilderArgs = {
name: 'myStorageAccount',
group: { resourceGroupName: 'myResourceGroup' },
// other necessary arguments
};
const storageBuilder = new StorageBuilder(args);
storageBuilder
.asStorage({
// StorageFeatureBuilderType properties
})
.withCdn({
// StorageCdnType properties
})
.withContainer({
name: 'myContainer',
// other ContainerProps properties
})
.withQueue('myQueue')
.withFileShare('myFileShare')
.withPolicies({
// StoragePolicyType properties
})
.withNetwork({
// StorageNetworkType properties
})
.lock(true);
const resourceInfo = storageBuilder.build();
console.log(resourceInfo);
This guideline should help developers understand and reuse the methods in the StorageBuilder class effectively.