diff --git a/docs/data-sources/devices.md b/docs/data-sources/devices.md index e753eddd..f0096283 100644 --- a/docs/data-sources/devices.md +++ b/docs/data-sources/devices.md @@ -43,6 +43,7 @@ Read-Only: - `asset_tag` (String) - `cluster_id` (Number) - `comments` (String) +- `custom_fields` (Map of String) - `device_id` (Number) - `device_type_id` (Number) - `location_id` (Number) diff --git a/docs/resources/device.md b/docs/resources/device.md index 960c2161..573bfdd7 100644 --- a/docs/resources/device.md +++ b/docs/resources/device.md @@ -56,6 +56,7 @@ resource "netbox_device" "test" { - `cluster_id` (Number) - `comments` (String) +- `custom_fields` (Map of String) - `location_id` (Number) - `platform_id` (Number) - `serial` (String) diff --git a/docs/resources/ip_address.md b/docs/resources/ip_address.md index 861e28c0..45ddb350 100644 --- a/docs/resources/ip_address.md +++ b/docs/resources/ip_address.md @@ -54,6 +54,7 @@ resource "netbox_ip_address" "myvm_ip" { - `description` (String) - `dns_name` (String) - `interface_id` (Number) +- `object_type` (String) Defaults to `virtualization.vminterface`. - `role` (String) - `tags` (Set of String) - `tenant_id` (Number) diff --git a/docs/resources/site.md b/docs/resources/site.md index 8d23f24e..7a2084a8 100644 --- a/docs/resources/site.md +++ b/docs/resources/site.md @@ -46,7 +46,9 @@ resource "netbox_site" "example1" { - `group_id` (Number) - `latitude` (Number) - `longitude` (Number) +- `physical_address` (String) - `region_id` (Number) +- `shipping_address` (String) - `slug` (String) - `status` (String) Defaults to `active`. - `tags` (Set of String) diff --git a/netbox/resource_netbox_ip_address.go b/netbox/resource_netbox_ip_address.go index 5927c9ca..8c5b650a 100644 --- a/netbox/resource_netbox_ip_address.go +++ b/netbox/resource_netbox_ip_address.go @@ -50,6 +50,12 @@ func resourceNetboxIPAddress() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "object_type": { + Type: schema.TypeString, + Optional: true, + Default: "virtualization.vminterface", + ValidateFunc: validation.StringInSlice([]string{"virtualization.vminterface", "dcim.interface"}, false), + }, tagsKey: tagsSchema, "description": { Type: schema.TypeString, @@ -114,8 +120,10 @@ func resourceNetboxIPAddressRead(d *schema.ResourceData, m interface{}) error { if res.GetPayload().AssignedObjectID != nil { d.Set("interface_id", res.GetPayload().AssignedObjectID) + d.Set("object_type", res.GetPayload().AssignedObjectType) } else { d.Set("interface_id", nil) + d.Set("object_type", nil) } if res.GetPayload().Vrf != nil { @@ -156,6 +164,7 @@ func resourceNetboxIPAddressUpdate(d *schema.ResourceData, m interface{}) error ipAddress := d.Get("ip_address").(string) status := d.Get("status").(string) + objectType := d.Get("object_type").(string) descriptionValue, ok := d.GetOk("description") if ok { @@ -179,8 +188,7 @@ func resourceNetboxIPAddressUpdate(d *schema.ResourceData, m interface{}) error } if interfaceID, ok := d.GetOk("interface_id"); ok { - // The other possible type is dcim.interface for devices - data.AssignedObjectType = strToPtr("virtualization.vminterface") + data.AssignedObjectType = strToPtr(objectType) data.AssignedObjectID = int64ToPtr(int64(interfaceID.(int))) } diff --git a/netbox/resource_netbox_ip_address_test.go b/netbox/resource_netbox_ip_address_test.go index 09309694..89289655 100644 --- a/netbox/resource_netbox_ip_address_test.go +++ b/netbox/resource_netbox_ip_address_test.go @@ -47,6 +47,41 @@ resource "netbox_interface" "test" { `, testName) } +func testAccNetboxIPAddressFullDeviceDependencies(testName string) string { + return fmt.Sprintf(` +resource "netbox_site" "test" { + name = "%[1]s" + status = "active" +} + +resource "netbox_device_role" "test" { + name = "%[1]s" + color_hex = "123456" +} + +resource "netbox_manufacturer" "test" { + name = "%[1]s" +} + +resource "netbox_device_type" "test" { + model = "%[1]s" + manufacturer_id = netbox_manufacturer.test.id +} + +resource "netbox_device" "test" { + name = "%[1]s" + site_id = netbox_site.test.id + device_type_id = netbox_device_type.test.id + role_id = netbox_device_role.test.id +} +resource "netbox_device_interface" "test" { + name = "%[1]s" + device_id = netbox_device.test.id + type = "1000base-t" +} +`, testName) +} + func TestAccNetboxIPAddress_basic(t *testing.T) { testIP := "1.1.1.1/32" @@ -66,10 +101,12 @@ resource "netbox_ip_address" "test" { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("netbox_ip_address.test", "ip_address", testIP), resource.TestCheckResourceAttr("netbox_ip_address.test", "status", "active"), + resource.TestCheckResourceAttr("netbox_ip_address.test", "object_type", "virtualization.vminterface"), resource.TestCheckResourceAttr("netbox_ip_address.test", "tags.#", "1"), resource.TestCheckResourceAttr("netbox_ip_address.test", "tags.0", testName), resource.TestCheckResourceAttr("netbox_ip_address.test", "tenant_id", "0"), resource.TestCheckResourceAttr("netbox_ip_address.test", "vrf_id", "0"), + resource.TestCheckResourceAttrPair("netbox_ip_address.test", "interface_id", "netbox_interface.test", "id"), ), }, { @@ -87,10 +124,12 @@ resource "netbox_ip_address" "test" { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("netbox_ip_address.test", "ip_address", testIP), resource.TestCheckResourceAttr("netbox_ip_address.test", "status", "reserved"), + resource.TestCheckResourceAttr("netbox_ip_address.test", "object_type", "virtualization.vminterface"), resource.TestCheckResourceAttrPair("netbox_ip_address.test", "tenant_id", "netbox_tenant.test", "id"), resource.TestCheckResourceAttrPair("netbox_ip_address.test", "vrf_id", "netbox_vrf.test", "id"), resource.TestCheckResourceAttr("netbox_ip_address.test", "description", fmt.Sprintf("description for %[1]s", testIP)), resource.TestCheckResourceAttr("netbox_ip_address.test", "role", "loopback"), + resource.TestCheckResourceAttrPair("netbox_ip_address.test", "interface_id", "netbox_interface.test", "id"), ), }, { @@ -104,9 +143,11 @@ resource "netbox_ip_address" "test" { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("netbox_ip_address.test", "ip_address", testIP), resource.TestCheckResourceAttr("netbox_ip_address.test", "status", "dhcp"), + resource.TestCheckResourceAttr("netbox_ip_address.test", "object_type", "virtualization.vminterface"), resource.TestCheckResourceAttr("netbox_ip_address.test", "tenant_id", "0"), resource.TestCheckResourceAttr("netbox_ip_address.test", "vrf_id", "0"), resource.TestCheckResourceAttr("netbox_ip_address.test", "role", ""), + resource.TestCheckResourceAttrPair("netbox_ip_address.test", "interface_id", "netbox_interface.test", "id"), ), }, { @@ -130,6 +171,8 @@ resource "netbox_ip_address" "test" { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("netbox_ip_address.test", "ip_address", testIP), resource.TestCheckResourceAttr("netbox_ip_address.test", "status", "deprecated"), + resource.TestCheckResourceAttr("netbox_ip_address.test", "object_type", "virtualization.vminterface"), + resource.TestCheckResourceAttrPair("netbox_ip_address.test", "interface_id", "netbox_interface.test", "id"), ), }, { @@ -144,8 +187,42 @@ resource "netbox_ip_address" "test" { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("netbox_ip_address.test", "ip_address", testIP), resource.TestCheckResourceAttr("netbox_ip_address.test", "status", "active"), + resource.TestCheckResourceAttr("netbox_ip_address.test", "object_type", "virtualization.vminterface"), resource.TestCheckResourceAttr("netbox_ip_address.test", "tags.#", "1"), resource.TestCheckResourceAttr("netbox_ip_address.test", "dns_name", "mytest.example.com"), + resource.TestCheckResourceAttrPair("netbox_ip_address.test", "interface_id", "netbox_interface.test", "id"), + ), + }, + { + ResourceName: "netbox_ip_address.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetboxIPAddressDevice_basic(t *testing.T) { + + testIP := "1.1.1.2/32" + testSlug := "ipaddress" + testName := testAccGetTestName(testSlug) + resource.ParallelTest(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccNetboxIPAddressFullDeviceDependencies(testName) + fmt.Sprintf(` +resource "netbox_ip_address" "test" { + ip_address = "%s" + object_type = "dcim.interface" + interface_id = netbox_device_interface.test.id + status = "active" +}`, testIP), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netbox_ip_address.test", "ip_address", testIP), + resource.TestCheckResourceAttr("netbox_ip_address.test", "status", "active"), + resource.TestCheckResourceAttr("netbox_ip_address.test", "object_type", "dcim.interface"), + resource.TestCheckResourceAttrPair("netbox_ip_address.test", "interface_id", "netbox_device_interface.test", "id"), ), }, {