Skip to content

Commit

Permalink
Merge pull request #92 from e-breuninger/feature/netbox-3.0.9
Browse files Browse the repository at this point in the history
Support netbox 3.0.9
  • Loading branch information
fbreckle authored Nov 8, 2021
2 parents cafe858 + eaab07a commit 80857ec
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 23 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 1.0.0 (Nov 8, 2021)

FEATURES

* provider: Now supports NetBox v3.0.9

BREAKING CHANGES

* resource/virtual_machine: `vcpus` is now a float to match upstream API

## 0.3.2 (Nov 2, 2021)

ENHANCEMENTS
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default: testacc
# Run acceptance tests
.PHONY: testacc
testacc:
@NETBOX_VERSION=v2.11.12 sh -c "'$(CURDIR)/docker/start.sh' $(NETBOX_SERVER_URL)"
@NETBOX_VERSION=v3.0.9 sh -c "'$(CURDIR)/docker/start.sh' $(NETBOX_SERVER_URL)"
TF_ACC=1 NETBOX_SERVER_URL=$(NETBOX_SERVER_URL) NETBOX_API_TOKEN=0123456789abcdef0123456789abcdef01234567 go test -v -cover $(TEST)

.PHONY: test
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Netbox often makes API-breaking changes even in non-major releases. We aim to al

Provider version | Netbox version
--- | ---
v1.0.x | v3.0.9
v0.3.x | v2.11.12
v0.2.x | v2.10.10
v0.1.x | v2.9
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/davecgh/go-spew v1.1.1
github.com/fbreckle/go-netbox v0.0.0-20211019120953-a22717727647
github.com/fbreckle/go-netbox v0.0.0-20211108152602-6c9cea679011
github.com/go-openapi/runtime v0.19.32-0.20210924162202-f7fb72beda3a
github.com/goware/urlx v0.3.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fbreckle/go-netbox v0.0.0-20211019120953-a22717727647 h1:kpryjXA8l3bEfAtnUls0zj+CADWlxXw/FVv+BIqHLLw=
github.com/fbreckle/go-netbox v0.0.0-20211019120953-a22717727647/go.mod h1:Nf2bxylehF4ROF+s2paaRCKLIeYcUb2+NK1R/nOsE0o=
github.com/fbreckle/go-netbox v0.0.0-20211108152602-6c9cea679011 h1:zLAI0IiM54qujyB4MJd4o1nz5dID+AqQCLu/Zmn93W0=
github.com/fbreckle/go-netbox v0.0.0-20211108152602-6c9cea679011/go.mod h1:Nf2bxylehF4ROF+s2paaRCKLIeYcUb2+NK1R/nOsE0o=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
Expand Down
2 changes: 1 addition & 1 deletion netbox/data_source_netbox_virtual_machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func dataSourceNetboxVirtualMachine() *schema.Resource {
Computed: true,
},
"vcpus": {
Type: schema.TypeString,
Type: schema.TypeFloat,
Computed: true,
},
"vm_id": {
Expand Down
2 changes: 1 addition & 1 deletion netbox/data_source_netbox_virtual_machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccNetboxVirtualMachinesDataSource_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.netbox_virtual_machines.test", "vms.#", "1"),
resource.TestCheckResourceAttr("data.netbox_virtual_machines.test", "vms.0.name", testName+"_0"),
resource.TestCheckResourceAttr("data.netbox_virtual_machines.test", "vms.0.vcpus", "4.00"),
resource.TestCheckResourceAttr("data.netbox_virtual_machines.test", "vms.0.vcpus", "4"),
resource.TestCheckResourceAttr("data.netbox_virtual_machines.test", "vms.0.memory_mb", "1024"),
resource.TestCheckResourceAttr("data.netbox_virtual_machines.test", "vms.0.disk_size_gb", "256"),
resource.TestCheckResourceAttr("data.netbox_virtual_machines.test", "vms.0.comments", "thisisacomment"),
Expand Down
2 changes: 1 addition & 1 deletion netbox/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func providerConfigure(ctx context.Context, data *schema.ResourceData) (interfac
res, _ := netboxClient.(*client.NetBoxAPI).Status.StatusList(req, nil)
netboxVersion := res.GetPayload().(map[string]interface{})["netbox-version"]

supportedVersion := "2.11.12"
supportedVersion := "3.0.9"

if netboxVersion != supportedVersion {

Expand Down
17 changes: 5 additions & 12 deletions netbox/resource_netbox_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func resourceNetboxVirtualMachine() *schema.Resource {
Optional: true,
},
"vcpus": &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeFloat,
Optional: true,
},
"disk_size_gb": &schema.Schema{
Expand Down Expand Up @@ -94,7 +94,7 @@ func resourceNetboxVirtualMachineCreate(ctx context.Context, d *schema.ResourceD

vcpusValue, ok := d.GetOk("vcpus")
if ok {
vcpus := vcpusValue.(string)
vcpus := vcpusValue.(float64)
data.Vcpus = &vcpus
}

Expand Down Expand Up @@ -198,16 +198,9 @@ func resourceNetboxVirtualMachineRead(ctx context.Context, d *schema.ResourceDat
d.Set("comments", res.GetPayload().Comments)
vcpus := res.GetPayload().Vcpus
if vcpus != nil {
// vcpus comes as string with double digit precision
// for usability, we trim the .00 part if its a .00 value
// this way, we do not get configuration drift if e.g. vcpus = "4" is set
if (*vcpus)[len(*vcpus)-3:] == ".00" {
d.Set("vcpus", (*vcpus)[0:len(*vcpus)-3])
} else {
d.Set("vcpus", res.GetPayload().Vcpus)
}
} else {
d.Set("vcpus", res.GetPayload().Vcpus)
} else {
d.Set("vcpus", nil)
}
d.Set("memory_mb", res.GetPayload().Memory)
d.Set("disk_size_gb", res.GetPayload().Disk)
Expand Down Expand Up @@ -253,7 +246,7 @@ func resourceNetboxVirtualMachineUpdate(ctx context.Context, d *schema.ResourceD

vcpusValue, ok := d.GetOk("vcpus")
if ok {
vcpus := vcpusValue.(string)
vcpus := vcpusValue.(float64)
data.Vcpus = &vcpus
}

Expand Down
12 changes: 6 additions & 6 deletions netbox/resource_netbox_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ resource "netbox_virtual_machine" "test" {
tenant_id = netbox_tenant.test.id
role_id = netbox_device_role.test.id
platform_id = netbox_platform.test.id
vcpus = "4"
vcpus = 4
tags = ["%[1]sa"]
}`, testName),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -113,7 +113,7 @@ resource "netbox_virtual_machine" "test" {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "name", testName),
resource.TestCheckResourceAttrPair("netbox_virtual_machine.test", "cluster_id", "netbox_cluster.test", "id"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "vcpus", ""),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "vcpus", "0"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "memory_mb", "0"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "disk_size_gb", "0"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "comments", ""),
Expand Down Expand Up @@ -142,25 +142,25 @@ func TestAccNetboxVirtualMachine_fractionalVcpu(t *testing.T) {
resource "netbox_virtual_machine" "test" {
name = "%s"
cluster_id = netbox_cluster.test.id
vcpus = "2.50"
vcpus = 2.50
}`, testName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "name", testName),
resource.TestCheckResourceAttrPair("netbox_virtual_machine.test", "cluster_id", "netbox_cluster.test", "id"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "vcpus", "2.50"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "vcpus", "2.5"),
),
},
{
Config: testAccNetboxVirtualMachineFullDependencies(testName) + fmt.Sprintf(`
resource "netbox_virtual_machine" "test" {
name = "%s"
cluster_id = netbox_cluster.test.id
vcpus = "4"
vcpus = 4
}`, testName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "name", testName),
resource.TestCheckResourceAttrPair("netbox_virtual_machine.test", "cluster_id", "netbox_cluster.test", "id"),
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "vcpus", "4"), // netbox will return "4.00", but we parse it to improve usability
resource.TestCheckResourceAttr("netbox_virtual_machine.test", "vcpus", "4"),
),
},
{
Expand Down

0 comments on commit 80857ec

Please sign in to comment.