drunk-pulumi-azure

VmBuilder Class Overview

The VmBuilder class is designed to build and configure an Azure Virtual Machine (VM) instance with specific configurations such as OS, size, login, network settings, encryption, and scheduling.

Constructor

Purpose:

Initializes the VmBuilder with the provided arguments.

Sample Usage:

const vmBuilder = new VmBuilder({
  name: 'myVmInstance',
  group: { resourceGroupName: 'myResourceGroup' },
  // other necessary arguments
});

enableEncryption

Purpose:

Enables encryption for the VM with the specified properties.

Sample Usage:

vmBuilder.enableEncryption({
  diskEncryptionSetId: 'encryption-set-id',
});

withSchedule

Purpose:

Sets the schedule for the VM.

Sample Usage:

vmBuilder.withSchedule({
  startOn: '2023-01-01T00:00:00Z',
  stopOn: '2023-01-01T12:00:00Z',
});

withSubnetId

Purpose:

Sets the subnet ID for the VM.

Sample Usage:

vmBuilder.withSubnetId('subnet-id');

withTags

Purpose:

Sets the tags for the VM.

Sample Usage:

vmBuilder.withTags({
  environment: 'production',
  project: 'myProject',
});

generateLogin

Purpose:

Enables the generation of a random login for the VM.

Sample Usage:

vmBuilder.generateLogin();

withLoginInfo

Purpose:

Sets the login information for the VM.

Sample Usage:

vmBuilder.withLoginInfo({
  adminLogin: 'adminUser',
  password: 'securePassword',
});

withSize

Purpose:

Sets the size of the VM.

Sample Usage:

vmBuilder.withSize('Standard_DS1_v2');

withWindowsImage

Purpose:

Sets the Windows image for the VM.

Sample Usage:

vmBuilder.withWindowsImage({
  publisher: 'MicrosoftWindowsServer',
  offer: 'WindowsServer',
  sku: '2019-Datacenter',
  version: 'latest',
});

withLinuxImage

Purpose:

Sets the Linux image for the VM.

Sample Usage:

vmBuilder.withLinuxImage({
  publisher: 'Canonical',
  offer: 'UbuntuServer',
  sku: '18.04-LTS',
  version: 'latest',
});

ignoreChangesFrom

Purpose:

Specifies properties to ignore changes for.

Sample Usage:

vmBuilder.ignoreChangesFrom('property1', 'property2');

buildLogin

Purpose:

Generates a random login if enabled.

Sample Usage:

This method is called internally by the build method and is not typically called directly.

buildVm

Purpose:

Creates the VM instance with the specified configurations.

Sample Usage:

This method is called internally by the build method and is not typically called directly.

build

Purpose:

Builds the VM instance and returns the resource information.

Sample Usage:

const resourceInfo = vmBuilder.build();
console.log(resourceInfo);

Full Example

Here is a full example demonstrating how to use the VmBuilder class:

import VmBuilder from './Builder/VmBuilder';
import { VmBuilderArgs } from './types';

const args: VmBuilderArgs = {
  name: 'myVmInstance',
  group: { resourceGroupName: 'myResourceGroup' },
  // other necessary arguments
};

const vmBuilder = new VmBuilder(args);

vmBuilder
  .enableEncryption({
    diskEncryptionSetId: 'encryption-set-id',
  })
  .withSchedule({
    startOn: '2023-01-01T00:00:00Z',
    stopOn: '2023-01-01T12:00:00Z',
  })
  .withSubnetId('subnet-id')
  .withTags({
    environment: 'production',
    project: 'myProject',
  })
  .generateLogin()
  .withLoginInfo({
    adminLogin: 'adminUser',
    password: 'securePassword',
  })
  .withSize('Standard_DS1_v2')
  .withWindowsImage({
    publisher: 'MicrosoftWindowsServer',
    offer: 'WindowsServer',
    sku: '2019-Datacenter',
    version: 'latest',
  })
  .ignoreChangesFrom('property1', 'property2');

const resourceInfo = vmBuilder.build();
console.log(resourceInfo);

Summary

This guideline should help developers understand and reuse the methods in the VmBuilder class effectively.