Getting started with the Skytap Terraform provider

Terraform lets you define and create complex virtual infrastructure environments in Skytap.

This quick start guide demonstrates some of the basic functionality of Skytap and the Terraform provider. In this guide, you’ll install Terraform and the Terraform provider on your local machine. Then we’ll use the provider to quickly create Skytap environments from a Skytap template.

Contents

Before you begin

For more information about using Terraform, see the HashiCorp Terraform documentation and videos:

Installing Terraform

First, make sure Terraform is installed.

To install Terraform
  • Download the appropriate Terraform for your operating system, and then follow the instructions at Installing Terraform to install it on your computer.

    Make sure the location of the Terraform provider is in the PATH of the operating system on the computer where you installed it.

Information you’ll need to configure the Terraform provider

To use the Terraform provider to build infrastructure in Skytap, you’ll need to know the following Skytap information:

  • User name
  • API token
  • Region
  • IDs for the template you’ll use to create environments

Using the Skytap Terraform provider

The following example, you’ll use the Skytap Terraform provider to create an environment in Skytap from a Skytap template, add a network to the environment, and then add another VM.

Step 1 – Creating a configuration

To define the new environment

The first part of the configuration defines your Skytap credentials.

provider "skytap" {
  username = "${var.skytap_username}"
  api_token = "${var.skytap_api_token}"
}

Creating an environment

The next part of the configuration defines an environment that will be created from the template 1498907:

# Create an environment
resource "skytap_environment" "two_lpar" {
  template_id = "1498891"
  name = "Two Node LPAR environment"
  description = "Two deployed AIX LPARs with an iSCSI network"
}

The id of the new environment is exported. Use this id to make changes to the environment.

Creating a network

The next part of the configuration defines a second network for the environment.

When you create an environment from a template, the template’s network is also created. Using the Terraform provider, you can modify the network, or add additional networks.

# Create an additional network
resource "skytap_network" "network" {
  environment_id = "${skytap_environment.two_lpar.id}"
  name = "iSCSI"
  domain = "iscsi"
  subnet = "192.168.1.0/24"
  gateway = "192.168.1.254"
  tunnelable = false
}

Adding a VM

The next part of the configuration adds a VM from template 1498907 to the environment.

# Add a vm
resource "skytap_vm" "lpar1" {
  template_id = 1498891
  vm_id = 39131371
  environment_id = "${skytap_environment.two_lpar.id}"
  name = "Node 2 - AIX 7.2 TL3 SP2"
}

Generating the URL for the new environment

# Generate a URL
output "address" {
  value = "https://cloud.skytap.com/configurations/${skytap_environment.two_lpar.id}"
}

Step 2 – Generate the environment

To create the environment

From a command shell in the directory where you created the configuration:

  1. Type terraform init to initialize the configuration. Terraform automatically downloads and installs the Skytap Terraform provider, and displays any errors in the configuration.
  2. Type terraform plan to verify that the configuration is what you intend to generate.
  3. Type terraform apply to run the configuration and create the environment you specified.

    When the environment is built, Terraform displays the URL for the environment in Skytap: https://cloud.skytap.com/configurations/{environment_id}.

Step 3 - Delete the environment

To delete the environment

From a command shell in the directory where you created the configuration:

  • Type terraform destroy to delete the environment.