Coder Social home page Coder Social logo

e-breuninger / terraform-provider-netbox Goto Github PK

View Code? Open in Web Editor NEW
164.0 12.0 115.0 1.72 MB

Terraform provider to interact with Netbox

Home Page: https://registry.terraform.io/providers/e-breuninger/netbox/latest/docs

License: Mozilla Public License 2.0

Makefile 0.15% Go 98.98% Shell 0.57% HCL 0.30%
netbox terraform terraform-provider

terraform-provider-netbox's Introduction

terraform-provider-netbox

The Terraform Netbox provider is a plugin for Terraform that allows for the full lifecycle management of Netbox resources. This provider is maintained by E. Breuninger.

See: Official documentation in the Terraform registry.

Requirements

Supported netbox versions

Netbox often makes breaking API changes even in non-major releases. Check the table below to see which version a provider was tested against. It is generally recommended to use the provider version matching your Netbox version. We aim to always support the latest minor version of Netbox.

Since version 1.6.6, each version of the provider has a built-in list of all Netbox versions it supports at release time. Upon initialization, the provider will probe your Netbox version and include a (non-blocking) warning if the used Netbox version is not supported.

Netbox version Provider version
v3.7.0 - 3.7.8 v3.8.0 and up
v3.6.0 - 3.6.9 v3.7.0 - 3.7.7
v3.5.1 - 3.5.9 v3.6.x
v3.4.3 - 3.4.10 v3.5.x
v3.3.0 - 3.4.2 v3.0.x - 3.5.1
v3.2.0 - 3.2.9 v2.0.x
v3.1.9 v1.6.0 - 1.6.7
v3.1.3 v1.1.x - 1.5.2
v3.0.9 v1.0.x
v2.11.12 v0.3.x
v2.10.10 v0.2.x
v2.9 v0.1.x

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the Go install command:
go install

Installation

Starting with Terraform 0.13, you can download the provider via the Terraform registry.

For further information on how to use third party providers, see the Terraform documentation

Releases for all major plattforms are available on the release page.

Using the provider

Here is a short example on how to use this provider:

provider "netbox" {
  server_url = "https://demo.netbox.dev"
  api_token  = "<your api token>"
}

resource "netbox_platform" "testplatform" {
  name = "my-test-platform"
}

For a more examples, see the provider documentation.

Developing the Provider

If you wish to work on the provider, you need Go installed on your machine (see Requirements above).

To compile the provider, run go install. This will build the provider and put the provider binary in the $GOPATH/bin directory.

To generate or update documentation, run make docs.

In order to run the suite of unit tests, run make test.

In order to run the full suite of acceptance tests, run make testacc.

In order to run a single specific acceptance test, run

TEST_FUNC=<test_name> make testacc-specific-test

For example:

TEST_FUNC=TestAccNetboxLocationDataSource_basic make testacc-specific-test

Note: Acceptance tests create a docker compose stack on port 8001.

make testacc

If you notice a failed test, it might be due to a stale netbox data volume. Before concluding there is a problem, refresh the docker containers by running docker-compose down --volumes in the docker directory. Then run the tests again.

If you get too many open files errors when running the acceptance test suite locally on Linux, your user limit for open file descriptors might be too low. You can increase that limit with ulimit -n 2048.

Contribution

We focus on virtual machine management and IPAM. If you want to contribute more resources to this provider, feel free to make a PR.

terraform-provider-netbox's People

Contributors

arjenvri avatar bebehei avatar dependabot-preview[bot] avatar dependabot[bot] avatar edwin-bruurs avatar fbreckle avatar flxpeters avatar gennadyspb avatar haipersuccor02 avatar hollow avatar holmesb avatar ikaremostest avatar ikke avatar jake2184 avatar joeyberkovitz avatar kyle-burnett avatar luispcoutinho avatar mifrost avatar ns1pelle avatar pezhore avatar robvand avatar rthomson avatar sanverik avatar sjurtf avatar t-tran avatar tagur87 avatar thibaultbustarret-ovhcloud avatar tstarck avatar twink0r avatar zeddd1abl0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-netbox's Issues

Verificiation of auto-generated documentation does not error on new files

We currently use the following procedure to check if the docs are up-to-date:

  • run go generate
  • if the docs are up-to-date, there should be no changes
  • if there are changes, the docs are not up-to-date

To check if there are changes, we use git diff --compact-summary --exit-code and then check its error code. This only catches changes in existing files, not new ones.

Expected Behavior

If a new documentation file should have been created, but was not, the doc verification fails.

Actual Behavior

If a new documentation file should have been created, but was not, the doc verification succeeds.

Steps to Reproduce

Add a new resource/data-source without adding documentation. The pipeline does not fail.

References

The git diff step https://github.com/e-breuninger/terraform-provider-netbox/runs/6622162657
Alternatively, run touch foo in a clean git repo and then run git diff --compact-summary --exit-code; echo $?. It will return 0.

Can't manage netbox_virtual_machine

Hey guys, any idea why this is happening?

Terraform Version

$ terraform version
Terraform v0.13.3

  • provider registry.terraform.io/e-breuninger/netbox v0.0.3
  • provider registry.terraform.io/terraform-provider-openstack/openstack v1.32.0

Affected Resource(s)

  • netbox_virtual_machine

Terraform Configuration Files

terraform {
  backend "http" {
  }
  required_providers {
    openstack = {
      source = "terraform-provider-openstack/openstack"
      required_version = ">= 0.13"
    }
    netbox = {
      source = "e-breuninger/netbox"
      required_version = ">= 0.13"
      version = "0.0.3"
    }
  }
}

provider "openstack" {
  user_name   = "***"
  tenant_name = "***"
  password    = "***"
  auth_url    = "***"
  region      = "***"
}

provider "netbox" {
  server_url = "***"
  api_token  = "***"
}

resource "netbox_virtual_machine" "testvm" {
  name         = "my-test-vm"
  comments     = "my-test-comment"
  memory_mb    = 1024
  vcpus        = 4
  disk_size_gb = 512
  cluster_id   = 4
  # tenant_id    = netbox_tenant.testtenant.id
  # platform_id  = netbox_platform.testplatform.id
  # role_id      = netbox_device_role.testdevicerole.id
}

Debug Output

https://gist.github.com/felipeneuwald/6374449273ce2b345f29da03254e405c

Panic Output

Expected Behavior

Apply the changes

Actual Behavior

Error

Steps to Reproduce

  1. terraform apply

Important Factoids

References

Server error (upgrade to netbox 3.1.3)

Hi,

I wanted to use new version of terraform provider plugin. I upgrade netbox to 3.1.3 but I have an issue on it:
Capture d’écran du 2022-03-16 09-06-04

I see on netbox that this issue is fix in the next version (3.1.4).

Is it possible to test and validate this plugin for a newer version of netbox ?

Thanks,
Thibaut

Fix failing acceptance tests

make testacc has the following failures:
1.
=== CONT TestAccNetboxAvailablePrefix_multiplePrefixesSerial resource_netbox_available_prefix_test.go:92: Step 1/2 error: Error running apply: exit status 1

    Error: unexpected success response: content available as default response in error (status 204): {"Payload":null}

      with netbox_available_prefix.test2,
      on terraform_plugin_test.tf line 19, in resource "netbox_available_prefix" "test2":
      19: resource "netbox_available_prefix" "test2" {`

=== CONT TestAccNetboxAvailableIPAddress_basic resource_netbox_available_ip_address_test.go:18: Step 1/1 error: Check failed: Check 1/3 error: netbox_available_ip_address.test: Attribute 'ip_address' expected "1.1.2.1/24", got "1.1.2.2/24"

=== CONT TestAccNetboxAvailableIPAddress_multipleIpsSerial resource_netbox_available_ip_address_test.go:85: Step 1/1 error: Check failed: Check 1/3 error: netbox_available_ip_address.test1: Attribute 'ip_address' expected "1.1.4.1/24", got "1.1.4.5/24"

=== RUN TestAccNetboxAvailablePrefix_basic resource_netbox_available_prefix_test.go:42: Step 1/2 error: Check failed: Check 1/5 error: netbox_available_prefix.test: Attribute 'prefix' expected "1.1.0.0/25", got "1.1.0.128/25"

=== CONT TestAccNetboxVirtualMachinesDataSource_basic data_source_netbox_virtual_machines_test.go:15: Step 4/5 error: Check failed: Check 1/3 error: data.netbox_virtual_machines.test: Attribute 'vms.#' expected "2", got "7"

=== CONT TestAccNetboxInterfacesDataSource_basic data_source_netbox_interfaces_test.go:16: Step 4/4 error: Check failed: Check 1/2 error: data.netbox_interfaces.test: Attribute 'interfaces.#' expected "1", got "3"

Tags not working when updating netbox-clusters

Terraform Version

terraform v0.14.9
provider v0.2.2
netbox v2.10.10

Affected Resource(s)

netbox-cluster

Terraform Configuration Files

provider "netbox" {
  server_url            = var.netbox_server
  api_token             = var.netbox_api_token
  allow_insecure_https  = true
}

resource "netbox_cluster" "cluster" {
    name = var.netbox_cluster.name
    cluster_type_id = var.netbox_cluster.cluster_type_id
    tags = [
      var.netbox_cluster.env,
      var.netbox_cluster.client
    ]
}

variable "netbox_cluster" {
  type = object({
    name = string
    cluster_type_id = number
    env = string
    client = string
  })
}
netbox_cluster = {
    name = "test"
    cluster_type_id = 2
    env = "test"
    client = "infra"
}

Expected Behavior

Terraform should update the cluster test and add the Tags "test" and "infra"

Actual Behavior

Terraform states the following error:
Error: [PATCH /virtualization/clusters/{id}/][400] virtualization_clusters_partial_update default map[tags:[This field may not be null.]]
on main.tf line 72, in resource "netbox_cluster" "cluster":
72: resource "netbox_cluster" "cluster" {

Steps to Reproduce

  1. terraform apply

Root Cause

Tags are not set inside the update function of the Cluster-Resource.
(terraform-provider-netbox/netbox/resource_netbox_cluster.go: func resourceNetboxClusterUpdate)

Recommended Bugfig

add "tags, _ := getNestedTagListFromResourceDataSet(api, d.Get("tags"))
data.Tags = tags"
to terraform-provider-netbox/netbox/resource_netbox_cluster.go inside the function resourceNetboxClusterUpdate.

Update API Version to support Netbox 3.2.x

I stumbled across this project in mid-April and was hoping to implement it, however my existing Netbox deploy was already on 3.2.0 by that time. It seems there are number of significant (breaking) API changes (including a date format change and removing some deprecated fields), so updating would require more than a migration to a more current go-netbox release.

registry.terraform.io/e-breuninger/netbox 0.2.2 is not available for darwin_arm64

Hi,

I noticed that there is no darwin_arm64 build available for this provider. Is there a technical reason for that?

Would be great to have this.

Error: Could not retrieve providers for locking
Terraform failed to fetch the requested providers for darwin_arm64 in order to calculate their checksums: some providers could not be installed:

  • registry.terraform.io/e-breuninger/netbox: provider registry.terraform.io/e-breuninger/netbox 0.2.2 is not available for darwin_arm64.

Create new tenant

Hi all,

thanks for this tool.
Is it possible to create a new tenant with you tool?
I can not find a way to create new tenant with your netboxprovider.
May you support a possibility to create new tenants?

Cheers

Reduce API Calls for VLAN/Prefix

Thank you for supplying this nice provider.
While creating many prefixes we noticed the time it takes to create resources is increased by unneeded API calls.

Would it be possible to consider removing the unneeded update call for VLAN/Prefixes?

below a PR for your review
#150

Add more configuration exampels

Hi there,
Terraform Version: v0.14.5

Affected Resources:
netbox_ip_address
netbox_virtual_machine

Hi, I'm currently trying to use this terraform provider to also add the VM's im adding to my netbox installation. I want to use netbox later as a ansible inventory, so I need to add the ipv4 address to the VM. Unfortunately, I'm wasn't able to do so.
Here are 2 versions I tried:

resource "netbox_ip_address" "ipOfTestvm" {
    ip_address = "10.20.20.20/24"
    status = "active"
    assigned_object_type = "virtual_machine"
    assigned_object_id = 2
}

resource "netbox_virtual_machine" "testvm" {
    name = "testvm"
    cluster_id = 1
}

and

resource "netbox_virtual_machine" "testvm" {
    name = "testvm"
    cluster_id = 1
    primary_ipv4 = 1

I also tried to write the primary_ipv4 directly as a string.

None of these solutions worked. I'm out of ideas. The rest of the working solution (everything else worked), I reverse engineered with the swagger api documentation of netbox and the error messages from the provider itself.

I think it would be a good idea to add some more documentation in regards of using this provider with specific use case examples?

netbox_primary_ip not working

Hello.
Function for assigning primary ip to a vm is'nt working.

Error:

Error: json: cannot unmarshal string into Go struct field VirtualMachineWithConfigContext.local_context_data of type map[string]interface {}

  on .terraform/modules/vm.netbox-ip/netbox.tf line 21, in resource "netbox_primary_ip" "vm-primary-ip":
  21: resource "netbox_primary_ip" "vm-primary-ip" {

Terraform version: 0.13.6 (also tryed 0.14.8, result is the same)
Resource definition:

resource "netbox_primary_ip" "vm-primary-ip" {
  ip_address_id = netbox_available_ip_address.vm_ip.id
  virtual_machine_id = var.vm_id
}

Implement Tenant Groups

In order to group tenants we need to implement the Tenant Group resource.

The Tenant resource already exists ans needs an extension to assign it to a Tenant Group.

plugin crashes on netbox_available_ip_address if prefix is full

Getting an netbox_available_ip_address from a prefix that is 100% utilized results in a panic instead of a graceful error message.

Netbox Version

Tested with both 3.1.0 (unsupported, I know) and 3.0.9 to make sure it's not an API thing. Happens with both.

Terraform Version

1.1.2

Affected Resource(s)

  • netbox_available_ip_address

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

terraform {
  required_version = ">= 1.0.0"

  required_providers {
    netbox = {
      source  = "e-breuninger/netbox"
      version = "1.0.2"
    }
  }
}

provider "netbox" {
  server_url           = "https://IP:PORT"
  api_token            = "TOKEN"
  allow_insecure_https = true
}

data "netbox_prefix" "this" {
  cidr = "10.0.0.0/24"
}

resource "netbox_available_ip_address" "this" {
  prefix_id = data.netbox_prefix.this.id
  status    = "active"
  dns_name  = "test.example.com"
}

output "ip_address" {
  value = resource.netbox_available_ip_address.this.ip_address
}

Panic Output

Stack trace from the terraform-provider-netbox_v1.0.2 plugin:

panic: runtime error: index out of range [0] with length 0

goroutine 45 [running]:
github.com/e-breuninger/terraform-provider-netbox/netbox.resourceNetboxAvailableIPAddressCreate(0x0, {0x11f49a0, 0xc00013a630})
  github.com/e-breuninger/terraform-provider-netbox/netbox/resource_netbox_available_ip_address.go:87 +0x485
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x12164c0, {0x15e7598, 0xc00004eac0}, 0x2, {0x11f49a0, 0xc00013a630})
  github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:329 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0005f4000, {0x15e7598, 0xc00004eac0}, 0xc0002d85b0, 0xc00039c080, {0x11f49a0, 0xc00013a630})
  github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:467 +0x871
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00000c0c0, {0x15e7598, 0xc00004eac0}, 0xc0002e4aa0)
  github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:977 +0xd8a
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00057a900, {0x15e7640, 0xc000104300}, 0xc0001ee000)
  github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:603 +0x30e
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x13b3120, 0xc00057a900}, {0x15e7640, 0xc000104300}, 0xc0002a2960, 0x0)
  github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000523340, {0x15f6ad0, 0xc00019cc00}, 0xc000188000, 0xc000320f00, 0x2142f00, 0x0)
  google.golang.org/[email protected]/server.go:1194 +0xc8f
google.golang.org/grpc.(*Server).handleStream(0xc000523340, {0x15f6ad0, 0xc00019cc00}, 0xc000188000, 0x0)
  google.golang.org/[email protected]/server.go:1517 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
  google.golang.org/[email protected]/server.go:859 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
  google.golang.org/[email protected]/server.go:857 +0x294

Error: The terraform-provider-netbox_v1.0.2 plugin crashed!

Expected Behavior

The provider should throw a human readable/understandable error message and not crash if prefix is full

Actual Behavior

The provider throws an error about index out if range and panics

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Netbox 3 support

We're using netbox 3, and while the current provider version seems to work fine for what we want to use (mostly ipam prefixes), it would be nice to have proper support. The go-netbox api library has released a 3.0 version, however I noticed that you maintain your own fork. Any chance that it will get the upstream updates?

provider crash (SIGSEGV) when netbox API connection is not available

Terraform Version

Terraform v1.1.2

Debug Output

Stack trace from the terraform-provider-netbox_v1.1.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x109c2af]

Panic Output

https://gist.github.com/cova-fe/5530a6406fb6e977e42f908ed8bf295a

Expected Behavior

Provider contacting netbox with no errors

Actual Behavior

A SIGSEGV error when the API are not responding.

Steps to Reproduce

Set the provider configuration to something that does not work (i.e. https://localhost:8080) and run tf plan.

Any reason there isn't a Device resource?

Hey all,

General question: is there any specific reason why there is a Virtual Machine resource but not a Device resource? I've noticed that the various Netbox providers all seem to forego it. I'd like to implement and PR but want to make sure it's not against philosophy or something.

Thanks

Update API Version to supported Netbox Version (3.1.3)

Hello,

for my purposes I wanted to work with ASNs in this provider but I noticed them not being present. During investigation I noticed that referenced go-netbox library (https://github.com/fbreckle/go-netbox) is generated for an ealier version (3.0) which does not include the API entpoints I need.

In my opinion it is reasonable to use the API version of Netbox that is "officially" supported by the current provider release.

I create a PR in the go-netbox repo with the updated files: fbreckle/go-netbox#9

Please let me know if I can contribute any further work to get the current API version to work.

Error parsing time (extra text) when creating resources

More of a FYI.

I'm hitting an issue with the latest release of NetBox. I know I'm getting ahead of myself, so no action needed. Just sharing in case someone else runs into this. The provider creates the resources, however Terraform returns an error complaining about not being able to parse the time like in this issue on StackOverflow.

EDIT: I added a link to the NetBox breaking change in references that I believe is the culprit of this (issue netbox-community/netbox#8463).

Terraform Version

$ terraform version
Terraform v1.1.7
on linux_amd64
+ provider registry.terraform.io/e-breuninger/netbox v1.5.2

Affected Resource(s)

This affected all the resources tested:

  • netbox_platform
  • netbox_device_role
  • ...

Terraform Configuration Files

terraform {
  required_providers {
    netbox = {
      source = "e-breuninger/netbox"
    }
  }
}

provider "netbox" {
  server_url = "https://demo.netbox.dev"
  api_token = "0123456789abcdef0123456789abcdef01234567"
}

Debug Output

Panic Output

Expected Behavior

What should have happened?
Apply and create the resources

Actual Behavior

What actually happened?
It does create the resources, but Terraform errors out, so it does not save the state.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

Resource:

resource "netbox_device_role" "container" {
  name      = "Container Router"
  vm_role   = true
  slug      = "container"
  color_hex = "ff0000"
}

Terraform apply:

$ terraform apply -auto-approve

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # netbox_device_role.container will be created
  + resource "netbox_device_role" "container" {
      + color_hex = "ff0000"
      + id        = (known after apply)
      + name      = "Container Router"
      + slug      = "container"
      + vm_role   = true
    }

Plan: 1 to add, 0 to change, 0 to destroy.
netbox_device_role.container: Creating...
╷
│ Warning: Possibly unsupported Netbox version
│ 
│   with provider["registry.terraform.io/e-breuninger/netbox"],
│   on main.tf line 9, in provider "netbox":
│    9: provider "netbox" {
│ 
│ This provider was tested against Netbox v3.1.3. Your Netbox version is v3.2.0. Unexpected errors may occur.
│ 
│ (and one more similar warning elsewhere)
╵
╷
│ Error: parsing time "2022-04-06T17:57:25.048803Z": extra text: "T17:57:25.048803Z"
│ 
│   with netbox_device_role.container,
│   on main.tf line 29, in resource "netbox_device_role" "container":
│   29: resource "netbox_device_role" "container" {
│ 
╵

Important Factoids

I'm running against a non-tested Netbox version (v3.2.0).

References

v3.2.0 Breaking Changes

The created field of all change-logged models now conveys a full datetime object, rather than only a date. (Previous date-only values will receive a timestamp of 00:00.) While this change is largely unconcerning, strictly-typed API consumers may need to be updated.

Add prefixes data source

Thank you for building this useful terraform provider!

Would it be possible to support a prefixes data source that allows for retrieving prefixes based on prefix status, role, vid, vrf and family?

thank you

netbox_available_ip_addresses are dynamic

Hi,

If you create a list of netbox_available_ip_address resources, then delete one that is not at the end of the list, all those after it receive new addresses. This is undesirable bc these are usually server IPs which should remain static:

resource "netbox_available_ip_address" "mains" {
  count = length(var.vms)
  prefix_id = var.a_subnet_id
  status = "active"
}

Where var.vms is:

  vms = ["server1", "server2", "server3"]

Delete server2 from the list and server3's IP is changed. Might be a tough problem to solve, but could the VM-to-IP assignment be obtained from state and somehow made static? I won't have time to fix this, but putting it out there in case someone wants to take it on.

Check if Netbox and provider version are compatible at start up

Netbox had several breaking API changes from 2.8 to 2.9. This leads to errors when using a version of this provider with a incompatible Netbox version. The provider should check if the version of the provider is compatible with the target Netbox version.

In order to do that we need a way to evaluate the Netbox version via API and check it on start up.

  • If the version matches a supported version, everything is fine - continue.
  • For incompatible versions it should exit with an error.
  • For unknown compatibility (new, not checked versions) it should log a warning.

This should help to avoid issues like #4 and give users a friendly message if the versions doesn't match.

Discussion: How to handle the breaking API changes

It's fairly clear that Netbox's API changes will continue to introduce breaking changes, and in light of issues #12 and #51 (and addressing the challenges of testing multiple Netbox versions for the provider, I'd like to start a discussion about how we could approach this task.

Option 1: Implicit Versioning

We could opt to have some linking/reference to the Netbox version in the provider version tag. It looks like for #51, breaking changes were introduced in v2.11 of Netbox, so perhaps the provider should have some indication that it's for version 2.10.x?

If we add in new features, the provider could be updated using multiple versions of the backing Netbox go library and new versions of the 2.10.x/2.11.x provider could be cut.

Downside: this is a lot more work on the provider management side - regression testing, feature parity checks (what if something is added in 2.11.x which isn't included in 2.10, how do we handle our documentation to state in which version a particular resource/data_source is supported? It would also be imperative to limit how many concurrent versions of Netbox the provider supports - perhaps just the latest two minor versions (currently 2.10.x and 2.11.x).

Option 2: Provider Compatibility Validation

We could put a check in the provider init that queries the target Netbox server's API briefly covered here.

This would also require some overhead on the provider management side - but not as much as maintaining multiple versions of the provider. Documentation could be updated to indicate the compatible versions for the current provider, and link to the last known good version that supports the previous Netbox version.

Downside: We would have to cut off support for prior versions and if there is a community need for a feature to be added to a prior version of Netbox, it would be difficult to implement without messing with versions (as in Option 1).

Implement Cluster Groups

In order to group clusters we need to implement the cluster group resource.

The Cluster resource already exists and must be extended so one can assign a Cluster to a Cluster Group.

Bring go-netbox into this repo

Hi,

A suggestion: to avoid having to switch go-netbox client en-masse during PRs when changes to it are needed, might be worth considering moving the client into this repo. Eg in PR #106, I have switched to using my forked go-client so the PR can be tested. Would be obviated and the client & terraform provider kept in-sync if go-netbox was moved here. Easier PR process. fbreckle/go-netbox serves this provider exclusively and is not general purpose.

Cheers

Feature request/call out: Config Context

Hello,

Feature request/call out: Config Context

We do have a need to modifying config context, ( mostly setting what tag's they should belong to )

So before we start looking into developing that feature just wanted to check so there is no one else doing that we then rather can help rather then we do it all by our self.

Br
Christoffer

Error on Update of `netbox_circuit` resource

Terraform Version

Terraform v1.1.6
on linux_amd64

Affected Resource(s)

  • netbox_circuit

Terraform Configuration Files

First Run

resource "netbox_circuit" "circuit2" {
  cid         = "Test Circuit"
  status      = "active"
  tenant_id   = 2
  provider_id = 3
  type_id     = 6
}

Second Run

resource "netbox_circuit" "circuit2" {
  cid         = "Test Circuit2"
  status      = "active"
  tenant_id   = 2
  provider_id = 3
  type_id     = 6
}

Debug Output

Error: [PATCH /circuits/circuits/{id}/][400] circuits_circuits_partial_update default  map[tags:[This field may not be null.]]

with netbox_circuit.circuit2,
on main.tf line 20, in resource "netbox_circuit" "circuit2":
 20: resource "netbox_circuit" "circuit2" {

Expected Behavior

Resource should update without error.

Actual Behavior

Any update causes an HTTP 400 error because the tags field is null in the json response.

Steps to Reproduce

  1. terraform apply
  2. Update the cid field
  3. terraform apply

References

Seems the update function is missing this line to initialize the Tags field with an empty list of tags.
https://github.com/e-breuninger/terraform-provider-netbox/blob/master/netbox/resource_netbox_circuit.go#L74

Provider Crash

Terraform Version

1.2.0

Netbox Version

v3.0.10

Provider version

v1.0.2

Affected Resource(s)

Provider Crash

Terraform Configuration Files

data "netbox_prefix"
resource "netbox_available_ip_address"

Panic Output

Error: Plugin did not respond

│ with provider["registry.terraform.io/e-breuninger/netbox"],
│ on provider-backend.tf line 116, in provider "netbox":
│ 116: provider "netbox" {

│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ConfigureProvider call. The plugin logs may contain
│ more details.

Stack trace from the terraform-provider-netbox_v1.0.2 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x109c2af]
goroutine 23 [running]:
github.com/fbreckle/go-netbox/netbox/client/status.(*StatusListOK).GetPayload(...)
github.com/fbreckle/[email protected]/netbox/client/status/status_list_responses.go:74
github.com/e-breuninger/terraform-provider-netbox/netbox.providerConfigure({0x143d5d7, 0x6}, 0xc0002c7590)
github.com/e-breuninger/terraform-provider-netbox/netbox/provider.go:95 +0x22f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Provider).Configure(0xc0003d0420, {0x15e7640, 0xc0002c7590}, 0xc0001e50c0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/provider.go:296 +0x23e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ConfigureProvider(0xc00000c0c0, {0x15e7598, 0xc0002c2440}, 0xc00012c8b8)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:523 +0x27b
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).Configure(0xc00039ed80, {0x15e7640, 0xc000331500}, 0xc0002c2280)
github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:387 +0x2c2
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_Configure_Handler({0x13b3120, 0xc00039ed80}, {0x15e7640, 0xc000331500}, 0xc00057c240, 0x0)
github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:326 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000589180, {0x15f6ad0, 0xc0001af680}, 0xc0000b8100, 0xc0001ec930, 0x2142eb8, 0x0)
google.golang.org/[email protected]/server.go:1194 +0xc8f
google.golang.org/grpc.(*Server).handleStream(0xc000589180, {0x15f6ad0, 0xc0001af680}, 0xc0000b8100, 0x0)
google.golang.org/[email protected]/server.go:1517 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
google.golang.org/[email protected]/server.go:859 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/[email protected]/server.go:857 +0x294
Error: The terraform-provider-netbox_v1.0.2 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: exit code 1

Error: json: cannot unmarshal string into Go struct field VirtualMachineWithConfigContext.vcpus of type int64

Create recource netbox_virtual_machine with vcpu error

Terraform Version

$> terraform -v
Terraform v0.15.3
on linux_amd64
+ provider registry.terraform.io/e-breuninger/netbox v0.1.3

NetBox Version

2.11

Affected Resource(s)

  • netbox_virtual_machine

Terraform Configuration Files

$> cat netbox.tf 
terraform {
    required_providers {
        netbox = {
            source  = "e-breuninger/netbox"
            version = "0.1.3"
        }
    }
    required_version = ">= 0.13"
}

variable "netbox_api_token" {
    type = string
}

provider "netbox" {
    server_url           = "https://netbox.srv.local"
    api_token            = var.netbox_api_token
    allow_insecure_https = false
}

data "netbox_cluster" "cluster" {
    name = "MDC Production OpenStack"
}

resource "netbox_virtual_machine" "create_vm" {
    name         = "test-vm"
    cluster_id   = data.netbox_cluster.cluster.id
    vcpus        = 4
}

Steps to Reproduce

$> terraform apply -var netbox_api_token=${NETBOX_TOKEN}

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # netbox_virtual_machine.create_vm will be created
  + resource "netbox_virtual_machine" "create_vm" {
      + cluster_id   = 4
      + id           = (known after apply)
      + name         = "test-vm"
      + primary_ipv4 = (known after apply)
      + vcpus        = 4
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

netbox_virtual_machine.create_vm: Creating...
╷
│ Error: json: cannot unmarshal string into Go struct field VirtualMachineWithConfigContext.vcpus of type int64
│ 
│   with netbox_virtual_machine.create_vm,
│   on netbox.tf line 25, in resource "netbox_virtual_machine" "create_vm":
│   25: resource "netbox_virtual_machine" "create_vm" {
│ 
╵

Data source zero results

Hi,

I'm looking to add a flag to data sources to not throw an error with zero results - my use case being I'm doing for_each with the result of a number of netbox searches, and simply want to return an empty set on empty searches rather than throw an error.

I'm happy to add this to all datasources.

Do you have preference on name or implementation? Currently thinking something like error_on_no_result and default it to true, and wrap the error raising in a conditional.

Implement Sites

In order to manage Sites we need to implement Sites as a new resource.

Sites can be assigned to the following currently supported resources:

  • Virtual Machines
  • Cluster (#10)

There should be a method to assign Sites with this resources.

netbox_ip_address has no description field

I think this classifies as a feature request, but netbox_available_ip allows you to add a description to the requested IPs while netbox_ip_address does not. This would be a very helpful feature to have, I intended on using it when using netbox_available_ip but am no longer calling it.

Mistake in the Plugin Documentation?

Hey,

I think I just noticed, a mistake in the plugin documentation. On the first example

resource "netbox_cluster" "testcluster" { name = "my-test-cluster" cluster_group_id = netbox_cluster_type.testclustertype.id }

the variable name "cluster_group_id "should be replaced by "cluster_type_id" as we definde the type and not the group here.
Otherwise the Terraform execution will run into an error.

resource netbox_ip_address fails to apply tags

Hi there,

using tags with the netbox_ip_address fails with 400

Terraform Version

Terraform v0.13.3

  • provider registry.terraform.io/e-breuninger/netbox v0.0.3

Affected Resource(s)

Please list the resources as a list, for example:

  • netbox_ip_address

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

terraform {
  required_providers {
    netbox = {
      source = "e-breuninger/netbox"
      version = ">=0.0.3"
    }
  }
}

provider "netbox" {
    server_url           = "http://localhost:8000"
    api_token            = "<TOKENREMOVED>"
    allow_insecure_https = true
}
resource "netbox_ip_address" "testip" {
  ip_address   = "1.2.3.4/32"
  status       = "active"
  tags  = ["testingterraform"]
}

Debug Output

https://gist.github.com/chrisbnorman/af384cde634b157748c038c9bcb2dd34

Panic Output

none

Expected Behavior

modify tag

Actual Behavior

fails with 400

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

without using tags it creates/modifies/deletes without issue

Duplicate IPs when creating multiple netbox_available_ip_address resources

Terraform Version

terraform v0.13.2
provider v0.2.0
netbox: v2.11.7

Affected Resource(s)

netbox_available_ip

Terraform Configuration Files

provider "netbox" {
  server_url           = "https://netbox.domain.com"
  api_token            = var.netbox_api_token
  allow_insecure_https = false
}
resource "netbox_prefix" "main" {
  prefix = "10.0.0.0/24"
  status = "active"
  description = "main"
}
resource "netbox_cluster_type" "main" {
  name = "main"
}
resource "netbox_cluster" "main" {
  cluster_type_id = netbox_cluster_type.main.id
  name = "main"
}
resource "netbox_virtual_machine" "main" {
  cluster_id = netbox_cluster.main.id
  name = "main"
}
resource "netbox_interface" "main" {
  name = "main"
  virtual_machine_id = netbox_virtual_machine.main.id
}
resource "netbox_available_ip_address" "main1" {
  prefix_id = netbox_prefix.main.id
  status = "active"
  interface_id = netbox_interface.main.id
}
resource "netbox_available_ip_address" "main2" {
  prefix_id = netbox_prefix.main.id
  status = "active"
  interface_id = netbox_interface.main.id
}

Expected Behavior

Two distinct IP addresses created. 10.0.0.1/24 & 10.0.0.2/24

Actual Behavior

2 x 10.0.0.1/24

Important Factoids

If I delete netbox_available_ip_address.main2 (comment it out and apply), then recreate it, it will correctly create a fresh IP: 10.0.0.2/24. So I suspect a race-condition when multiple are created in the same execution.

Might be of interest to @pezhore

netbox_ip_address ID field appears non-functional

Terraform Version:

Terraform v1.1.3
on darwin_amd64

  • provider registry.terraform.io/e-breuninger/netbox v1.1.0
  • provider registry.terraform.io/telmate/proxmox v2.9.4

Netbox Version: 3.1.3

Affected Resource

netbox_ip_address

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

Would expect netbox provider to be able to retrieve the next available IP, set it to reserved and store the ID using the netbox_available_ip_address resource, then in a subsequent resource call using netbox_ip_address set the IP to 'active' and assign it to the new VM/Container interface entry based on the ID from the previous step.

Actual Behavior

netbox terraform provider resource netbox_ip_address appears to ignore the id field.

This issue occours when trying to use the netbox_ip_address resource to modify an IP address already touched using the netbox_available_ip_address.

When not using the ID field, the netbox provider reports that it is a duplicate IP.
When using the ID field, terraform reports the following error:

terraform apply

 Error: Invalid or unknown key

   with netbox_ip_address.update_ip,
   on main.tf line 67, in resource "netbox_ip_address" "update_ip":
   67:     id                = "${resource.netbox_available_ip_address.reserve_ip.id}"

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

Sample .tf file content:

resource "netbox_available_ip_address" "reserve_ip" {
    prefix_id         = data.netbox_prefix.find_ip.id
    tenant_id         = data.netbox_tenant.customer-a.id
    vrf_id            = data.netbox_vrf.cust-a-vrf.id
    status            = "reserved"
    dns_name          = var.dns_entry
}

output "avail_ip" {
  value               = resource.netbox_available_ip_address.reserve_ip
  sensitive           = false
}

resource "proxmox_lxc" "basic" {
  target_node         = "pve"
  hostname            = var.dns_entry
  ostemplate          = "storage:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz"
  password            = "BasicLXCContainer"
  unprivileged        = true
  ostype              = "ubuntu"
  cores               = 2
  memory              = "2048"
  rootfs {
    storage           = "pool1"
    size              = "8G"
  }
  network {
    name              = "eth0"
    bridge            = "vmbr0"
    ip                = resource.netbox_available_ip_address.reserve_ip.ip_address
    ip6               = "dhcp"
  }
  ssh_public_keys     = <<-EOT
    [email protected]
  EOT
}

resource "netbox_virtual_machine" "create_vm" {
    cluster_id        = data.netbox_cluster.vmw-cluster-01.id
    name              = resource.proxmox_lxc.basic.hostname
    disk_size_gb      = 8 
    memory_mb         = proxmox_lxc.basic.memory
    vcpus             = proxmox_lxc.basic.cores
    role_id           = 13
    tenant_id         = data.netbox_tenant.customer-a.id

resource "netbox_interface" "create_if" {
  name                = resource.proxmox_lxc.basic.network[0].name
  mac_address         = resource.proxmox_lxc.basic.network[0].hwaddr
  virtual_machine_id  = resource.netbox_virtual_machine.create_vm.id
}

resource "netbox_ip_address" "update_ip" {
    ip_address        = resource.netbox_available_ip_address.reserve_ip.ip_address
    id                = resource.netbox_available_ip_address.reserve_ip.id
    tenant_id         = resource.netbox_available_ip_address.reserve_ip.tenant_id
    vrf_id            = resource.netbox_available_ip_address.reserve_ip.vrf_id
    interface_id      = resource.netbox_interface.create_if.id
    dns_name          = var.dns_entry
    status            = "active"
}

Important Factoids

API token has full access to netbox instance

I'm relatively new to Terraform so I expect I'm not using the 'correct' method to accomplishing this.

is_pool issue with netbox_available_prefix

Terraform Version

Terraform v1.1.2

Affected Resource(s)

  • netbox_available_prefix

Expected Behavior

the state of is_pool should be changed from true->false

Actual Behavior

The is_pool is not changed

Steps to Reproduce

Run terraform in order to request a new prefix, with is_pool set to true. Subsequently change the tf file to "is_bool: false". tf plan shows that the resource should be updated (true->false) as expected. run tf apply, the output shows that netbox is indeed called against the affected resources. However, the flag is not updated.

Important Factoids

I sniffed the API calls and while the provider indeed contacts the API, the json in the PUT call does not contains "is_pool" flag, that looks suspicious. (attaching the wireshark output as screenshot, as the text output from tcpdump is a bit complicated to format)
image

  • Please note that I'm using netbox 3.1.5, not 3.1.3 even though this should have no impact on this behavior, AFAIK.

Feature request: Add devices as a resource

Hello,

i was wondering if you plan to add devices to the configurable resources so they could be changed with terraform.
Or is that not within the scope of the project?

Greetings
Flori

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.