Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/smutel/terraform-provider-netbox

Terraform provider for Netbox
https://github.com/smutel/terraform-provider-netbox

Last synced: 3 months ago
JSON representation

Terraform provider for Netbox

Lists

README

        

# terraform-provider-netbox

[![Lisence](https://img.shields.io/badge/license-ISC-informational?style=flat-square)](https://github.com/smutel/terraform-provider-netbox/blob/master/LICENSE)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-informational.svg?style=flat-square&logo=git)](https://conventionalcommits.org)
[![Build Status](https://img.shields.io/github/actions/workflow/status/smutel/terraform-provider-netbox/master.yml?branch=master&style=flat-square)](https://github.com/smutel/terraform-provider-netbox/actions/workflows/master.yml)
[![Issues](https://img.shields.io/github/issues-raw/smutel/terraform-provider-netbox?style=flat-square)](https://github.com/smutel/terraform-provider-netbox/issues)
[![Last release](https://img.shields.io/github/v/release/smutel/terraform-provider-netbox?style=flat-square)](https://github.com/smutel/terraform-provider-netbox/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/smutel/terraform-provider-netbox/v7?style=flat-square)](https://goreportcard.com/report/github.com/smutel/terraform-provider-netbox/v7)

Terraform provider for [Netbox.](https://netbox.readthedocs.io/en/stable/)

## Requirements

* A libc library like libc6-compat or libc-utils
* General developer tools like make, bash, ... (to build the provider)
* Go 1.21 minimum (to build the provider)
* Terraform (to use the provider)

## Compatibility with Netbox

| Netbox version | Provider version |
|:--------------:|:----------------:|
| 2.8 | 0.x.y |
| 2.9 | 1.x.y |
| 2.11 | 2.x.y |
| 3.0 | 3.x.y |
| 3.1 | 4.x.y |
| 3.2 | 5.x.y |
| 3.3 | 6.x.y |
| 3.4 | 7.x.y |

## go-netbox

This project does not use [netbox-community/go-netbox](https://github.com/netbox-community/go-netbox) but the same library generated by myself located here [smutel/go-netbox](https://github.com/smutel/go-netbox) for three reasons:
* By the past this project was not maintained anymore so I decided to create my own project
* I am using a [patch strategy](https://github.com/smutel/go-netbox/tree/main/patchs) and generation of the library [by the CI](https://github.com/smutel/go-netbox/blob/main/utils/netbox_generate_client)
* I does not need to wait if I need a patch quickly

## Building the provider

Clone repository to: ``$GOPATH/src/github.com/smutel/terraform-provider-netbox``

```shell
mkdir -p $GOPATH/src/github.com/smutel
cd $GOPATH/src/github.com/smutel
git clone [email protected]:smutel/terraform-provider-netbox.git
```

Enter the provider directory and build the provider

```shell
cd $GOPATH/src/github.com/smutel/terraform-provider-netbox
make build
```

# Testing

To run the tests you need to have a running netbox installation. For example netbox-docker.

To run the tests execute:
```shell
source utils/netbox_docker_variables.sh
TF_ACC=1 go test -v ./...
```
Scheme and URL are not needed it the default is used (https and localhost:8000)

To run only some tests execute the following:
```shell
source utils/netbox_docker_variables.sh
TF_ACC=1 go test -v ./... -run TestAccNetboxVirtualizationVM
```

# Debugging the provider

To run this provider in delve run:
```shell
dlv exec --accept-multiclient --continue --headless ./terraform-provider-netbox -- -debug
```
For Visual Studio Code a config is provided in this repo. Pressing should run the provider in debug mode.

This will output a value for TF_REATTACH_PROVIDER:
```shell
Starting: /home/andy/go/bin/dlv dap --check-go-version=false --listen=127.0.0.1:43501 --log-dest=3 from /home/andy/terraform/terraform-provider-netbox
DAP server listening at: 127.0.0.1:43501
Type 'dlv help' for list of commands.
{"@level":"debug","@message":"plugin address","@timestamp":"2022-09-04T19:19:00.482554+02:00","address":"/tmp/plugin2734508527","network":"unix"}
Provider started. To attach Terraform CLI, set the TF_REATTACH_PROVIDERS environment variable with the following:

TF_REATTACH_PROVIDERS='{"registry.terraform.io/smutel/netbox":{"Protocol":"grpc","ProtocolVersion":5,"Pid":2519102,"Test":true,"Addr":{"Network":"unix","String":"/tmp/plugin2734508527"}}}'
```

In your terrafom directory run the following:
```shell
export TF_REATTACH_PROVIDER=(Value from above)
terraform plan
```

More information about debugging a terraform provider can be found in the terraform [documentation](https://www.terraform.io/plugin/debugging#starting-a-provider-in-debug-mode)

## Installing the provider

---
**NOTE**

Before changing the version of the provider, please remove the temporary folder `.terraform` and `~/.terraform.d`.

---

### Automatic installation from Terraform 0.13

```hcl
terraform {
required_providers {
netbox = {
source = "smutel/netbox"
version = "~> 6.0.0"
}
}
}
```

### Manual installation

You can install the provider manually in your global terraform provider folder.

```shell
export NETBOX_PROVIDER_VERSION=6.0.0
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/smutel/netbox/${NETBOX_PROVIDER_VERSION}/linux_amd64
cp terraform-provider-netbox_v${NETBOX_PROVIDER_VERSION} ~/.terraform.d/plugins/registry.terraform.io/smutel/netbox/${NETBOX_PROVIDER_VERSION}/linux_amd64/terraform-provider-netbox_v${NETBOX_PROVIDER_VERSION}
```

### Manual installation (to test the compiled version = version 0.0.1)

```shell
make localinstall
==> Creating folder ~/.terraform.d/plugins/registry.terraform.io/smutel/netbox/0.0.1/linux_amd64
==> Installing provider in this folder
```

## Using the provider

The definition of the provider is optional.
All the parameters could be setup by environment variables.

```hcl
provider netbox {
# Environment variable NETBOX_URL
url = "127.0.0.1:8000"

# Environment variable NETBOX_TOKEN
token = "0123456789abcdef0123456789abcdef01234567"

# Environment variable NETBOX_SCHEME
scheme = "http"

# Environment variable NETBOX_INSECURE
insecure = "true"
}
```

For further information, check this [documentation](https://registry.terraform.io/providers/smutel/netbox/latest/docs)

## Contributing to this project

To contribute to this project, please follow the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) rules.