Skip to content

This is a provider for Terraform that lets you provision infrastructure on SoftLayer.

License

Notifications You must be signed in to change notification settings

audunstrand/terraform-provider-softlayer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform provider for SoftLayer

This is a terraform provider that lets you provision servers on SoftLayer via Terraform.

Build status: Build Status

Installing

Binaries are published on Bintray: Download

Copied from the Terraform documentation:

To install a plugin, put the binary somewhere on your filesystem, then configure Terraform to be able to find it. The configuration where plugins are defined is ~/.terraformrc for Unix-like systems and %APPDATA%/terraform.rc for Windows.

You should update your .terraformrc and refer to the binary:

providers {
  softlayer = "/path/to/terraform-provider-softlayer"
}

A note about SSH keys

SoftLayer provisions SSH keys to new virtual servers only once during the creation of the virtual server. You can provision new SSH keys and assign them to the virtual server during the creation process, assign existing SSH keys by ID, or assign a combination of existing and newly provisioned SSH keys. Changing SSH keys assigned to a virtual server is not possible after it has already been created. It will need to be re-created. If you attempt to create a new SSH key using the softlayer_ssh_key resource type, and that key is already in the SoftLayer system, you will get an error stating that the key already exists. If this happens, use the Id of the existing SSH key as in the example below.

To get a list of existing SSH key Id's from SoftLayer, I recommend using the SoftLayer API Python Client. Once the client is setup, you can run the following command and get the existing SSH key Id's from the output:

[[email protected] ~]# slcli sshkey list
............
:........:...........:.................................................:..........................:
:   id   :   label   :                   fingerprint                   :          notes           :
:........:...........:.................................................:..........................:
: 123456 : test1-dev : xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx : Test Key 1               :
: 789101 : test2-dev : xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx : Test Key 2               :
:........:...........:.................................................:..........................:

Using the provider

Here is an example that will setup the following:

  • An SSH key resource.
  • A virtual server resource that uses an existing SSH key.
  • A virtual server resource using an existing SSH key and a Terraform managed SSH key (created as "test_key_1" in the example below).

(create this as sl.tf and run terraform commands from this directory):

provider "softlayer" {
    username = ""
    api_key = ""
}

# This will create a new SSH key that will show up under the \
# Devices>Manage>SSH Keys in the SoftLayer console.
resource "softlayer_ssh_key" "test_key_1" {
    name = "test_key_1"
    public_key = "${file(\"~/.ssh/id_rsa_test_key_1.pub\")}"
    # Windows Example:
    # public_key = "${file(\"C:\ssh\keys\path\id_rsa_test_key_1.pub\")}"
}

# Virtual Server created with existing SSH Key already in SoftLayer \
# inventory and not created using this Terraform template.
resource "softlayer_virtualserver" "myserver1" {
    name = "my_server_1"
    domain = "example.com"
    ssh_keys = ["123456"]
    image_type = "os_code"
    image = "DEBIAN_7_64"
    region = "ams01"
    public_network_speed = 10
    cpu = 1
    ram = 1024
}

# Virtual Server created with a mix of previously existing and \
# Terraform created/managed resources.
resource "softlayer_virtualserver" "myserver2" {
    name = "my_server_2"
    domain = "example.com"
    ssh_keys = ["123456", "${softlayer_ssh_key.test_key_1.id}"]
    image_type = "template_id"
    image = "dacf4db1-69a8-4bc8-bade-f51bd286c4df"
    region = "ams01"
    public_network_speed = 10
    cpu = 1
    ram = 1024
}

You'll need to provide your SoftLayer username and API key, so that Terraform can connect. If you don't want to put credentials in your configuration file, you can leave them out:

provider "softlayer" {}

...and instead set these environment variables:

  • SOFTLAYER_USERNAME: Your SoftLayer username
  • SOFTLAYER_API_KEY: Your API key

Building from source

  1. Install Go on your machine
  2. Set up Gopath
  3. git clone this repository into $GOPATH/src/github.com/finn-no/terraform-provider-softlayer
  4. Run go get to get dependencies
  5. Run go install to build the binary. You will now find the binary at $GOPATH/bin/terraform-provider-softlayer.

Releasing

  1. Update .bintray.json with the new version to be released (e.g. 0.1337), and the release date.
  2. Tag the release: git tag 0.1337
  3. Push the tag: git push --tags
  4. Travis CI will build and release the binaries.

Running

  1. You must create a new key not already added to softlayer (ssh-keygen). We will assume that is id_rsa.
  2. create the example file sl.tf in your working directory
  3. terraform plan
  4. terraform apply
  5. look up the public ip in the softlayer dashboard
  6. ssh -i ~/.ssh/id_rsa.pub root@

About

This is a provider for Terraform that lets you provision infrastructure on SoftLayer.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%