Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ 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.
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`.

Expand Down
18 changes: 17 additions & 1 deletion docs/resources/available_ip_address.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ resource "netbox_available_ip_address" "myvm-ip" {
}
```

### Creating an IP with Custom Fields
```terraform
data "netbox_prefix" "test" {
cidr = "10.0.0.0/24"
}

resource "netbox_available_ip_address" "test" {
prefix_id = data.netbox_prefix.test.id

custom_fields = {
"test_field_1" = "test_field_value_1",
"test_field_2" = "test_field_value_2"
}
}
```
<!-- schema generated by tfplugindocs -->
## Schema

Expand All @@ -95,7 +110,8 @@ resource "netbox_available_ip_address" "myvm-ip" {
- `tenant_id` (Number)
- `virtual_machine_interface_id` (Number) Conflicts with `interface_id` and `device_interface_id`.
- `vrf_id` (Number)

- `custom_fields` (Map of String)
-
### Read-Only

- `id` (String) The ID of this resource.
Expand Down
4 changes: 4 additions & 0 deletions examples/resources/netbox_available_ip_address/prefix.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ data "netbox_prefix" "test" {

resource "netbox_available_ip_address" "test" {
prefix_id = data.netbox_prefix.test.id
custom_fields = {
"test_field_1" = "test_field_value_1",
"test_field_2" = "test_field_value_2"
}
}
12 changes: 9 additions & 3 deletions netbox/resource_netbox_available_ip_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ This resource will retrieve the next available IP address from a given prefix or
Type: schema.TypeString,
Optional: true,
},
tagsKey: tagsSchema,
tagsKey: tagsSchema,
customFieldsKey: customFieldsSchema,
"role": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -192,6 +193,10 @@ func resourceNetboxAvailableIPAddressRead(d *schema.ResourceData, m interface{})
d.Set("description", ipAddress.Description)
d.Set("status", ipAddress.Status.Value)
d.Set(tagsKey, getTagListFromNestedTagList(ipAddress.Tags))
cf := getCustomFields(ipAddress.CustomFields)
if cf != nil {
d.Set(customFieldsKey, cf)
}
return nil
}

Expand All @@ -209,13 +214,14 @@ func resourceNetboxAvailableIPAddressUpdate(d *schema.ResourceData, m interface{
data.DNSName = getOptionalStr(d, "dns_name", false)
data.Vrf = getOptionalInt(d, "vrf_id")
data.Tenant = getOptionalInt(d, "tenant_id")

if interfaceID, ok := d.GetOk("interface_id"); ok {
// The other possible type is dcim.interface for devices
data.AssignedObjectType = strToPtr("virtualization.vminterface")
data.AssignedObjectID = int64ToPtr(int64(interfaceID.(int)))
}

if customFields, ok := d.GetOk(customFieldsKey); ok {
data.CustomFields = getCustomFields(customFields)
}
vmInterfaceID := getOptionalInt(d, "virtual_machine_interface_id")
deviceInterfaceID := getOptionalInt(d, "device_interface_id")
interfaceID := getOptionalInt(d, "interface_id")
Expand Down
32 changes: 32 additions & 0 deletions netbox/resource_netbox_available_ip_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,38 @@ resource "netbox_available_ip_address" "test" {
},
})
}
func TestAccNetboxAvailableIPAddress_customField(t *testing.T) {
testPrefix := "1.1.8.0/24"
testIP := "1.1.8.1/24"
resource.ParallelTest(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "netbox_prefix" "test" {
prefix = "%s"
status = "active"
is_pool = false
}
resource "netbox_custom_field" "test_ip_address" {
name = "custom_field_ip_address"
type = "text"
content_types = ["ipam.ipaddress"]
}
resource "netbox_available_ip_address" "test" {
prefix_id = netbox_prefix.test.id
status = "active"
custom_fields = {"${netbox_custom_field.test_ip_address.name}" = "HelloWorld"}
}`, testPrefix),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_available_ip_address.test", "ip_address", testIP),
resource.TestCheckResourceAttr("netbox_available_ip_address.test", "status", "active"),
resource.TestCheckResourceAttr("netbox_available_ip_address.test", "custom_fields.custom_field_ip_address", "HelloWorld"),
),
},
},
})
}

func init() {
resource.AddTestSweepers("netbox_available_ip_address", &resource.Sweeper{
Expand Down