diff --git a/netbox/resource_netbox_prefix_test.go b/netbox/resource_netbox_prefix_test.go index b715560e..ed991b8b 100644 --- a/netbox/resource_netbox_prefix_test.go +++ b/netbox/resource_netbox_prefix_test.go @@ -233,7 +233,7 @@ resource "netbox_prefix" "test" { { Config: testAccNetboxPrefixFullDependencies(testName, randomSlug, testVid) + fmt.Sprintf(` resource "netbox_custom_field" "test" { - name = "test" + name = "%s" type = "text" weight = 100 content_types = ["ipam.prefix"] @@ -249,9 +249,52 @@ resource "netbox_prefix" "test" { custom_fields = { "${netbox_custom_field.test.name}" = "test-field" } -}`, testPrefix, testDesc), +}`, testSlug, testPrefix, testDesc), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netbox_prefix.test", fmt.Sprintf("custom_fields.%s", testSlug), "test-field"), + ), + }, + { + ResourceName: "netbox_prefix.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetboxPrefix_customFields(t *testing.T) { + testPrefix := "1.1.2.128/25" + testSlug := "prefix_cf" + testVid := "124" + randomSlug := testAccGetTestName(testSlug) + testDesc := "test prefix 2" + testName := testAccGetTestName(testSlug) + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccNetboxPrefixFullDependencies(testName, randomSlug, testVid) + fmt.Sprintf(` +resource "netbox_custom_field" "test" { + name = "%s" + type = "text" + weight = 100 + content_types = ["ipam.prefix"] +} + +resource "netbox_prefix" "test" { + prefix = "%s" + description = "%s 2" + status = "active" + tags = [netbox_tag.test.name] + mark_utilized = true + + custom_fields = { + "${netbox_custom_field.test.name}" = "test-field" + } +}`, testSlug, testPrefix, testDesc), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("netbox_prefix.test", "custom_fields.test", "test-field"), + resource.TestCheckResourceAttr("netbox_prefix.test", fmt.Sprintf("custom_fields.%s", testSlug), "test-field"), ), }, { diff --git a/netbox/resource_netbox_service_test.go b/netbox/resource_netbox_service_test.go index 5f346072..460446ba 100644 --- a/netbox/resource_netbox_service_test.go +++ b/netbox/resource_netbox_service_test.go @@ -76,7 +76,7 @@ func TestAccNetboxService_customFields(t *testing.T) { { Config: testAccNetboxServiceFullDependencies(testName) + fmt.Sprintf(` resource "netbox_custom_field" "test" { - name = "custom_field" + name = "%s" type = "text" content_types = ["ipam.service"] } @@ -86,14 +86,14 @@ resource "netbox_service" "test_customfield" { ports = [333] protocol = "tcp" custom_fields = {"${netbox_custom_field.test.name}" = "testtext"} -}`, testName), +}`, testSlug, testName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("netbox_service.test_customfield", "name", testName), resource.TestCheckResourceAttrPair("netbox_service.test_customfield", "virtual_machine_id", "netbox_virtual_machine.test", "id"), resource.TestCheckResourceAttr("netbox_service.test_customfield", "ports.#", "1"), resource.TestCheckResourceAttr("netbox_service.test_customfield", "ports.0", "333"), resource.TestCheckResourceAttr("netbox_service.test_customfield", "protocol", "tcp"), - resource.TestCheckResourceAttr("netbox_service.test_customfield", "custom_fields.custom_field", "testtext"), + resource.TestCheckResourceAttr("netbox_service.test_customfield", fmt.Sprintf("custom_fields.%s", testSlug), "testtext"), ), }, { diff --git a/netbox/resource_netbox_virtual_machine_test.go b/netbox/resource_netbox_virtual_machine_test.go index 4d6746bc..2099cd01 100644 --- a/netbox/resource_netbox_virtual_machine_test.go +++ b/netbox/resource_netbox_virtual_machine_test.go @@ -411,18 +411,18 @@ func TestAccNetboxVirtualMachine_customFields(t *testing.T) { { Config: testAccNetboxVirtualMachineFullDependencies(testName) + fmt.Sprintf(` resource "netbox_custom_field" "test" { - name = "custom_field" + name = "%s" type = "text" content_types = ["virtualization.virtualmachine"] } resource "netbox_virtual_machine" "test" { - name = "%[1]s" + name = "%s" cluster_id = netbox_cluster.test.id site_id = netbox_site.test.id custom_fields = {"${netbox_custom_field.test.name}" = "76"} -}`, testName), +}`, testSlug, testName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("netbox_virtual_machine.test", "custom_fields.custom_field", "76"), + resource.TestCheckResourceAttr("netbox_virtual_machine.test", fmt.Sprintf("custom_fields.%s", testSlug), "76"), ), }, },