Skip to main content

Getting Started with Terraform UXI Provider

Installation and example of using Terraform UXI provider

Updated over a week ago

Terraform is an open-source infrastructure as code (IaC) tool used for provisioning and managing cloud infrastructure resources across multiple cloud providers. For more information, refer to wikipedia. Terraform provides a HashiCorp Configuration Language (HCL) that allows developers and operations teams to define the desired state of their infrastructure as code.

Note: This installation is only for those who are already familiar with Terraform and use Terraform to manage their network and cloud infrastructure.

Installation
The latest release of the provider can be found on releases. You can download the appropriate version of the provider for your operating system using a command line shell or a browser.

This can be useful in environments that do not allow direct access to the Internet.

Install Scripts
See linux, windows, and macOS install scripts that will download the latest release of the provider and install it in the appropriate location for your operating system.

Then, skip to Configure the Terraform Configuration Files to complete the steps.

Linux
The following examples use Bash on Linux (x64).

  • On a Linux operating system with Internet access, download the plugin from GitHub using the shell.

RELEASE=x.y.z wget -q https://github.com/aruba-uxi/terraform-provider-hpeuxi/releases/download/v${RELEASE}/terraform-provider-hpeuxi_${RELEASE}_linux_amd64.zip
  • Extract the plugin.

unzip terraform-provider-hpeuxi_${RELEASE}_linux_amd64.zip -d terraform-provider-hpeuxi_${RELEASE}
  • Create a directory for the provider.

Note

The directory hierarchy that Terraform uses to precisely determine the source of each provider it finds locally.

$PLUGIN_DIRECTORY/$SOURCEHOSTNAME/$SOURCENAMESPACE/$NAME/$VERSION/$OS_$ARCH/

mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/aruba-uxi/hpeuxi/${RELEASE}/linux_amd64
  • Copy the extracted plugin to a target system and move to the Terraform plugins directory.

mv terraform-provider-hpeuxi_${RELEASE}/terraform-provider-hpeuxi_v${RELEASE} ~/.local/share/terraform/plugins/registry.terraform.io/aruba-uxi/hpeuxi/${RELEASE}/linux_amd64
  • Verify the presence of the plugin in the Terraform plugins directory.

cd ~/.local/share/terraform/plugins/registry.terraform.io/aruba-uxi/hpeuxi/${RELEASE}/linux_amd64 ls

macOS
The following example uses Zsh (default) on macOS (Apple Silicon).

  • On a macOS operating system with Internet access, install wget with Homebrew.

brew install wget
  • Download the plugin from GitHub using the shell.

RELEASE=x.y.z wget https://github.com/aruba-uxi/terraform-provider-hpeuxi/releases/download/v${RELEASE}/terraform-provider-hpeuxi_${RELEASE}_darwin_arm64.zip
  • Extract the plugin.

unzip terraform-provider-hpeuxi_${RELEASE}_darwin_arm64.zip -d terraform-provider-hpeuxi_${RELEASE}
  • Create a directory for the provider.

Note

The directory hierarchy that Terraform uses to precisely determine the source of each provider it finds locally.

$PLUGIN_DIRECTORY/$SOURCEHOSTNAME/$SOURCENAMESPACE/$NAME/$VERSION/$OS_$ARCH/

mkdir -p ~/.terraform.d/plugins/registry.terraform.io/aruba-uxi/hpeuxi/${RELEASE}/darwin_arm64
  • Copy the extracted plugin to a target system and move to the Terraform plugins directory.

mv terraform-provider-hpeuxi_${RELEASE}/terraform-provider-hpeuxi_v${RELEASE} ~/.terraform.d/plugins/registry.terraform.io/aruba-uxi/hpeuxi/${RELEASE}/darwin_arm64
  • Verify the presence of the plugin in the Terraform plugins directory.

cd ~/.terraform.d/plugins/registry.terraform.io/aruba-uxi/hpeuxi/${RELEASE}/darwin_arm64 ls

Windows
The following examples use PowerShell on Windows (x64).

  • On a Windows operating system with Internet access, download the plugin using the PowerShell.

Set-Variable -Name "RELEASE" -Value "x.y.z" Invoke-WebRequest https://github.com/aruba-uxi/terraform-provider-hpeuxi/releases/download/v${RELEASE}/terraform-provider-hpeuxi_${RELEASE}_windows_amd64.zip -outfile terraform-provider-hpeuxi_${RELEASE}_windows_amd64.zip
  • Extract the plugin.

Expand-Archive terraform-provider-hpeuxi_${RELEASE}_windows_amd64.zip cd terraform-provider-hpeuxi_${RELEASE}_windows_amd64
  • Copy the extracted plugin to a target system and move to the Terraform plugins directory.

Note

The directory hierarchy that Terraform uses to precisely determine the source of each provider it finds locally.

$PLUGIN_DIRECTORY/$SOURCEHOSTNAME/$SOURCENAMESPACE/$NAME/$VERSION/$OS_$ARCH/

New-Item $ENV:APPDATA\terraform.d\plugins\registry.terraform.io\aruba-uxi\hpeuxi\${RELEASE}\ -Name "windows_amd64" -ItemType "directory" Move-Item terraform-provider-hpeuxi_v${RELEASE}.exe $ENV:APPDATA\terraform.d\plugins\registry.terraform.io\aruba-uxi\hpeuxi\${RELEASE}\windows_amd64\terraform-provider-hpeuxi_v${RELEASE}.exe
  • Verify the presence of the plugin in the Terraform plugins directory.

cd $ENV:APPDATA\terraform.d\plugins\registry.terraform.io\aruba-uxi\hpeuxi\${RELEASE}\windows_amd64 dir

Configure the Terraform Configuration Files

Create and edit the file using any of the built-in editors (you can also use your favorite editor) to create and save a file with a .tf extension into the same directly where you have moved the plugin:

nano uxi.tf

Copy the following contents in the file named 'uxi.tf'.

Example: A Terraform configuration block.

terraform { required_providers { hpeuxi = { source = "HewlettPackard/hpeuxi" version = "0.1.0-alpha.1" } } } provider "hpeuxi" { # Configuration options }

Verify the Terraform Initialization of a Manually Installed Provider
To verify the initialization, navigate to the working directory for your Terraform configuration and run terraform init. You should see a message indicating that Terraform has been successfully initialized and the installed version of the Terraform Provider for HPE UXI.

Example: Initialize and Use a Manually Installed Provider

% terraform init
Initializing the backend... Initializing provider plugins... - Finding hewlettpackard/hpeuxi versions matching "0.1.0-alpha.1"... - Installing hewlettpackard/hpeuxi v0.1.0-alpha.1... - Installed hewlettpackard/hpeuxi v0.1.0-alpha.1 (self-signed, key ID D4B16F4F2C16B845) Partner and community providers are signed by their developers. If you'd like to know more about provider signing, you can read about it here: https://www.terraform.io/docs/cli/plugins/signing.html Terraform has created a lock file .terraform.lock.hcl to record the provider selections it made above. Include this file in your version control repository so that Terraform can guarantee to make the same selections by default when you run "terraform init" in the future. Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.

Get the Provider Version
To find the provider version, navigate to the working directory of your Terraform configuration and run terraform version. You should see a message indicating the provider version.

Example: Terraform Provider Version from the Terraform Registry

% terraform version
Terraform v1.7.5 on darwin_amd64 + provider registry.terraform.io/hewlettpackard/hpeuxi v0.1.0-alpha.1 Your version of Terraform is out of date! The latest version is 1.11.2. You can update by downloading from https://www.terraform.io/downloads.html

Example of using Terraform

Prerequisites

Terraform version >= v1.7.0 and 64-bit install terraform.
A Greenlake API client to authenticate against UXI configuration API.

See here for more information on generating client credentials.

  • Open the previously generated file using nano uxi.tf and add client id and client secret of the UXI from the GreenLake account

    terraform {
    required_providers {
    hpeuxi = {
    source = "HewlettPackard/hpeuxi"
    version = "0.1.0-alpha.1"
    }
    }
    }
    # ====================== PROVIDER CONFIGURATION =======================

    provider "hpeuxi" {
    # Replace with actual provider configuration
    client_id = <your client_id> (RATHER USE HPEUXI_CLIENT_ID ENV VAR)
    client_secret = <your client_secret> (RATHER USE HPEUXI_CLIENT_SECRET ENV VAR)
    }

Note: We recommend secrets (GreenLake credentials) be stored as environment variables, as shown here: https://registry.terraform.io/providers/HewlettPackard/hpeuxi/latest/docs#optional

  • Run the first Terraform Execution Plan.

The best way to get started using Terraform is to run execution plans. All Terraform plans are written in HCL (Hashicorp Configuration Language). HCL is very similar to the JSON format.

Example:

Open the file using the nano uxi.tf and copy the following code from here

terraform {
required_providers {
hpeuxi = {
source = "HewlettPackard/hpeuxi"
version = "0.1.0-alpha.1"
}
}
}

# ====================== PROVIDER CONFIGURATION =======================

provider "hpeuxi" {
# Replace with actual provider configuration
client_id = <your client_id> (RATHER USE HPEUXI_CLIENT_ID ENV VAR)
client_secret = <your client_secret> (RATHER USE HPEUXI_CLIENT_SECRET ENV VAR)
}

# ============================== GROUP RESOURCE CONFIGURATION ======================================

# Create level 1 group attached to the root node
resource "hpeuxi_group" "level_1" {
name = "Parent Group"
}

# Create level 2 group attached to level 1 group
resource "hpeuxi_group" "level_2" {
name = "Child Group"
parent_group_id = hpeuxi_group.level_1.id
}

# ============================== AGENT RESOURCE CONFIGURATION ======================================

# Declare an agent resource
resource "hpeuxi_agent" "my_agent" {
name = "HPE-YQ5G7FLWQ9"
notes = "notes"
pcap_mode = "light"
}

# Import agent using its ID with an import block
import {
to = hpeuxi_agent.my_agent
id = "e9199fe1-d055-39bc-b691-593e645e6783"
}

# Assign an agent to a group
resource "hpeuxi_agent_group_assignment" "my_agent_group_assignment" {
agent_id = hpeuxi_agent.my_agent.id
group_id = hpeuxi_group.level_2.id
}

# ============================== SENSOR RESOURCE CONFIGURATION =====================================

# Declare a sensor resource
resource "hpeuxi_sensor" "my_sensor" {
name = "name"
address_note = "Example 3rd Floor"
notes = "notes"
pcap_mode = "light"
# Deleting a sensor is not supported
lifecycle {
prevent_destroy = true
}
}

# Import sensor using its ID with an import block
import {
to = hpeuxi_sensor.my_sensor
id = <sensor_id>
}

# Assign a sensor to a group
resource "hpeuxi_sensor_group_assignment" "my_sensor_group_assignment" {
sensor_id = = hpeuxi_sensor.my_sensor.id
group_id = hpeuxi_group.level_2.id
}

# ============================== WIRED NETWORK RESOURCE CONFIGURATION ==============================

# Declare a wired network resource
resource "hpeuxi_wired_network" "my_wired_network" {
name = "tf-ethernet-0"

# Deleting of wired networks is not supported yet
lifecycle {
prevent_destroy = true
}
}

# Import a wired network using its ID with an import block
import {
to = hpeuxi_wired_network.my_wired_network
id = <wired_network_id>
}

# Assign a wired network to the parent group (group and group children sensors will test this
# network)
resource "hpeuxi_network_group_assignment" "my_wired_network_group_assignment" {
network_id = hpeuxi_wired_network.my_wired_network.id
group_id = hpeuxi_group.level_1.id
}

# ============================== WIRELESS NETWORK RESOURCE CONFIGURATION ===========================

# Declare a wireless network resource
resource "hpeuxi_wireless_network" "my_wireless_network" {
name = "tf-ssid-0"
# Deleting of wireless networks is not supported yet
lifecycle {
prevent_destroy = true
}
}

# Import a wireless network using its ID with an import block
import {
to = hpeuxi_wireless_network.my_wireless_network
id = <wireless_network_id>
}

# Assign a wireless network to the parent group (group and group children sensors will test this
# network)
resource "hpeuxi_network_group_assignment" "my_wireless_network_group_assignment" {
network_id = hpeuxi_wireless_network.my_wireless_network.id
group_id = hpeuxi_group.level_1.id
}

# ============================== SERVICE TEST RESOURCE CONFIGURATION ===============================

# Declare a service test resource
resource "hpeuxi_service_test" "my_service_test" {
name = "Google"

# Deleting of service tests is not supported yet
lifecycle {
prevent_destroy = true
}
}

# Import a service test using its ID with an import block
import {
to = hpeuxi_service_test.my_service_test
id = <service_test_id>
}

# Assign a service test to the parent group (group and group children sensors will test this
# service test)
resource "hpeuxi_service_test_group_assignment" "my_service_test_group_assignment" {
service_test_id = hpeuxi_service_test.my_service_test.id
group_id = hpeuxi_group.level_1.id
}
  • Run the plan using the following commands

terraform init
terraform plan
terraform apply

How to get the IDs of resources for import reasons?

To get the IDs, one could either use the configuration API GET Endpoint(s).

Using API GET Endpoint:

Example: To get sensor_id You can run the sensor GET endpoint and see the id field below:

{ 
"id": "06a2c5d6-ba8f-421c-b6b1-3aedc15ac08c",
"serial": "CNHJKLQ2M6",
"name": "CNHJKLQ2M6",
"modelNumber": "UX-F5C",
"wifiMacAddress": "20:4c:03:50:79:23",
"ethernetMacAddress": "20:4c:03:50:79:22",
"addressNote": "",
"longitude": -121.9880602,
"latitude": 37.3860927,
"notes": "",
"pcapMode": "light",
"type": "networking-uxi/sensor"
}

Finding the right Terraform resource/data-source

We have all the resources that can help you manage the sensors, agents, groups, and tests.

We have all the data sources that can help you retrieve information from sensors, agents, groups, and tests.

Please follow this link to check out all the resources and data sources.
​

Did this answer your question?