Create a virtual machine if it doesn't exist

Is there anyway for to make octopus create a Hyper-V virtual machine when it needs to deploy and there isn’t a server already available?

The use case for me would be:

  1. We have many projects, most of which do not need to be in a DEV environment if they are not being worked on in the last month
  2. After a month of inactivity the server decommissions itself
  3. I make a change to a project which hasn’t been worked in over a month
  4. Teamcity builds the project successfully and creates a new release in octopus
  5. Octopus sees the new release, checks if a server is available in the DEV environment with a role specific to that project
    6a) If there is octopus deploys to that server
    6b) If there isn’t octopus creates a new VM (powershell script?), adds the machine to the DEV environment with the required role, deploys to it

I guess this might not be an octopus feature but is there a way to wire it up?

I.e. We could run the create VM script as part of the teamcity build process, but how can we add the VM to octopus automatically?

Or is there a different tool which allows this case better?

Hi Nick,

Thanks for getting in touch! So I had a discussion with one of our developers about this and we have a couple of ideas that you could work with here. I will also mention; we do not have much experience or use cases for type of situation so you many need to find what works for you from the ideas I can provide. :slight_smile:

The first idea involves configuring a single image for a specific Environment/Project. The Tentacle is already installed on the image and registered with Octopus. The image may or may not be running in order for you to save on VM resources.

-Check if it is running.

-If not, start the image.

-Once it is started, he Tentacle should appear back online. (You will need to deploy to install Calamari)


The second idea involves creating a brand new image. A base image would exist suitable for the Environment/Project. However, you may need to spin one of these up per customer, branch or release.
You would need a separate Project that determines if a new image needs to be launched.

-If so, run a script that creates a Tenant or Environment, launches it and waits.

-If the Tentacle is already installed, then no instances should exist for it yet in this method. The following steps are used to configure the Tentacle instance and register it with Octopus.

-If the VM Hypervisor gives the VM Client OS enough information to uniquely identify itself (eg instance ID, Hostname), a start-up script can configure the tentacle as a new (and only) instance.

-If not, an external script (e.g. using PS Remoting) needs to supply this to the machine and kick off the tentacle configuration.

These are the best ideas we have at the moment and would love to hear your thoughts and what you end up with.

Below is a link to automating the Tentacle installation.
Automating Tentacle Installation

Best Regards,