Because PowerVC is built on top of OpenStack, there are all sorts of cool things that “just work” because of its open source roots. One of those technologies is Terraform from HashiCorp, which is a tool that enables you to write, plan and create infrastructure as code. This is a powerful concept as you can spec out complex infrastructures “in code” and quickly spin them up, change or delete them as needed—and let Terraform manage the minutia of how to orchestrate all of the details. Terraform supports a wealth of “provider” platforms, which allow you to manage resources from OpenStack, Chef, Docker, SoftLayer, AWS, Azure, vSphere and everything in between—it’s really powerful and covers a lot of ground.

As there are already a wealth of great articles out there that describe Terraform in much more detail and why you might find it compelling, I won’t go into all the gory details in this article. Rather, let’s jumpstart things such that you can use Terraform right alongside PowerVC to deploy an environment with a single virtual machine to demonstrate the art of the possible.

Download Terraform

First, download the Terraform binary for your platform; you can run Terraform from anywhere—for example, I ran Terraform from my MacBook and provisioned infrastructure through a remote PowerVC installation for the examples shown in this blog post. After your download finishes, unzip the Terraform binary to a location of your choosing (let’s call this directory $TF_DIR).

Create a Terraform Configuration

Terraform describes infrastructure in a text file [using the “TF” file extension]. Let’s go ahead and create one of these to talk to PowerVC by leveraging the out-of-box Terraform OpenStack provider. In this example, we will describe an infrastructure with a single virtual machine. In the $TF_DIR directory, create a file called main.tf with the following contents:

provider "openstack" {
  user_name   = "<your_user>"
  password    = "<your_password>"
  tenant_name = "ibm-default"
  domain_name = "Default"
  auth_url    = "https://<your_powervc_ip>:5000/v3/"
  insecure    = true
}

resource "openstack_compute_instance_v2" "my-VM" {
  name      = "my-VM"
  image_id  = "<your-image-id>"
  flavor_id = "<your-flavor-id>"

  network {
    uuid = "<your-network-id>"
    name = "<your-network-name>"
  }
}

Replace the items within the <> characters with values that reflect your infrastructure (you can select whichever image, flavor and network that you want). You can retrieve the “uuid values” from your PowerVC installation by using the OpenStack CLIs:

  • source /opt/ibm/powervc/powervcrc
  • openstack image list
  • openstack flavor list
  • openstack network list

Great… now we’ve got our configuration file created!

Get Ready… Start Provisioning

Now it’s time for the fun part—let’s invoke Terraform to start provisioning the infrastructure; all you need to do is run [./terraform apply] and sit back and relax. You should see a series of messages that look like:

openstack_compute_instance_v2.my-VM: Still creating... (10s elapsed)
openstack_compute_instance_v2.my-VM: Still creating... (20s elapsed)
openstack_compute_instance_v2.my-VM: Still creating... (30s elapsed)
openstack_compute_instance_v2.my-VM: Still creating... (40s elapsed)
openstack_compute_instance_v2.my-VM: Still creating... (50s elapsed)
openstack_compute_instance_v2.my-VM: Still creating... (1m0s elapsed)
openstack_compute_instance_v2.my-VM: Still creating... (1m10s elapsed)
openstack_compute_instance_v2.my-VM: Creation complete (ID: de4c62e8-505c-408e-a14e-f1a98b6d3926)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

…that’s it—you just deployed your first VM using Terraform! If you want more verbose details about what’s happening behind the scenes, you can enable debug output by running [env –i OS_DEBUG=1 TF_LOG=DEBUG ./terraform apply]; this is helpful in the event you’re trying to track down a potential problem in your configuration file. From here, you can destroy the environment by running [./terraform destroy] and it will cleanup whatever resource(s) it created.

Parting Thoughts

Now that you see how easy it is to start using Terraform with PowerVC, the doors are wide open for an endless amount of automation within your data center. Whether it’s deploying infrastructure across different cloud providers (including your Power Systems estate managed by PowerVC), deploying software with Chef, firing up Docker containers—Terraform has you covered. Give it a try today and let us know about your story!

2 comments on"Infrastructure as Code: Terraform meets PowerVC"

  1. Hello
    Very good. It works super. May I ask ? I use 2 V7000. But powervc creates lpars always from V7000 where is image sample aix or linux. I looked for command description for disk array. I want to create lpars on the second V7000 (which has not image aix etc ).
    Can you advice me how put (write) to tf file name of V7000 where I want to create powervc lpars ? As it possible. Thanks.

    • Joe Cropper January 23, 2019

      Thanks for the feedback and glad to hear you’re provisioning via Terraform! To your question on deploying to a different V7000… PowerVC does not currently support deploying an image on one storage array to hosts connected to another storage array. Given this restriction, Terraform won’t be able to orchestrate that operation either. That said, you could consider using the image import/export functionality in PowerVC to move the image between arrays and then orchestrate the deployment. Hope this helps and as always, please let us know if you have additional questions or comments!

Join The Discussion

Your email address will not be published. Required fields are marked *