Digital Ocean is awesome. Not only can you get a Linux machine for $5/month, but you can even pay them by the hour. That means you can rent a Virtual machine with 16GB memory and 8 cores for an hour and pay only $0.238. That can be great to test something or to use the machine to build your project. Not only that, but they will even give you some money back if you use the affiliate link. In this article you'll see a number of examples to automatically create a DigitalOcean Droplet using a Perl script.

Setup

Before you can do any of these, you first need to create an account where I think you need to provide the Credit Card information for when they need to charge you money.

Once you have done that you need to visit the Apps & API. Because the CPAN module currently (version 0.09) only supports the old API of DigitalOcean you will need to follow the link that leads to API v1.0 Page. There you'll see a Client ID and a big blue button Generate new key. You need to click on that button. Then you'll have both a Client ID and an API Key.

Configuration

In order to avoid having this private information in the source code, I prefer to have a configuration file which won't be in a version control system seen by many other people. So I created a file called .digitalocean in my home directory. On Windows, I'd probably create a file called digitalocean.ini.

The configuration file does not need to be complex. Mine looks like this:

[one] client_id = u0_CRTY7o6VabadsefeERTA api_key = 4564aa4ljada998dlkadljahelliaeak67cef

Then I can use Config::Tiny to read this information and Data::Dumper just to see how it is read by this module.

use strict; use warnings; use 5.010; use Config::Tiny; use Data::Dumper qw(Dumper); my $Config = Config::Tiny->read( '/home/gabor/.digitalocean', 'utf8' ); die Dumper $Config;

$VAR1 = bless( { 'one' => { 'client_id' => 'u0_CRTY7o6VabadsefeERTA', 'api_key' => '4564aa4ljada998dlkadljahelliaeak67cef' } }, 'Config::Tiny' );