NetApp / terraform-provider-netapp-cloudmanager

Terraform provider to create NetAPP OCCM instances, CVO resources, volumes, snapshots, ... in Azure, AWS, GCP.
Mozilla Public License 2.0
17 stars 27 forks source link
aws azure cloudmanager cvo netapp netapp-public terraform

Terraform Provider for NetApp Cloud Volumes ONTAP for AWS, GCP and Azure

This is the repository for the Terraform Provider for NetApp Cloud Volumes ONTAP (CVO) for AWS, GCP and Azure. The Provider can be used with Terraform to work with Cloud Volumes ONTAP for AWS, GCP and Azure resources.

For general information about Terraform, visit the official website and the GitHub project page.

The provider plugin was developed by NetApp.

Naming Conventions

The APIs for NetApp Cloud Volumes ONTAP for AWS, GCP and Azure do not require resource names to be unique. They are considered as 'labels' and resources are uniquely identified by 'ids'. However these ids are not user friendly, and as they are generated on the fly, they make it difficult to track resources and automate.

This provider assumes that resource names are unique, and enforces it within its scope. This is not an issue if everything is managed through Terraform, but could raise conflicts if the rule is not respected outside of Terraform.

Using the Provider

The current version of this provider requires Terraform 0.13 or higher to run.

Terraform 0.13 introduces a registry, and you can use directly the provider without building it yourself. See https://registry.terraform.io/providers/NetApp/netapp-cloudmanager

If you want to build it, see the section below.

Note that you need to run terraform init to fetch the provider before deploying.

Provider Documentation

The documentation is available at: https://registry.terraform.io/providers/NetApp/netapp-cloudmanager/latest/docs

The provider is also documented here.

Check the provider documentation for details on entering your connection information and how to get started with writing configuration for NetApp CVO resources.

Controlling the provider version

Note that you can also control the provider version. This is controlled by a required_providers block in your Terraform configuration.

The syntax is as follows:

terraform {
  required_providers {
    netapp-cloudmanager = {
      source = "NetApp/netapp-cloudmanager"
      version = "20.10.0"
    }
  }
}

Read more on provider version control.

Building The Provider

Prerequisites

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.11+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

The following go packages are required to build the provider:

    github.com/Azure/azure-sdk-for-go v46.4.0+incompatible
    github.com/Azure/go-autorest/autorest/azure/auth v0.5.3
    github.com/aws/aws-sdk-go v1.35.5
    github.com/fatih/structs v1.1.0
    github.com/hashicorp/terraform v0.13.4
    github.com/sirupsen/logrus v1.7.0
    golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
    golang.org/x/tools v0.0.0-20201008025239-9df69603baec // indirect

Check go.mod for the latest list.

Cloning the Project

First, you will want to clone the repository to $GOPATH/terraform-provider-netapp-cloudmanager:

mkdir -p $GOPATH
cd $GOPATH
git clone https://github.com/NetApp/terraform-provider-netapp-cloudmanager.git

Running the Build

After the clone has been completed, you can enter the provider directory and build the provider.

cd $GOPATH/terraform-provider-netapp-cloudmanager
make build

Note: go install will move the binary to $GOPATH/bin

Installing the Local Plugin

With Terraform 0.13 or newer, see the sanity check section under Walkthrough example.

With earlier versions of Terraform, after the build is complete, copy the terraform-provider-netapp-cloudmanager binary into the same path as your terraform binary, and re-run terraform init.

After this, your project-local .terraform/plugins/ARCH/lock.json (where ARCH matches the architecture of your machine) file should contain a SHA256 sum that matches the local plugin. Run shasum -a 256 on the binary to verify the values match.

Developing the Provider

NOTE: Before you start work on a feature, please make sure to check the issue tracker and existing pull requests to ensure that work is not being duplicated. For further clarification, you can also ask in a new issue.

See Building the Provider for details on building the provider.

Testing the Provider

NOTE: Testing the provider for NetApp Cloud Volumes ONTAP for AWS, GCP and Azure is currently a complex operation as it requires having a NetApp CVO subscription in CVO to test against. You can then use a .json file to expose your credentials.

Configuring Environment Variables

Most of the tests in this provider require a comprehensive list of environment variables to run. See the individual *_test.go files in the cloudmanager/ directory for more details. The next section also describes how you can manage a configuration file of the test environment variables.

Using the .tf-netapp-cloudmanager-devrc.mk file

The tf-netapp-cloudmanager-devrc.mk.example file contains an up-to-date list of environment variables required to run the acceptance tests. Copy this to $HOME/.tf-netapp-cloudmanager-devrc.mk and change the permissions to something more secure (ie: chmod 600 $HOME/.tf-netapp-cloudmanager-devrc.mk), and configure the variables accordingly.

Running the Acceptance Tests

After this is done, you can run the acceptance tests by running:

$ make testacc

If you want to run against a specific set of tests, run make testacc with the TESTARGS parameter containing the run mask as per below:

make testacc TESTARGS="-run=TestAccNetAppCVOOCCM"

This following example would run all of the acceptance tests matching TestAccNetAppCVOOCCM. Change this for the specific tests you want to run.

Walkthrough example

Installing go and terraform

bash
mkdir tf_na_netapp_cloudmanager
cd tf_na_netapp_cloudmanager

# if you want a private installation, use
export GO_INSTALL_DIR=`pwd`/go_install
mkdir $GO_INSTALL_DIR
# otherwise, go recommends to use
export GO_INSTALL_DIR=/usr/local

linux

curl -O https://dl.google.com/go/go1.15.2.linux-amd64.tar.gz
tar -C $GO_INSTALL_DIR -xvf go1.15.2.linux-amd64.tar.gz

export PATH=$PATH:$GO_INSTALL_DIR/go/bin

curl -O https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_linux_amd64.zip
unzip terraform_0.13.4_linux_amd64.zip
mv terraform $GO_INSTALL_DIR/go/bin

mac

curl -O https://dl.google.com/go/go1.15.2.darwin-amd64.tar.gz
tar -C $GO_INSTALL_DIR -xvf go1.15.2.darwin-amd64.tar.gz

export PATH=$PATH:$GO_INSTALL_DIR/go/bin

curl -O https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_darwin_amd64.zip
unzip terraform_0.13.4_darwin_amd64.zip
mv terraform $GO_INSTALL_DIR/go/bin

Installing dependencies

We're using go.mod to manage dependencies, so there is not much to do.

# make sure git is installed
which git

export GOPATH=`pwd`

Cloning the NetApp provider repository and building the provider

git clone https://github.com/NetApp/terraform-provider-netapp-cloudmanager.git
cd terraform-provider-netapp-cloudmanager
make build
# binary is in: $GOPATH/bin/terraform-provider-netapp-cloudmanager

The build step will install the provider in the $GOPATH/bin directory.

Sanity check

Local installation - linux

mkdir -p /tmp/terraform/netapp.com/netapp/netapp-cloudmanager/20.10.0/linux_amd64
cp $GOPATH/bin/terraform-provider-netapp-cloudmanager /tmp/terraform/netapp.com/netapp/netapp-cloudmanager/20.10.0/linux_amd64

Local installation - mac

mkdir -p ~/.terraform.d/plug-in/netapp.com/netapp/netapp-cloudmanager/20.10.0/darwin_amd64
cp $GOPATH/bin/terraform-provider-netapp-cloudmanager ~/.terraform.d/plug-in/netapp.com/netapp/netapp-cloudmanager/20.10.0/darwin_amd64

Check the provider can be loaded

cd examples/cloudmanager/local
export TF_CLI_CONFIG_FILE=`pwd`/terraform.rc
terraform init

Should do nothing but indicate that Terraform has been successfully initialized!