ResourceBuilder
Class OverviewThe ResourceBuilder
class is designed to build and configure various Azure resources, including resource groups, roles, vaults, and virtual networks. It provides a fluent interface for chaining method calls to configure the resources.
Initializes the ResourceBuilder
with the provided name.
const resourceBuilder = new ResourceBuilder('myResource');
createRoles
Enables the creation of roles for the resource group.
resourceBuilder.createRoles();
withRoles
Sets the environment roles for the resource group.
resourceBuilder.withRoles({
// EnvRolesInfo properties
});
createEnvUID
Enables the creation of a User Assigned Identity for encryption purposes.
resourceBuilder.createEnvUID();
withEnvUIDFromVault
Loads the User Assigned Identity from the vault.
resourceBuilder.withEnvUIDFromVault();
withRolesFromVault
Loads roles from the vault.
resourceBuilder.withRolesFromVault();
createRG
Enables the creation of a resource group with optional role enablement properties.
resourceBuilder.createRG({
enableRGRoles: { readOnly: true },
enableVaultRoles: true,
});
withRG
Sets the resource group information.
resourceBuilder.withRG({
resourceGroupName: 'myResourceGroup',
location: 'West US',
});
createVault
Enables the creation of a Key Vault with an optional name.
resourceBuilder.createVault('myKeyVault');
withVault
Sets the Key Vault information.
resourceBuilder.withVault({
// KeyVaultInfo properties
});
withVaultFrom
Loads the Key Vault information from a given name.
resourceBuilder.withVaultFrom('myKeyVault');
linkVaultTo
Links the Key Vault to specified network properties.
resourceBuilder.linkVaultTo({
asPrivateLink: true,
subnetNames: ['subnet1', 'subnet2'],
ipAddresses: ['192.168.1.1', '192.168.1.2'],
});
addSecrets
Adds secrets to the Key Vault.
resourceBuilder.addSecrets({
secretName: pulumi.secret('secretValue'),
});
addCerts
Adds certificates to the Key Vault.
resourceBuilder.addCerts({
name: 'certName',
// other CertBuilderType properties
});
withVnet
Sets the virtual network properties.
resourceBuilder.withVnet({
// ResourceVnetBuilderType properties
});
enableEncryption
Enables or disables encryption.
resourceBuilder.enableEncryption(true);
withLogFrom
Loads log information from a given name.
resourceBuilder.withLogFrom('logName');
withBuilder
Adds a custom builder function.
resourceBuilder.withBuilder((results) => {
// custom builder logic
});
withBuilderIf
Conditionally adds a custom builder function.
resourceBuilder.withBuilderIf(true, (results) => {
// custom builder logic
});
withBuilderAsync
Adds an asynchronous custom builder function.
resourceBuilder.withBuilderAsync(async (results) => {
// custom async builder logic
});
withBuilderAsyncIf
Conditionally adds an asynchronous custom builder function.
resourceBuilder.withBuilderAsyncIf(true, async (results) => {
// custom async builder logic
});
withResource
Adds a custom resource function.
resourceBuilder.withResource((results) => {
// custom resource logic
});
lock
Enables or disables locking of the resource group.
resourceBuilder.lock(true);
build
Builds the configured resources and returns the results.
const results = await resourceBuilder.build();
console.log(results);
Here is a full example demonstrating how to use the ResourceBuilder
class:
import ResourceBuilder from './Builder/ResourceBuilder';
import { ResourceGroupInfo, KeyVaultInfo } from '../types';
const resourceBuilder = new ResourceBuilder('myResource');
resourceBuilder
.createRoles()
.withRoles({
// EnvRolesInfo properties
})
.createEnvUID()
.withEnvUIDFromVault()
.withRolesFromVault()
.createRG({
enableRGRoles: { readOnly: true },
enableVaultRoles: true,
})
.withRG({
resourceGroupName: 'myResourceGroup',
location: 'West US',
})
.createVault('myKeyVault')
.withVault({
// KeyVaultInfo properties
})
.withVaultFrom('myKeyVault')
.linkVaultTo({
asPrivateLink: true,
subnetNames: ['subnet1', 'subnet2'],
ipAddresses: ['192.168.1.1', '192.168.1.2'],
})
.addSecrets({
secretName: pulumi.secret('secretValue'),
})
.addCerts({
name: 'certName',
// other CertBuilderType properties
})
.withVnet({
// ResourceVnetBuilderType properties
})
.enableEncryption(true)
.withLogFrom('logName')
.withBuilder((results) => {
// custom builder logic
})
.withBuilderIf(true, (results) => {
// custom builder logic
})
.withBuilderAsync(async (results) => {
// custom async builder logic
})
.withBuilderAsyncIf(true, async (results) => {
// custom async builder logic
})
.withResource((results) => {
// custom resource logic
})
.lock(true);
const results = await resourceBuilder.build();
console.log(results);
This guideline should help developers understand and reuse the methods in the ResourceBuilder
class effectively.