Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/test-install-scripts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2025 Hewlett Packard Enterprise Development LP

name: Test Installation Scripts

on:
push:
branches:
- main
pull_request:
paths:
- 'scripts/install-hpe-provider-*.sh'
- 'scripts/install-hpe-provider-*.ps1'
- 'scripts/test/**'
- '.github/workflows/test-install-scripts.yaml'

jobs:
test-macos:
name: Test macOS Installation Script
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Install BATS
run: brew install bats-core

- name: Run BATS tests
run: bats scripts/test/install-hpe-provider-macos.bats

test-linux:
name: Test Linux Installation Script
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install BATS
run: |
sudo apt-get update
sudo apt-get install -y bats

- name: Run BATS tests
run: bats scripts/test/install-hpe-provider-linux.bats

test-windows:
name: Test Windows Installation Script
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Run Pester tests
shell: pwsh
run: |
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser
Import-Module Pester
Invoke-Pester -Path scripts/test/install-hpe-provider-windows.Tests.ps1 -Output Detailed
198 changes: 198 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# Installing the Terraform Provider for HPE

This document assumes the use of Terraform 0.13 or later.


## Installation

The latest release of the provider can be found on [`https://github.com/HPE/terraform-provider-hpe/releases`][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](./scripts/install-hpe-provider.sh), [windows](./scripts/install-hpe-provider-windows.ps1), and
[macOS](./scripts/install-hpe-provider-macos.sh) 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](#configure-the-terraform-configuration-files) to complete the
steps.

### Linux

The following examples use Bash on Linux (x64).

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

```console
RELEASE=x.y.z
wget -q https://github.com/HPE/terraform-provider-hpe/releases/download/v${RELEASE}/terraform-provider-hpe_${RELEASE}_linux_amd64.zip
```

2. Extract the plugin.

```console
unzip terraform-provider-hpe_${RELEASE}_linux_amd64.zip -d terraform-provider-hpe_${RELEASE}
```

3. 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/`

```console
mkdir -p ~/.local/share/terraform/plugins/registry.terraform.io/hpe/hpe/${RELEASE}/linux_amd64
```

4. Copy the extracted plugin to a target system and move to the Terraform plugins directory.

```console
mv terraform-provider-hpe_${RELEASE}/terraform-provider-hpe_v${RELEASE} ~/.local/share/terraform/plugins/registry.terraform.io/hpe/hpe/${RELEASE}/linux_amd64
```

5. Verify the presence of the plugin in the Terraform plugins directory.

```console
cd ~/.local/share/terraform/plugins/registry.terraform.io/hpe/hpe/${RELEASE}/linux_amd64
ls
```

### macOS

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

1. On a macOS operating system with Internet access, install wget with [Homebrew](https://brew.sh).

```console
brew install wget
```

2. Download the plugin from GitHub using the shell.

```console
RELEASE=x.y.z
wget -q https://github.com/HPE/terraform-provider-hpe/releases/download/v${RELEASE}/terraform-provider-hpe_${RELEASE}_darwin_arm64.zip
```

3. Extract the plugin.

```console
unzip terraform-provider-hpe_${RELEASE}_darwin_arm64.zip -d terraform-provider-hpe_${RELEASE}
```

4. 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/`

```console
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hpe/hpe/${RELEASE}/darwin_arm64
```

5. Copy the extracted plugin to a target system and move to the Terraform plugins directory.

```console
mv terraform-provider-hpe_${RELEASE}/terraform-provider-hpe_v${RELEASE} ~/.terraform.d/plugins/registry.terraform.io/hpe/hpe/${RELEASE}/darwin_arm64
```

6. Verify the presence of the plugin in the Terraform plugins directory.

```console
cd ~/.terraform.d/plugins/registry.terraform.io/hpe/hpe/${RELEASE}/darwin_arm64
ls
```

### Windows

The following examples use PowerShell on Windows (x64).

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

```powershell
Set-Variable -Name "RELEASE" -Value "x.y.z"
Invoke-WebRequest https://github.com/HPE/terraform-provider-hpe/releases/download/v${RELEASE}/terraform-provider-hpe_${RELEASE}_windows_amd64.zip -outfile terraform-provider-hpe_${RELEASE}_windows_amd64.zip
```

2. Extract the plugin.

```powershell
Expand-Archive terraform-provider-hpe_${RELEASE}_windows_amd64.zip
cd terraform-provider-hpe_${RELEASE}_windows_amd64
```

3. 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/`

```powershell
New-Item $ENV:APPDATA\terraform.d\plugins\registry.terraform.io\hpe\hpe\${RELEASE}\ -Name "windows_amd64" -ItemType "directory"

Move-Item terraform-provider-hpe_v${RELEASE}.exe $ENV:APPDATA\terraform.d\plugins\registry.terraform.io\hpe\hpe\${RELEASE}\windows_amd64\terraform-provider-hpe_v${RELEASE}.exe
```

4. Verify the presence of the plugin in the Terraform plugins directory.

```powershell
cd $ENV:APPDATA\terraform.d\plugins\registry.terraform.io\hpe\hpe\${RELEASE}\windows_amd64
dir
```

### Configure the Terraform Configuration Files

A working directory can be initialized with providers that are installed locally on a system by using `terraform init`. The Terraform configuration block is used to configure some behaviors of Terraform itself, such as the Terraform version and the required providers source and version.

**Example**: A Terraform configuration block.

```hcl
terraform {
required_providers {
hpe = {
source = "HPE/hpe"
version = ">= 0.4.0"
}
}
required_version = ">= 1.11"
}
```

### 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.

**Example**: Initialize and Use a Manually Installed Provider

```console
% terraform init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hpe/hpe from the dependency lock file
- Installing hpe/hpe x.y.z...
- Installed hpe/hpe x.y.z (unauthenticated)

Terraform has been successfully initialized!
```

## 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

```console
% terraform version
Terraform x.y.z
on darwin_arm64
+ provider registry.terraform.io/hpe/hpe x.y.z
```
16 changes: 16 additions & 0 deletions scripts/gofmtcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

set -e

# Check gofmt
echo "==> Checking that code complies with gofmt requirements..."
gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`)
echo $gofmt_files
if [ ! -z ${gofmt_files} ]; then
echo 'gofmt needs running on the following files:'
echo "${gofmt_files}"
echo "You can use the command: \`make fmt\` to reformat code."
exit 1
fi

exit 0
38 changes: 38 additions & 0 deletions scripts/install-hpe-provider-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -e

os="darwin"

if [[ `uname -m` == 'x86_64' ]]
then
echo 'Intel Architecture detected'
arch="amd64"
elif [[ `uname -m` == 'arm64' ]]
then
echo 'Apple Silicon Architecture detected'
arch="arm64"
fi

repo="HPE/terraform-provider-hpe"
macos_hpe_dir="${HOME}/.terraform.d/plugins/registry.terraform.io/hpe/hpe"

get_latest_release () {
local release_url="https://api.github.com/repos/${repo}/releases/latest"
curl -sL "$release_url" | ggrep -Po '"tag_name": "\K.*?(?=")'
}

download_and_extract () {
local dest_dir="${macos_hpe_dir}/${version_number}/${os}_${arch}/"
local hpe_zip="terraform-provider-hpe_${version_number}_${os}_${arch}.zip"
local hpe_dl_url="https://github.com/${repo}/releases/download/${VERSION}/${hpe_zip}"

mkdir -p "$dest_dir" && cd "$dest_dir"
curl -sL "$hpe_dl_url" -o "$hpe_zip" && \
unzip -u "$hpe_zip" && \
rm -f "$hpe_zip"
}

VERSION=${VERSION:=$(get_latest_release)}
version_number=${VERSION//v}
download_and_extract
55 changes: 55 additions & 0 deletions scripts/install-hpe-provider-windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
param ($VERSION)

$os="windows"
$arch="amd64"
$repo="HPE/terraform-provider-hpe"
$windows_hpe_dir="$env:appdata\terraform.d\plugins\registry.terraform.io\hpe\hpe"

$users_pwd = Get-Location

function get_latest_release {
Write-Host Getting latest release
$release_url="https://api.github.com/repos/${repo}/releases/latest"
$tag = (Invoke-WebRequest $release_url | ConvertFrom-Json)[0].tag_name
$VERSION=${tag}

$VERSION
}

if (!$VERSION) {
$VERSION=get_latest_release
}

$version_number=$VERSION -replace 'v'

$dest_dir="${windows_hpe_dir}\${version_number}\${os}_${arch}\"
$hpe_zip="terraform-provider-hpe_${version_number}_${os}_${arch}.zip"
$hpe=$hpe_zip -replace '.zip'
$hpe_dl_url="https://github.com/${repo}/releases/download/${VERSION}/${hpe_zip}"

New-Item -ItemType Directory -Path "$dest_dir" -Force | Out-Null
Set-Location "$dest_dir"

try {
Invoke-WebRequest $hpe_dl_url -Out $hpe_zip
}
catch {
Write-Host "Error: The version that was specified does not exist."

Set-Location "${users_pwd}"
Remove-Item -Path "${windows_hpe_dir}\${version_number}" -Recurse -Force -ErrorAction SilentlyContinue

Write-Host "Exiting..."
Return
}

Write-Host Extracting release files
Expand-Archive $hpe_zip -Force

Get-ChildItem -Path $hpe -Recurse -File | Move-Item -Destination $dest_dir -Force

Remove-Item $hpe_zip -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $hpe -Recurse -Force -ErrorAction SilentlyContinue
Write-Host Complete

Set-Location "${users_pwd}"
28 changes: 28 additions & 0 deletions scripts/install-hpe-provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -e

os="linux"
arch="amd64"
repo="HPE/terraform-provider-hpe"
linux_hpe_dir="${HOME}/.local/share/terraform/plugins/registry.terraform.io/hpe/hpe"

get_latest_release () {
local release_url="https://api.github.com/repos/${repo}/releases/latest"
curl -sL "$release_url" | grep -Po '"tag_name": "\K.*?(?=")'
}

download_and_extract () {
local dest_dir="${linux_hpe_dir}/${version_number}/${os}_${arch}/"
local hpe_zip="terraform-provider-hpe_${version_number}_${os}_${arch}.zip"
local hpe_dl_url="https://github.com/${repo}/releases/download/${VERSION}/${hpe_zip}"

mkdir -p "$dest_dir" && cd "$dest_dir"
curl -sL "$hpe_dl_url" -o "$hpe_zip" && \
unzip -u "$hpe_zip" && \
rm -f "$hpe_zip"
}

VERSION=${VERSION:=$(get_latest_release)}
version_number=${VERSION//v}
download_and_extract
Loading