Packer by HashiCorp

You can use Packer 1.3.2 to automate the creation of modified templates.

Installation and configuration

Download and unpack Packer version 1.3.2 executable for target OS and architecture. You must first allocate a public IP address and import the public ssh key to use Packer.

Template file example

In this example we use Fedora 27 [Cloud Images] to create a modified template, using shell provisioner and amazon-ebs builder. In the terms of Packer the configuration file with the description of the created template is called Template and represents as a JSON-file.

template_fedora.json
{
  "builders": [{
    "type": "amazon-ebs",
    "access_key": "<my_ec2_access_key>",
    "secret_key": "<my_ec2_secret_key>",
    "skip_region_validation": true,
    "region": "croc",
    "availability_zone": "ru-msk-vol51",
    "subnet_id": "<subnet_id>",
    "ssh_keypair_name": "cloud_key",
    "ssh_private_key_file": "/home/test_user/.ssh/cloud_key",
    "custom_endpoint_ec2": "https://api.cloud.croc.ru",
    "source_ami": "cmi-9A41F7F9",
    "instance_type": "m2.small",
    "ssh_username": "ec2-user",
    "ami_name": "fedora_modified_cmi",
  }],
  "provisioners" : [{
    "script": "./setup.sh",
    "type": "shell"
  }]
}
setup.sh
#!/bin/sh

echo "have fun!¡" >> ~/.bash_profile

Currently CROC Cloud Platform supports only amazon-ebs builder. You can read the detailed information about creation of Templates in the documentation. In the template_fedora.json example, the following parameters are used:

  • "access_key" and "secret_key" - API access keys, getting of which is described in the documentation;
  • "skip_region_validation" - to skip the region validation step put the true value here;
  • "region" - "croc" the only supported region;
  • "availability_zone" - one of available locations for an instance launch;
  • "subnet_id" - subnet’s id, where instance will be launched;
  • "ssh_keypair_name" - imported ssh key name;
  • "ssh_private_key_file" - path to private ssh key;
  • "custom_endpoint_ec2" - CROC Cloud EC2 API address;
  • "source_ami" - base template id;
  • "instance_type" - type of the instance, launched during the template creation process;
  • "ssh_username" - username for ssh connection;
  • "ami_name" - new template name;