-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
521 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# netbox\_tenancy\_contact\_group Data Source | ||
|
||
Get info about tenancy contact groups from netbox. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "netbox_tenancy_contact_group" "contact_group_test" { | ||
slug = "TestContactGroup" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
* ``slug`` - (Required) The slug of the tenancy contact groups. | ||
|
||
## Attributes Reference | ||
|
||
In addition to the above arguments, the following attributes are exported: | ||
* ``id`` - The id (ref in Netbox) of this object. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ resource "netbox_tenancy_contact" "contact_test" { | |
email = "[email protected]" | ||
address = "Somewhere in the world" | ||
comments = "Good contact" | ||
contact_group_id = netbox_tenancy_contact_group.contact_group_02.id | ||
tag { | ||
name = "tag1" | ||
|
@@ -71,6 +72,7 @@ The following arguments are supported: | |
* ``email`` - (Optional) The e-mail for this object. | ||
* ``address`` - (Optional) The address for this object. | ||
* ``comments`` - (Optional) Comments for this object. | ||
* ``contact_group_id`` - (Optional) ID of the group where this object belongs to. | ||
|
||
The ``custom_field`` block (optional) supports: | ||
* ``name`` - (Required) Name of the existing custom resource to associate with this resource. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# netbox\_tenancy\_contact\_group Resource | ||
|
||
Manage a contact group within Netbox. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "netbox_tenancy_contact_group" "contact_group_test" { | ||
description = "Contact group created by terraform" | ||
name = "TestContactGroup" | ||
parent_id = 10 | ||
slug = "TestContactGroup" | ||
tag { | ||
name = "tag1" | ||
slug = "tag1" | ||
} | ||
custom_field { | ||
name = "cf_boolean" | ||
type = "boolean" | ||
value = "true" | ||
} | ||
custom_field { | ||
name = "cf_date" | ||
type = "date" | ||
value = "2020-12-25" | ||
} | ||
custom_field { | ||
name = "cf_text" | ||
type = "text" | ||
value = "some text" | ||
} | ||
custom_field { | ||
name = "cf_integer" | ||
type = "integer" | ||
value = "10" | ||
} | ||
custom_field { | ||
name = "cf_selection" | ||
type = "selection" | ||
value = "1" | ||
} | ||
custom_field { | ||
name = "cf_url" | ||
type = "url" | ||
value = "https://github.com" | ||
} | ||
custom_field { | ||
name = "cf_multiple_selection" | ||
type = "multiple" | ||
value = "0,1" | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
* ``description`` - (Optional) Description for this object. | ||
* ``name`` - (Required) The name for this object. | ||
* ``parent_id`` - (Optional) ID of the parent. | ||
* ``slug`` - (Required) The slug for this object. | ||
|
||
The ``custom_field`` block (optional) supports: | ||
* ``name`` - (Required) Name of the existing custom resource to associate with this resource. | ||
* ``type`` - (Required) Type of the existing custom resource to associate with this resource (text, integer, boolean, url, selection, multiple). | ||
* ``value`` - (Required) Value of the existing custom resource to associate with this resource. | ||
|
||
The ``tag`` block (optional) supports: | ||
* ``name`` - (Required) Name of the existing tag to associate with this resource. | ||
* ``slug`` - (Required) Slug of the existing tag to associate with this resource. | ||
|
||
## Attributes Reference | ||
|
||
In addition to the above arguments, the following attributes are exported: | ||
* ``id`` - The id (ref in Netbox) of this object. | ||
|
||
## Import | ||
|
||
Contact groups can be imported by `id` e.g. | ||
|
||
``` | ||
$ terraform import netbox_tenancy_contact_group.contact_group_test id | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,6 +481,7 @@ resource "netbox_tenancy_contact" "contact" { | |
email = "[email protected]" | ||
address = "Somewhere in the world" | ||
comments = "Good contact" | ||
contact_group_id = netbox_tenancy_contact_group.contact_group_02.id | ||
|
||
tag { | ||
name = "tag1" | ||
|
@@ -534,3 +535,68 @@ resource "netbox_tenancy_contact" "contact" { | |
value = "0,1" | ||
} | ||
} | ||
|
||
resource "netbox_tenancy_contact_group" "contact_group_01" { | ||
name = "A contact group" | ||
slug = "cg01" | ||
description = "A contact group" | ||
|
||
tag { | ||
name = "tag1" | ||
slug = "tag1" | ||
} | ||
|
||
tag { | ||
name = "tag2" | ||
slug = "tag2" | ||
} | ||
|
||
custom_field { | ||
name = "cf_boolean" | ||
type = "boolean" | ||
value = "true" | ||
} | ||
|
||
custom_field { | ||
name = "cf_date" | ||
type = "date" | ||
value = "2020-12-25" | ||
} | ||
|
||
custom_field { | ||
name = "cf_text" | ||
type = "text" | ||
value = "some text" | ||
} | ||
|
||
custom_field { | ||
name = "cf_integer" | ||
type = "integer" | ||
value = "10" | ||
} | ||
|
||
custom_field { | ||
name = "cf_selection" | ||
type = "selection" | ||
value = "1" | ||
} | ||
|
||
custom_field { | ||
name = "cf_url" | ||
type = "url" | ||
value = "https://github.com" | ||
} | ||
|
||
custom_field { | ||
name = "cf_multiple_selection" | ||
type = "multiple" | ||
value = "0,1" | ||
} | ||
} | ||
|
||
resource "netbox_tenancy_contact_group" "contact_group_02" { | ||
name = "Another contact group" | ||
slug = "cg02" | ||
description = "Another contact group" | ||
parent_id = netbox_tenancy_contact_group.contact_group_01.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package netbox | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
netboxclient "github.com/smutel/go-netbox/netbox/client" | ||
"github.com/smutel/go-netbox/netbox/client/tenancy" | ||
) | ||
|
||
func dataNetboxTenancyContactGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataNetboxTenancyContactGroupRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"slug": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(1, 100), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataNetboxTenancyContactGroupRead(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*netboxclient.NetBoxAPI) | ||
|
||
slug := d.Get("slug").(string) | ||
|
||
p := tenancy.NewTenancyContactGroupsListParams().WithSlug(&slug) | ||
|
||
list, err := client.Tenancy.TenancyContactGroupsList(p, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if *list.Payload.Count < 1 { | ||
return fmt.Errorf("Your query returned no results. " + | ||
"Please change your search criteria and try again.") | ||
} else if *list.Payload.Count > 1 { | ||
return fmt.Errorf("Your query returned more than one result. " + | ||
"Please try a more specific search criteria.") | ||
} | ||
|
||
d.SetId(strconv.FormatInt(list.Payload.Results[0].ID, 10)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.