This post is part of the Automating your Pure Storage Infrastructure series.
    Using Terraform to Provision your Pure Storage Infrastructure

Using Terraform to Provision your Pure Storage Infrastructure

Share on:

There are many things I love about the Pure Storage Flasharray, but one of my favorite is how easy it is to integrate into different automation solutions. In this blog I will cover how to use Terraform to provision your Pure Storage Infrastructure. This will be the first post of many that show how easy it is to accomplish the same task using multiple automation methods.

Information on the Pure Storage Terraform Provider

The official site has information on how to use the plugin, and the GitHub has some information as well.

Installing and Setting up the Terraform Provder

The terraform provider is not currently part of the Terraform Registry but I do have a request to get it added, because of that it must manually be installed on your local machine.

  1. Download the latest version of the provider for either MacOS(Darwin), Linux or Windows

  2. Unzip and Copy the terraform-provider-flash to %APPDATA%\terraform.d\plugins on Windows and ~/.terraform.d/plugins on Linux and MacOS.

  3. Create ~/.terraformrc or %APPDATA%/.terraformrc file and add the following code updating the path to be the location to your plugin file:

    1providers {
    2purestorage = "/Users/dstamen/.terraform.d/plugins/terraform-provider-flash"
    3}
    
  4. Thats it, you should be ready to run your Pure Storage Terraform deployment next!

Using Terraform to Provision your Pure Storage Infrastructure

Below is a sample terraform module that will create a volume, two hosts with an ISCSI iqn and then add the hosts and volume to a hostgroup.

 1provider "purestorage" {
 2  username   = pureuser
 3  password   = mypassword
 4  target     = flasharray.my.lab
 5}
 6
 7resource "purestorage_volume" "vol1" {
 8  name = "pure-ds-01"
 9  size = "1048000000"
10}
11
12resource "purestorage_host" "host1" {
13  name = "esxi01"
14  iqn = ["iqn.1998-01.com.vmware:esxi01"]
15  personality = "esxi"
16}
17
18resource "purestorage_host" "host2" {
19  name = "esxi02"
20  iqn = ["iqn.1998-01.com.vmware:esxi02"]
21  personality = "esxi"
22}
23
24resource "purestorage_hostgroup" "hostgroup1" {
25  name = "cluster01"
26  hosts = ["esxi01","esxi02"]
27  volume {
28    vol = "pure-ds-01"
29    lun = "250"
30  }
31  depends_on = [purestorage_host.host1,purestorage_host.host2,purestorage_volume.vol1]
32}

Running your Terraform Module

Run terraform init and make sure the provider is configured right and that it can initialize your module.

Run terraform plan to see what infrastructure changes will be made.

Run terraform apply to provision your Pure Storage Infrastructure.

Run terraform destroy to destroy your provisioned Pure Storage Infrastructure.

Closing

Terraform is an extremely powerful tool and im learning more about it all the time. If you are wondering what else you can do with the Pure Storage Terraform Provider head on over to the resources page to see what resources can be provisioned.

If you have any additional feature requests or problems I recommend raising an issue on the GitHub page.

Any questions or comments? Leave them below.

comments powered by Disqus

See Also