Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow netbox_custom_field to accept object as type, and specify object_type #593

Closed
Closed
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
8 changes: 8 additions & 0 deletions netbox/resource_netbox_custom_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ func resourceCustomField() *schema.Resource {
models.CustomFieldTypeValueSelect,
models.CustomFieldTypeValueMultiselect,
models.CustomFieldTypeValueJSON,
models.CustomFieldTypeValueObject,
}, false),
},
"object_type": {
Type: schema.TypeString,
Optional: true,
},
"content_types": {
Type: schema.TypeSet,
Required: true,
Expand Down Expand Up @@ -108,6 +113,7 @@ func resourceNetboxCustomFieldUpdate(d *schema.ResourceData, m interface{}) erro
data := &models.WritableCustomField{
Name: strToPtr(d.Get("name").(string)),
Type: d.Get("type").(string),
ObjectType: d.Get("object_type").(string),
Description: d.Get("description").(string),
GroupName: d.Get("group_name").(string),
Label: d.Get("label").(string),
Expand Down Expand Up @@ -154,6 +160,7 @@ func resourceNetboxCustomFieldCreate(d *schema.ResourceData, m interface{}) erro
data := &models.WritableCustomField{
Name: strToPtr(d.Get("name").(string)),
Type: d.Get("type").(string),
ObjectType: d.Get("object_type").(string),
Description: d.Get("description").(string),
GroupName: d.Get("group_name").(string),
Label: d.Get("label").(string),
Expand Down Expand Up @@ -217,6 +224,7 @@ func resourceNetboxCustomFieldRead(d *schema.ResourceData, m interface{}) error
customField := res.GetPayload()
d.Set("name", customField.Name)
d.Set("type", *customField.Type.Value)
d.Set("object_type", customField.ObjectType)

d.Set("content_types", customField.ContentTypes)

Expand Down
29 changes: 29 additions & 0 deletions netbox/resource_netbox_custom_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ resource "netbox_custom_field" "test" {
})
}

func TestAccNetboxCustomField_object(t *testing.T) {
testSlug := "custom_fields_object"
testName := strings.ReplaceAll(testAccGetTestName(testSlug), "-", "_")
resource.Test(t, resource.TestCase{
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "netbox_custom_field" "test" {
name = "%s"
type = "object"
object_type = "ipam.prefix"
content_types = ["virtualization.vminterface"]
group_name = "mygroup"
weight = 100
}`, testName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netbox_custom_field.test", "name", testName),
resource.TestCheckResourceAttr("netbox_custom_field.test", "type", "object"),
resource.TestCheckTypeSetElemAttr("netbox_custom_field.test", "content_types.*", "virtualization.vminterface"),
resource.TestCheckResourceAttr("netbox_custom_field.test", "group_name", "mygroup"),
resource.TestCheckResourceAttr("netbox_custom_field.test", "weight", "100"),
),
},
},
})
}

func TestAccNetboxCustomField_integer(t *testing.T) {
testSlug := "custom_fields_integer"
testName := strings.ReplaceAll(testAccGetTestName(testSlug), "-", "_")
Expand Down
Loading