Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Terraform plugin improvements #479

Merged
merged 6 commits into from
Apr 12, 2017
Merged

Conversation

chungers
Copy link
Contributor

@chungers chungers commented Apr 11, 2017

Closes #406

This PR introduces a schema change to the terraform instance plugins' Properties. Previously we have an abstraction that supports only 1 resource (the vm) per Properties. Now we support multiple. In fact, the abstraction has been removed. You can just use any valid tf.json like this:

{
  "resource" : {
    "ibmcloud_infra_file_storage": {
      "csy_test_file_storage1": {
        "iops" : 0.25,
        "type" : "Endurance",
        "datacenter" : "dal10",
        "capacity" : 20
      }
    },
    "softlayer_virtual_guest" : {
       "host" : {
	  "cores": 2,
	  "memory": 2048,
	  "tags": [ "terraform_demo_swarm_mgr_sl" ],
	  "connection": {
	     "user": "root",
	     "private_key": "${file(\"~/.ssh/id_rsa_de\")}"
	     },
	  "hourly_billing": true,
	  "local_disk": true,
	  "network_speed": 100,
	  "datacenter": "dal10",
	  "os_reference_code": "UBUNTU_14_64",
	  "domain": "softlayer.com",
	  "ssh_key_ids": [ "${data.softlayer_ssh_key.public_key.id}" ]
       }
    }
  }
}

Note that there is only one member named host under the softlayer_virtual_guest section. The name host will be replaced by the plugin with a generated name so that the user doesn't have to track hostnames. However, it's possible to have a hostname prefix via the @hostnamePrefix field if supported. There is a check to ensure that zero or at most one vm resource is specified. You can't have multiple vm instances per Properties because the accounting between Terraform and Infrakit will be off.

The example above will be transformed to

{
    "resource": {
      "ibmcloud_infra_file_storage": {
        "csy_test_file_storage1": {
          "capacity": 20,
          "datacenter": "dal10",
          "iops": 0.25,
          "type": "Endurance"
        }
      },
      "softlayer_virtual_guest": {
        "instance-1491942481": {
          "connection": {
            "private_key": "${file(\"~/.ssh/id_rsa_de\")}",
            "user": "root"
          },
          "cores": 2,
          "datacenter": "dal10",
          "domain": "softlayer.com",
          "hostname": "instance-1491942481",
          "hourly_billing": true,
          "local_disk": true,
          "memory": 2048,
          "network_speed": 100,
          "os_reference_code": "UBUNTU_14_64",
          "ssh_key_ids": [
            "${data.softlayer_ssh_key.public_key.id}"
          ],
          "tags": [
            "terraform_demo_swarm_mgr_sl",
            "label1:value1",
            "label2:value2",
            "name:instance-1491942481"
          ],
          "user_metadata": "apt-get update -y\n\napt-get install -y software"
        }
      }
    }
  }

In essence, the plugin is now smarter as it looks for the only supported vm instance spec and injects userdata and tags appropriately. Everything else the user specified is left intact.

This makes it possible to create dependent resources that need to be provisioned and attach to the vm instance, like the storage volume in the above example.

Other in this PR:

  • Defined types that match VM providers
  • Use better typing to define the terraform schema
  • Removed dead code that tries to parse tf state file. This is no longer needed.

@ndegory @kaufers @JacobFrericks @craigyam

David Chung added 4 commits April 11, 2017 13:13
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
Signed-off-by: David Chung <david.chung@docker.com>
@codecov
Copy link

codecov bot commented Apr 11, 2017

Codecov Report

Merging #479 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #479   +/-   ##
=======================================
  Coverage   56.27%   56.27%           
=======================================
  Files          41       41           
  Lines        2662     2662           
=======================================
  Hits         1498     1498           
  Misses       1011     1011           
  Partials      153      153

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a76266...d6f9efa. Read the comment docs.

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "wip-tf" git@github.com:chungers/infrakit.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354273840
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@chungers chungers merged commit 8fb2de6 into docker-archive:master Apr 12, 2017
chungers pushed a commit to chungers/infrakit that referenced this pull request Sep 30, 2017
chungers pushed a commit to chungers/infrakit that referenced this pull request Oct 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Terraform Plugin
2 participants