Terraform CLI Usage

Terraform CLI Usage

This page describes common CLI commands to consume and publish Terraform assets through Sonatype Nexus Repository.

Retrieve Terraform Content

After configuring Terraform to use the Nexus proxy repository, run Terraform commands as usual from your workspace. The following commands use Nexus repository to retrieve Terraform content:

The following OpenTofu commands use Nexus Repository to retrieve content:

Upload Terraform Modules

Terraform modules are uploaded using the following path structure:

/v1/modules/{namespace}/{name}/{provider}/{version}/{filename}

CURL command:

curl
    -X PUT \
    'https://[NEXUS URL]/repository/<REPO_NAME>/v1/modules/{namespace}/{name}/{provider}/{version}/{filename}' \
    -u 'USERNAME:PASSWORD' \
    -H 'Content-Type: application/zip' \
    --data-binary '@{filename}.zip'

Parameters:

Note

As Terraform does not support a publish command, we use CURL to perform the publish operation.

Terraform module archives must include .tf files to be considered valid. Each module can be up to 100 MB in size and must be packaged as .tar.gz , .tgz, or .zip (recommended).

Upload Terraform Providers

Provider uploads use the following path structure:

/v1/providers/{namespace}/{type}/{version}/download/{os}/{arch}

CURL Command:

curl
    -X PUT \
    'https://[NEXUS URL]/repository/<REPO_NAME>/v1/providers/{namespace}/{type}/{version}/download/{os}/{arch}' \
    -u 'USERNAME:PASSWORD' \
    -H 'Content-Type: application/zip' \
    --data-binary '@{filename}.zip'

Parameters:

Note

The filename is not included in the URL path. Instead, it must be provided in the Content-Disposition header.

When a provider binary is uploaded, Nexus automatically generates provider metadata. A provider package must be a platform-specific binary archive in .zip format. Each provider version can include multiple archives for different operating systems and architectures.