Skip to content

Commit

Permalink
fix: handle netbox 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sjurtf committed Sep 27, 2024
1 parent a4e9def commit a6e6fb5
Show file tree
Hide file tree
Showing 20 changed files with 24 additions and 111 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,9 @@ jobs:
fail-fast: false
matrix:
netbox-version:
# - v4.0.0 has mandatory tenant group
- v4.0.1
- v4.0.2
- v4.0.3
# - v4.0.4 does not exist for some reason
- v4.0.5
- v4.0.6
- v4.0.7
- v4.0.8
- v4.0.9
- v4.0.10
- v4.1.0
- v4.1.1
- v4.1.2
steps:
- uses: actions/checkout@v4
- name: Set up Go
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TEST_FUNC?=TestAccNetboxEventRule_basic
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
DOCKER_COMPOSE=docker compose

export NETBOX_VERSION=v4.0.10
export NETBOX_VERSION=v4.1.2
export NETBOX_SERVER_URL=http://localhost:8001
export NETBOX_API_TOKEN=0123456789abcdef0123456789abcdef01234567
export NETBOX_TOKEN=$(NETBOX_API_TOKEN)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Since version [1.6.6](https://github.com/e-breuninger/terraform-provider-netbox/

| Netbox version | Provider version |
| --------------- | ---------------- |
| v4.0.0 - 4.0.10 | v3.9.0 and up |
| v4.1.0 - 4.1.2 | v3.10.0 and up |
| v4.0.0 - 4.0.10 | v3.9.0 - 3.9.1 |
| v3.7.0 - 3.7.8 | v3.8.0 - 3.8.9 |
| v3.6.0 - 3.6.9 | v3.7.0 - 3.7.7 |
| v3.5.1 - 3.5.9 | v3.6.x |
Expand Down
2 changes: 0 additions & 2 deletions docs/data-sources/vlan_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ data "netbox_vlan_group" "example3" {

- `description` (String)
- `id` (String) The ID of this resource.
- `max_vid` (Number)
- `min_vid` (Number)
- `vlan_count` (Number)


3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Netbox often makes breaking API changes even in non-major releases. Check the ta

| Netbox version | Provider version |
| --------------- | ---------------- |
| v4.0.0 - 4.0.10 | v3.9.0 and up |
| v4.1.0 - 4.1.2 | v3.10.0 and up |
| v4.0.0 - 4.0.10 | v3.9.0 - 3.9.1 |
| v3.7.0 - 3.7.8 | v3.8.0 - 3.8.9 |
| v3.6.0 - 3.6.9 | v3.7.0 - 3.7.7 |
| v3.5.1 - 3.5.9 | v3.6.x |
Expand Down
1 change: 0 additions & 1 deletion docs/resources/rack.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ resource "netbox_rack" "test" {
- `serial` (String)
- `tags` (Set of String)
- `tenant_id` (Number)
- `type` (String) Valid values are `2-post-frame`, `4-post-frame`, `4-post-cabinet`, `wall-frame`, `wall-frame-vertical`, `wall-cabinet` and `wall-cabinet-vertical`.
- `weight` (Number)
- `weight_unit` (String) Valid values are `kg`, `g`, `lb` and `oz`. Required when `weight` and `max_weight` is set.

Expand Down
6 changes: 0 additions & 6 deletions docs/resources/vlan_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ description: |-
resource "netbox_vlan_group" "example1" {
name = "example1"
slug = "example1"
min_vid = 1
max_vid = 4094
}
#Full VLAN Group example
resource "netbox_vlan_group" "example2" {
name = "Second Example"
slug = "example2"
min_vid = 1
max_vid = 4094
scope_type = "dcim.site"
scope_id = netbox_site.example.id
description = "Second Example VLAN Group"
Expand All @@ -39,8 +35,6 @@ resource "netbox_vlan_group" "example2" {

### Required

- `max_vid` (Number)
- `min_vid` (Number)
- `name` (String)
- `slug` (String)

Expand Down
4 changes: 0 additions & 4 deletions examples/resources/netbox_vlan_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
resource "netbox_vlan_group" "example1" {
name = "example1"
slug = "example1"
min_vid = 1
max_vid = 4094
}

#Full VLAN Group example
resource "netbox_vlan_group" "example2" {
name = "Second Example"
slug = "example2"
min_vid = 1
max_vid = 4094
scope_type = "dcim.site"
scope_id = netbox_site.example.id
description = "Second Example VLAN Group"
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 @@ -244,7 +244,7 @@ func dataSourceNetboxVirtualMachineRead(d *schema.ResourceData, m interface{}) e
mapping["custom_fields"] = v.CustomFields
}
if v.Disk != nil {
mapping["disk_size_gb"] = *v.Disk
mapping["disk_size_gb"] = *v.Disk / 1000
}
if v.LocalContextData != nil {
if localContextData, err := json.Marshal(v.LocalContextData); err == nil {
Expand Down
10 changes: 0 additions & 10 deletions netbox/data_source_netbox_vlan_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ func dataSourceNetboxVlanGroup() *schema.Resource {
Optional: true,
RequiredWith: []string{"scope_type"},
},
"min_vid": {
Type: schema.TypeInt,
Computed: true,
},
"max_vid": {
Type: schema.TypeInt,
Computed: true,
},
"vlan_count": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -92,8 +84,6 @@ func dataSourceNetboxVlanGroupRead(d *schema.ResourceData, m interface{}) error
d.SetId(strconv.FormatInt(result.ID, 10))
d.Set("name", result.Name)
d.Set("slug", result.Slug)
d.Set("min_vid", result.MinVid)
d.Set("max_vid", result.MaxVid)
d.Set("vlan_count", result.VlanCount)
d.Set("description", result.Description)
return nil
Expand Down
10 changes: 0 additions & 10 deletions netbox/data_source_netbox_vlan_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func TestAccNetboxVlanGroupDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "name", testName),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "slug", testSlug),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "description", "Test"),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "min_vid", "20"),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "max_vid", "200"),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "scope_type", "dcim.site"),
resource.TestCheckResourceAttrPair("data.netbox_vlan_group.test", "scope_id", "netbox_site.test", "id"),
),
Expand All @@ -56,8 +54,6 @@ func TestAccNetboxVlanGroupDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "name", testName),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "slug", testSlug),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "description", "Test"),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "min_vid", "20"),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "max_vid", "200"),
resource.TestCheckResourceAttr("data.netbox_vlan_group.test", "scope_type", "dcim.site"),
resource.TestCheckResourceAttrPair("data.netbox_vlan_group.test", "scope_id", "netbox_site.test", "id"),
),
Expand All @@ -84,8 +80,6 @@ resource "netbox_vlan_group" "test" {
slug = "%[1]s"
name = "%[2]s"
description = "Test"
min_vid = 20
max_vid = 200
scope_type = "dcim.site"
scope_id = netbox_site.test.id
tags = []
Expand All @@ -98,15 +92,11 @@ func testAccNetboxVlanGroupSetUpMore(testSlug, anotherSlug, testName string) str
resource "netbox_vlan_group" "same_name" {
slug = "%[1]s"
name = "%[3]s"
min_vid = 20
max_vid = 200
}
resource "netbox_vlan_group" "not_same" {
slug = "%[2]s"
name = "%[3]s_unique"
min_vid = 20
max_vid = 200
}
`, testSlug, anotherSlug, testName)
}
Expand Down
2 changes: 1 addition & 1 deletion netbox/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func providerConfigure(ctx context.Context, data *schema.ResourceData) (interfac

netboxVersion := res.GetPayload().(map[string]interface{})["netbox-version"].(string)

supportedVersions := []string{"4.0.0", "4.0.1", "4.0.2", "4.0.3", "4.0.5", "4.0.6", "4.0.7", "4.0.8", "4.0.9", "4.0.10"}
supportedVersions := []string{"4.1.0", "4.1.1", "4.1.2"}

if !slices.Contains(supportedVersions, netboxVersion) {
// Currently, there is no way to test these warnings. There is an issue to track this: https://github.com/hashicorp/terraform-plugin-sdk/issues/864
Expand Down
15 changes: 0 additions & 15 deletions netbox/resource_netbox_rack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

var resourceNetboxRackStatusOptions = []string{"reserved", "available", "planned", "active", "deprecated"}
var resourceNetboxRackTypeOptions = []string{"2-post-frame", "4-post-frame", "4-post-cabinet", "wall-frame", "wall-frame-vertical", "wall-cabinet", "wall-cabinet-vertical"}
var resourceNetboxRackWeightUnitOptions = []string{"kg", "g", "lb", "oz"}
var resourceNetboxRackOuterUnitOptions = []string{"mm", "in"}
var resourceNetboxRackWidthOptions = []int{10, 19, 21, 23}
Expand Down Expand Up @@ -84,12 +83,6 @@ Each rack is assigned a name and (optionally) a separate facility ID. This is he
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 50),
},
"type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(resourceNetboxRackTypeOptions, false),
Description: buildValidValueDescription(resourceNetboxRackTypeOptions),
},
"weight": {
Type: schema.TypeFloat,
Optional: true,
Expand Down Expand Up @@ -178,7 +171,6 @@ func resourceNetboxRackCreate(d *schema.ResourceData, m interface{}) error {
if assetTag := getOptionalStr(d, "asset_tag", false); assetTag != "" {
data.AssetTag = &assetTag
}
data.Type = getOptionalStr(d, "type", false)
data.Weight = getOptionalFloat(d, "weight")
data.MaxWeight = getOptionalInt(d, "max_weight")
data.WeightUnit = getOptionalStr(d, "weight_unit", false)
Expand Down Expand Up @@ -279,12 +271,6 @@ func resourceNetboxRackRead(d *schema.ResourceData, m interface{}) error {
d.Set("serial", rack.Serial)
d.Set("asset_tag", rack.AssetTag)

if rack.Type != nil {
d.Set("type", rack.Type.Value)
} else {
d.Set("type", nil)
}

d.Set("weight", rack.Weight)
d.Set("max_weight", rack.MaxWeight)

Expand Down Expand Up @@ -348,7 +334,6 @@ func resourceNetboxRackUpdate(d *schema.ResourceData, m interface{}) error {
if assetTag := getOptionalStr(d, "asset_tag", false); assetTag != "" {
data.AssetTag = &assetTag
}
data.Type = getOptionalStr(d, "type", false)
data.Weight = getOptionalFloat(d, "weight")
data.MaxWeight = getOptionalInt(d, "max_weight")
data.WeightUnit = getOptionalStr(d, "weight_unit", false)
Expand Down
3 changes: 0 additions & 3 deletions netbox/resource_netbox_rack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ resource "netbox_rack" "test" {
role_id = netbox_rack_role.test.id
serial = "%[1]sserial"
asset_tag = "%[1]sasset_tag"
type = "4-post-frame"
desc_units = true
outer_width = 10
outer_depth = 15
Expand Down Expand Up @@ -92,7 +91,6 @@ resource "netbox_rack" "test2" {
resource.TestCheckResourceAttrPair("netbox_rack.test", "role_id", "netbox_rack_role.test", "id"),
resource.TestCheckResourceAttr("netbox_rack.test", "serial", testName+"serial"),
resource.TestCheckResourceAttr("netbox_rack.test", "asset_tag", testName+"asset_tag"),
resource.TestCheckResourceAttr("netbox_rack.test", "type", "4-post-frame"),
resource.TestCheckResourceAttr("netbox_rack.test", "desc_units", "true"),
resource.TestCheckResourceAttr("netbox_rack.test", "outer_width", "10"),
resource.TestCheckResourceAttr("netbox_rack.test", "outer_depth", "15"),
Expand Down Expand Up @@ -129,7 +127,6 @@ resource "netbox_rack" "test" {
resource.TestCheckResourceAttr("netbox_rack.test", "role_id", "0"),
resource.TestCheckResourceAttr("netbox_rack.test", "serial", ""),
resource.TestCheckResourceAttr("netbox_rack.test", "asset_tag", ""),
resource.TestCheckResourceAttr("netbox_rack.test", "type", ""),
resource.TestCheckResourceAttr("netbox_rack.test", "weight", "0"),
resource.TestCheckResourceAttr("netbox_rack.test", "max_weight", "0"),
resource.TestCheckResourceAttr("netbox_rack.test", "weight_unit", ""),
Expand Down
4 changes: 2 additions & 2 deletions netbox/resource_netbox_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAccNetboxUser_basic(t *testing.T) {
Config: fmt.Sprintf(`
resource "netbox_user" "test_basic" {
username = "%s"
password = "abcdefghijkl"
password = "abcdefghijkl1"
active = true
staff = true
}`, testName),
Expand Down Expand Up @@ -56,7 +56,7 @@ resource "netbox_group" "test_group" {
resource "netbox_user" "test_group" {
username = "%[1]s"
password = "abcdefghijkl"
password = "abcdefghijkl1"
active = true
staff = true
group_ids = [netbox_group.test_group.id]
Expand Down
13 changes: 8 additions & 5 deletions netbox/resource_netbox_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func resourceNetboxVirtualMachineCreate(ctx context.Context, d *schema.ResourceD

diskSizeValue, ok := d.GetOk("disk_size_gb")
if ok {
diskSize := int64(diskSizeValue.(int))
data.Disk = &diskSize
diskSizeMb := int64(diskSizeValue.(int)) * 1000
data.Disk = &diskSizeMb
}

tenantIDValue, ok := d.GetOk("tenant_id")
Expand Down Expand Up @@ -308,7 +308,10 @@ func resourceNetboxVirtualMachineRead(ctx context.Context, d *schema.ResourceDat
d.Set("vcpus", nil)
}
d.Set("memory_mb", vm.Memory)
d.Set("disk_size_gb", vm.Disk)
if vm.Disk != nil {
diskSizeGb := *vm.Disk / 1000
d.Set("disk_size_gb", diskSizeGb)
}
if vm.Status != nil {
d.Set("status", vm.Status.Value)
} else {
Expand Down Expand Up @@ -383,8 +386,8 @@ func resourceNetboxVirtualMachineUpdate(ctx context.Context, d *schema.ResourceD

diskSizeValue, ok := d.GetOk("disk_size_gb")
if ok {
diskSize := int64(diskSizeValue.(int))
data.Disk = &diskSize
diskSizeMb := int64(diskSizeValue.(int)) * 1000
data.Disk = &diskSizeMb
}

primaryIP4Value, ok := d.GetOk("primary_ipv4")
Expand Down
20 changes: 0 additions & 20 deletions netbox/resource_netbox_vlan_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ func resourceNetboxVlanGroup() *schema.Resource {
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
"min_vid": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, 4093),
},
"max_vid": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(2, 4094),
},
"scope_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -73,14 +63,10 @@ func resourceNetboxVlanGroupCreate(d *schema.ResourceData, m interface{}) error

name := d.Get("name").(string)
slug := d.Get("slug").(string)
minVid := int64(d.Get("min_vid").(int))
maxVid := int64(d.Get("max_vid").(int))
description := d.Get("description").(string)

data.Name = &name
data.Slug = &slug
data.MinVid = minVid
data.MaxVid = maxVid
data.Description = description

if scopeType, ok := d.GetOk("scope_type"); ok {
Expand Down Expand Up @@ -125,8 +111,6 @@ func resourceNetboxVlanGroupRead(d *schema.ResourceData, m interface{}) error {

d.Set("name", vlanGroup.Name)
d.Set("slug", vlanGroup.Slug)
d.Set("min_vid", vlanGroup.MinVid)
d.Set("max_vid", vlanGroup.MaxVid)
d.Set("description", vlanGroup.Description)
d.Set(tagsKey, getTagListFromNestedTagList(vlanGroup.Tags))

Expand All @@ -148,14 +132,10 @@ func resourceNetboxVlanGroupUpdate(d *schema.ResourceData, m interface{}) error

name := d.Get("name").(string)
slug := d.Get("slug").(string)
minVid := int64(d.Get("min_vid").(int))
maxVid := int64(d.Get("max_vid").(int))
description := d.Get("description").(string)

data.Name = &name
data.Slug = &slug
data.MinVid = minVid
data.MaxVid = maxVid
data.Description = description

if scopeType, ok := d.GetOk("scope_type"); ok {
Expand Down
Loading

0 comments on commit a6e6fb5

Please sign in to comment.