Infrastructure as Code using Terraform and NetApp Service Level Manager

Terraform is a popular tool from HashiCorp that’s widely used by data center admins for managing and provisioning infrastructure as code. In this blog, let’s look at how to use Terraform and NetApp Service Level Manager (NSLM) for provisioning a LUN in ONTAP.

Before we start, this blog assumes a couple of things:

  • You have (some) experience with Terraform, the different provisioners and providers that come out of the box, its configuration files, tfstate files, etc.
  • You are comfortable with the Go language and its code organization.
  • You have basic idea of NSLM.

Getting Started

First, we must decide on the parameters we would take from admin for creating a LUN. Here is the input:

  • host: This is the hostname where NSLM is deployed
  • user_name: Username to be used to login to NSLM
  • password: Password to login to NSLM
  • svm: The Storage Virtual Machine on which we got to create the LUN
  • storage_service_level_name: This is the SSL name to be used while deciding where to create the LUN for the given application’s QoS needs.
  • lun_name: Name of the LUN
  • lun_size: Size of LUN to be created

Next, we need to define a resource schema under the project root as provider.go:

The resource name is “netapp_lun” here and any Terraform script which wants to import this resource would do it like as shown below in main.tf file under project root:

Once we have this in place, we need to declare the CRUD handlers as part of resourceNetappLun() under “resource_netapp_lun.go” file under project root (which gets invoked when the script runs).

Using Terraform to Provision Storage

Once we declare the CRUD handlers, we then need to define these handlers. For this example, let’s take a look at the implementation of Create operation (i.e: lunCreate()).

The basic flow is:

  • Fetch the SVM key using SVM name.

  • Fetch the SSL key for the given value.

  • Formulate a JSON body that consists of SVM key, SSL key, LUN name and LUN size.

  •  Invoke a POST method with the JSON body as text.

Once we have the required code in place, build the GO code.

File layout for Terraform providerBuilding the Terraform provider for NSLM using Go

Run the terraform commands

Creating a LUN with Terraform

Here is a small demo which captures the state of the controller before and after running the Terraform script.

To summarize, what we have demonstrated here is a new Netapp provider resource for LUN creation in Terraform that uses NSLM to provision storage from ONTAP. We can extend the same to have resources for file shares and other storage attributes which NSLM supports today. Watch out for a blog series in the future for more on Terraform + NSLM use cases to see a complete end-to-end application deployment stack!

If you have questions please use the comments below or reach out using our Slack channels!

Rakshith Venkatesh
Technical Marketing Engineer/Solution Architect at Netapp.Inc
I joined Netapp right after college as a NCG. Started off as a Sustenance Engineer in EPS org where I worked on the debugging the breadth of ONTAP stack while resolving customer issues. Then joined the Enterprise File services group as a developer. I was part of RESTful HTTP server implementation in CDOT which laid the foundation for supporting S3 natively in ONTAP. My last project was on implementing “Object store client” for “Fabric Pool” that helps in tiering data to backend object store servers such as S3/Azure.

I am now a TME/Solution Architect for APIS and NSLM DFMG product suite

Leave a Reply