Skip to content

Commit

Permalink
feat: Add contact assignment resource
Browse files Browse the repository at this point in the history
  • Loading branch information
smutel committed Jun 8, 2022
1 parent 38f4acb commit 2b413f2
Show file tree
Hide file tree
Showing 63 changed files with 530 additions and 39 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/dcim_platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/dcim_site.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/ipam_aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/ipam_ip_addresses.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/ipam_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/ipam_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/ipam_vlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/ipam_vlan_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/tenancy_contact.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/tenancy_contact_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/tenancy_contact_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/tenancy_tenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/tenancy_tenant_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/data-sources/virtualization_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ The following arguments are supported:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.
1 change: 1 addition & 0 deletions docs/resources/ipam_aggregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/ipam_ip_addresses.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/ipam_prefix.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The ``tag`` block supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/ipam_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/ipam_vlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The ``tag`` block supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/ipam_vlan_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/tenancy_contact.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
37 changes: 37 additions & 0 deletions docs/resources/tenancy_contact_assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# netbox\_tenancy\_contact\_assignment Resource

Link a contact to another resource within Netbox.

## Example Usage

```hcl
resource "netbox_tenancy_contact_assignment" "contact_assignment_01" {
contact_id = netbox_tenancy_contact.contact.id
contact_role_id = netbox_tenancy_contact_role.contact_role_02.id
content_type = netbox_virtualization_vm.vm_test.content_type
object_id = netbox_virtualization_vm.vm_test.id
priority = "primary"
}
```

## Argument Reference

The following arguments are supported:
* ``contact_id`` - (Required) ID of the contact to link to a resource.
* ``contact_role_id`` - (Required) The role of the contact for this resource.
* ``content_type`` - (Required) Type of the object where the contact will be linked.
* ``object_id`` - (Required) ID of the object where the contact will be linked.
* ``priority`` - (Required) Priority of this contact among primary, secondary and tertiary (primary by default).

## Attributes Reference

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.

## Import

Contact assignments can be imported by `id` e.g.

```
$ terraform import netbox_tenancy_contact_assignment.contact_assignment_test id
```
1 change: 1 addition & 0 deletions docs/resources/tenancy_contact_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/tenancy_contact_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/tenancy_tenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/tenancy_tenant_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/virtualization_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The ``custom_field`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
1 change: 1 addition & 0 deletions docs/resources/virtualization_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ The ``tag`` block (optional) supports:

In addition to the above arguments, the following attributes are exported:
* ``id`` - The id (ref in Netbox) of this object.
* ``content_type`` - The content type of this object.

## Import

Expand Down
14 changes: 14 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,17 @@ resource "netbox_tenancy_contact_role" "contact_role_01" {
value = "0,1"
}
}

resource "netbox_tenancy_contact_role" "contact_role_02" {
name = "Another contact role"
slug = "cr02"
description = "Another contact role"
}

resource "netbox_tenancy_contact_assignment" "contact_assignment_01" {
contact_id = netbox_tenancy_contact.contact.id
contact_role_id = netbox_tenancy_contact_role.contact_role_02.id
content_type = netbox_virtualization_vm.vm_test.content_type
object_id = netbox_virtualization_vm.vm_test.id
priority = "primary"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/smutel/go-netbox v3.1.0+incompatible
github.com/smutel/go-netbox v3.1.1+incompatible
github.com/vmihailenco/tagparser v0.1.2 // indirect
go.mongodb.org/mongo-driver v1.9.1 // indirect
golang.org/x/net v0.0.0-20220516155154-20f960328961 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/smutel/go-netbox v3.1.0+incompatible h1:2M1vldc2YIGs7OdPK+ujizRyghy04cK9Uzswgoc1Tcg=
github.com/smutel/go-netbox v3.1.0+incompatible/go.mod h1:UlNOimilX5qQkyVvFaDgajexiCRjVqzh1i0r9kQfr+M=
github.com/smutel/go-netbox v3.1.1+incompatible h1:H+4/jVhl0iaIKGch2tdDLDUArsDg+57TTc1phmm+mNw=
github.com/smutel/go-netbox v3.1.1+incompatible/go.mod h1:UlNOimilX5qQkyVvFaDgajexiCRjVqzh1i0r9kQfr+M=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
8 changes: 7 additions & 1 deletion netbox/data_netbox_dcim_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func dataNetboxDcimPlatform() *schema.Resource {
Read: dataNetboxDcimPlatformRead,

Schema: map[string]*schema.Schema{
"content_type": {
Type: schema.TypeString,
Computed: true,
},
"slug": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -47,7 +51,9 @@ func dataNetboxDcimPlatformRead(d *schema.ResourceData, m interface{}) error {
"Please try a more specific search criteria.")
}

d.SetId(strconv.FormatInt(list.Payload.Results[0].ID, 10))
r := list.Payload.Results[0]
d.SetId(strconv.FormatInt(r.ID, 10))
d.Set("content_type", convertURIContentType(r.URL))

return nil
}
8 changes: 7 additions & 1 deletion netbox/data_netbox_dcim_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func dataNetboxDcimSite() *schema.Resource {
Read: dataNetboxDcimSiteRead,

Schema: map[string]*schema.Schema{
"content_type": {
Type: schema.TypeString,
Computed: true,
},
"slug": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -47,7 +51,9 @@ func dataNetboxDcimSiteRead(d *schema.ResourceData, m interface{}) error {
"Please try a more specific search criteria.")
}

d.SetId(strconv.FormatInt(list.Payload.Results[0].ID, 10))
r := list.Payload.Results[0]
d.SetId(strconv.FormatInt(r.ID, 10))
d.Set("content_type", convertURIContentType(r.URL))

return nil
}
8 changes: 7 additions & 1 deletion netbox/data_netbox_ipam_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func dataNetboxIpamAggregate() *schema.Resource {
Read: dataNetboxIpamAggregateRead,

Schema: map[string]*schema.Schema{
"content_type": {
Type: schema.TypeString,
Computed: true,
},
"prefix": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -50,7 +54,9 @@ func dataNetboxIpamAggregateRead(d *schema.ResourceData,
"Please try a more specific search criteria.")
}

d.SetId(strconv.FormatInt(list.Payload.Results[0].ID, 10))
r := list.Payload.Results[0]
d.SetId(strconv.FormatInt(r.ID, 10))
d.Set("content_type", convertURIContentType(r.URL))

return nil
}
8 changes: 7 additions & 1 deletion netbox/data_netbox_ipam_ip_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func dataNetboxIpamIPAddresses() *schema.Resource {
Read: dataNetboxIpamIPAddressesRead,

Schema: map[string]*schema.Schema{
"content_type": {
Type: schema.TypeString,
Computed: true,
},
"address": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -45,7 +49,9 @@ func dataNetboxIpamIPAddressesRead(d *schema.ResourceData,
"Please try a more specific search criteria.")
}

d.SetId(strconv.FormatInt(list.Payload.Results[0].ID, 10))
r := list.Payload.Results[0]
d.SetId(strconv.FormatInt(r.ID, 10))
d.Set("content_type", convertURIContentType(r.URL))

return nil
}
8 changes: 7 additions & 1 deletion netbox/data_netbox_ipam_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func dataNetboxIpamRole() *schema.Resource {
Read: dataNetboxIpamRoleRead,

Schema: map[string]*schema.Schema{
"content_type": {
Type: schema.TypeString,
Computed: true,
},
"slug": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -47,7 +51,9 @@ func dataNetboxIpamRoleRead(d *schema.ResourceData, m interface{}) error {
"Please try a more specific search criteria.")
}

d.SetId(strconv.FormatInt(list.Payload.Results[0].ID, 10))
r := list.Payload.Results[0]
d.SetId(strconv.FormatInt(r.ID, 10))
d.Set("content_type", convertURIContentType(r.URL))

return nil
}
8 changes: 7 additions & 1 deletion netbox/data_netbox_ipam_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func dataNetboxIpamService() *schema.Resource {
Read: dataNetboxIpamServiceRead,

Schema: map[string]*schema.Schema{
"content_type": {
Type: schema.TypeString,
Computed: true,
},
"device_id": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -78,7 +82,9 @@ func dataNetboxIpamServiceRead(d *schema.ResourceData,
"Please try a more specific search criteria.")
}

d.SetId(strconv.FormatInt(list.Payload.Results[0].ID, 10))
r := list.Payload.Results[0]
d.SetId(strconv.FormatInt(r.ID, 10))
d.Set("content_type", convertURIContentType(r.URL))

return nil
}
Loading

0 comments on commit 2b413f2

Please sign in to comment.