Skip to main content
Once dev, staging, and production each need the same shape, a keypair plus a VM, with only the sizing and a couple of flags different, copy-pasting that shape three times means fixing a bug in it three times too. Terraform modules and Pulumi components let you write the shape once and instantiate it per environment.

Terraform module

modules/neolite-vm/variables.tf:
modules/neolite-vm/main.tf:
modules/neolite-vm/outputs.tf:
Instantiate it once per environment from the root module. var.console_password here is exactly what the quickstart and project structure tutorials already declared in full. product_id is picked by name per environment, the same pattern used in Environments - never pass a module products[0] directly, since a module has no way to warn its caller that the value is arbitrary:
Confirm "MS 4.2" against your own account’s catalog output first - see Step 1 in the catalog overview. A local ./modules/... source is enough for one repository. Publishing to a module registry is possible but only worth it once more than one repository needs the same module.

Pulumi component

The equivalent in Pulumi is a ComponentResource, shown here in TypeScript:
{ parent: this } registers the keypair and VM as children of the component in Pulumi’s resource tree, so pulumi up and the Pulumi Cloud console show them nested under it instead of as two unrelated top-level resources. Instantiate one per stack. config is exactly what the Pulumi quickstart already declared in full. productId is picked by name, the same pattern used in Environments - never pass a component products[0] directly:

Next steps