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');
createRolesEnables the creation of roles for the resource group.
resourceBuilder.createRoles();
withRolesSets the environment roles for the resource group.
resourceBuilder.withRoles({
// EnvRolesInfo properties
});
createEnvUIDEnables the creation of a User Assigned Identity for encryption purposes.
resourceBuilder.createEnvUID();
withEnvUIDFromVaultLoads the User Assigned Identity from the vault.
resourceBuilder.withEnvUIDFromVault();
withRolesFromVaultLoads roles from the vault.
resourceBuilder.withRolesFromVault();
createRGEnables the creation of a resource group with optional role enablement properties.
resourceBuilder.createRG({
enableRGRoles: { readOnly: true },
enableVaultRoles: true,
});
withRGSets the resource group information.
resourceBuilder.withRG({
resourceGroupName: 'myResourceGroup',
location: 'West US',
});
createVaultEnables the creation of a Key Vault with an optional name.
resourceBuilder.createVault('myKeyVault');
withVaultSets the Key Vault information.
resourceBuilder.withVault({
// KeyVaultInfo properties
});
withVaultFromLoads the Key Vault information from a given name.
resourceBuilder.withVaultFrom('myKeyVault');
linkVaultToLinks the Key Vault to specified network properties.
resourceBuilder.linkVaultTo({
asPrivateLink: true,
subnetNames: ['subnet1', 'subnet2'],
ipAddresses: ['192.168.1.1', '192.168.1.2'],
});
addSecretsAdds secrets to the Key Vault.
resourceBuilder.addSecrets({
secretName: pulumi.secret('secretValue'),
});
addCertsAdds certificates to the Key Vault.
resourceBuilder.addCerts({
name: 'certName',
// other CertBuilderType properties
});
withVnetSets the virtual network properties.
resourceBuilder.withVnet({
// ResourceVnetBuilderType properties
});
enableEncryptionEnables or disables encryption.
resourceBuilder.enableEncryption(true);
withLogFromLoads log information from a given name.
resourceBuilder.withLogFrom('logName');
withBuilderAdds a custom builder function.
resourceBuilder.withBuilder((results) => {
// custom builder logic
});
withBuilderIfConditionally adds a custom builder function.
resourceBuilder.withBuilderIf(true, (results) => {
// custom builder logic
});
withBuilderAsyncAdds an asynchronous custom builder function.
resourceBuilder.withBuilderAsync(async (results) => {
// custom async builder logic
});
withBuilderAsyncIfConditionally adds an asynchronous custom builder function.
resourceBuilder.withBuilderAsyncIf(true, async (results) => {
// custom async builder logic
});
withResourceAdds a custom resource function.
resourceBuilder.withResource((results) => {
// custom resource logic
});
lockEnables or disables locking of the resource group.
resourceBuilder.lock(true);
buildBuilds 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.