davejab / nexus-repository-terraform

A Nexus Repository 3 plugin that allows usage of Terraform repositories.
Eclipse Public License 1.0
19 stars 6 forks source link
nexus-repository nexus-repository-manager nexus3

Nexus Repository Terraform Format

Maven Central CircleCI Join the chat at https://gitter.im/sonatype/nexus-developers

Table Of Contents

Developing

Requirements

Also, there is a good amount of information available at Bundle Development.

You may also find it helpful to configure your IDE to use the Sonatype Code style.

Download

Find pre-compiled files here.

Building

To build the project and generate the bundle use Maven

mvn clean package -PbuildKar

If everything checks out, the bundle for terraform should be available in the target folder

Build with Docker

docker build -t nexus-repository-terraform .

Run as a Docker container

docker run -d -p 8081:8081 --name nexus-repository-terraform nexus-repository-terraform 

For further information like how to persist volumes check out the GitHub repo for our official image.

After allowing some time to spin up, the application will be available from your browser at http://localhost:8081.

To read the generated admin password for your first login to the web UI, you can use the command below against the running docker container:

docker exec -it nexus-repository-terraform cat /nexus-data/admin.password && echo

For simplicity, you should check Enable anonymous access in the prompts following your first login.

Using Terraform With Nexus Repository Manager 3

We have detailed instructions on how to get started here!

Compatibility with Nexus Repository Manager 3 Versions

The table below outlines what version of Nexus Repository the plugin was built against

Plugin Version Nexus Repository Version
v0.0.1-1 3.31.0-01
v0.0.7 3.38.0-01
v0.0.8 3.41.0-01

If a new version of Nexus Repository is released and the plugin needs changes, a new release will be made, and this table will be updated to indicate which version of Nexus Repository it will function against. This is done on a time available basis, as this is community supported. If you see a new version of Nexus Repository, go ahead and update the plugin and send us a PR after testing it out!

All released versions can be found here.

Features Implemented In This Plugin

Feature Implemented
Proxy :heavy_check_mark:
Hosted
Group

Supported Terraform Commands

Proxy

Command Implemented
terraform init :heavy_check_mark:

Installing the plugin

There are a range of options for installing the terraform plugin. You'll need to build it first, and then install the plugin with the options shown below:

Easiest Install

Thanks to some upstream work in Nexus Repository, it's become a LOT easier to install a plugin. To install the terraform plugin, follow these steps:

Once you've done this, go ahead and either restart Nexus Repo, or go ahead and start it if it wasn't running to begin with.

You should see terraform (proxy) in the available Repository Recipes to use, if all has gone according to plan :)

Temporary Install

Installations done via the Karaf console will be wiped out with every restart of Nexus Repository. This is a good installation path if you are just testing or doing development on the plugin.

(more) Permanent Install

For more permanent installs of the nexus-repository-terraform plugin, follow these instructions:

This will cause the plugin to be loaded with each restart of Nexus Repository. As well, this folder is monitored by Nexus Repository and the plugin should load within 60 seconds of being copied there if Nexus Repository is running. You will still need to start the bundle using the karaf commands mentioned in the temporary install.

(most) Permanent Install

If you are trying to use the terraform plugin permanently, it likely makes more sense to do the following:

This will cause the plugin to be loaded and started with each startup of Nexus Repository.

The Fine Print

It is worth noting that this is NOT SUPPORTED by Sonatype, and is a contribution of ours to the open source community (read: you!)

Don't worry, using this community item does not "void your warranty". In a worst case scenario, you may be asked by the Sonatype Support team to remove the community item in order to determine the root cause of any issues.

Remember:

Phew, that was easier than I thought. Last but not least of all:

Have fun creating and using this plugin and the Nexus platform, we are glad to have you here!

Getting help

Looking to contribute to our code but need some help? There's a few ways to get information:

Integration Tests

There a still some rough edges around writing integration tests, which are noted below. Please report any problems you find.

The project has a “format” module, and an “IT” module. This allows the “format” module to be bundled up and used by the IT framework classes in the “it” module. In this project, the sub module: nexus-repository-terraform is the "format" module. The sub module: nexus-repository-terraform-it is the "it" module.

Debugging ITs

You can connect a remote debugger to port 5005 to debug Integration Tests. Just add the -Dit.debug=true argument when running ITs. For example:

mvn clean verify -Dit.debug=true

After the IT starts (you would see the following in a terminal:

  ...
  [INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default) @ nexus-repository-...-it ---
  ...
  -------------------------------------------------------
   T E S T S
  -------------------------------------------------------
  Running org.sonatype.nexus.plugins...

), you can attach a remote debugger to port 5005. Keep trying to attach the remote debugger until the connection succeeds.

After each IT runs, you have to reconnect the remote debugger.

You can run a single IT by adding the -Dit.test=MyIntegrationTestToRunIT property. The example below also skips running the unit tests.

  mvn clean verify -Dit.debug=true -Dtest=skip -Dit.test=MyIntegrationTestToRunIT

When running ITs, the Nexus Repository Manager will write log output to the following file:

  nexus-repository-terraform/nexus-repository-terraform-it/target/it-data/1/nexus3/log/nexus.log

With multiple ITs, the 1 in the path above will be incremented for each IT.