-
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
695 additions
and
5 deletions.
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,3 @@ | ||
data "netbox_ipam_vrf" "vrf_test" { | ||
vrf_id = 15 | ||
} |
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,2 @@ | ||
# VRFs can be imported by id | ||
terraform import netbox_ipam_vrf.vrf_test 1 |
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,88 @@ | ||
resource "netbox_ipam_vrf" "vrf_test" { | ||
name = "Test VRF" | ||
enforce_unique = false | ||
export_targets = [ netbox_ipam_route_targets.rt_export_test.id ] | ||
import_targets = [ netbox_ipam_route_targets.rt_import_test.id ] | ||
rd = "test-vrf" | ||
description = "Test VRF" | ||
comments = <<-EOT | ||
Test Vrf | ||
EOT | ||
|
||
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 = "select" | ||
value = "1" | ||
} | ||
|
||
custom_field { | ||
name = "cf_url" | ||
type = "url" | ||
value = "https://github.com" | ||
} | ||
|
||
custom_field { | ||
name = "cf_multi_selection" | ||
type = "multiselect" | ||
value = jsonencode([ | ||
"0", | ||
"1" | ||
]) | ||
} | ||
|
||
custom_field { | ||
name = "cf_json" | ||
type = "json" | ||
value = jsonencode({ | ||
stringvalue = "string" | ||
boolvalue = false | ||
dictionary = { | ||
numbervalue = 5 | ||
} | ||
}) | ||
} | ||
|
||
custom_field { | ||
name = "cf_object" | ||
type = "object" | ||
value = 1 | ||
} | ||
|
||
custom_field { | ||
name = "cf_multi_object" | ||
type = "multiobject" | ||
value = jsonencode([ | ||
1, | ||
2 | ||
]) | ||
} | ||
} |
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,62 @@ | ||
package ipam | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
netboxclient "github.com/smutel/go-netbox/v3/netbox/client" | ||
"github.com/smutel/go-netbox/v3/netbox/client/ipam" | ||
"github.com/smutel/terraform-provider-netbox/v7/netbox/internal/util" | ||
) | ||
|
||
func DataNetboxIpamVrf() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Get info about vrf (ipam module) from netbox.", | ||
ReadContext: dataNetboxIpamVrfRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"content_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The content type of this vrf (ipam module).", | ||
}, | ||
"vrf_id": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "The ID of the vrf (ipam module).", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataNetboxIpamVrfRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
client := m.(*netboxclient.NetBoxAPI) | ||
|
||
id := int64(d.Get("vrf_id").(int)) | ||
idStr := strconv.FormatInt(id, 10) | ||
|
||
p := ipam.NewIpamVrfsListParams().WithID(&idStr) | ||
|
||
list, err := client.Ipam.IpamVrfsList(p, nil) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if *list.Payload.Count < 1 { | ||
return diag.Errorf("Your query returned no results. " + | ||
"Please change your search criteria and try again.") | ||
} else if *list.Payload.Count > 1 { | ||
return diag.Errorf("Your query returned more than one result. " + | ||
"Please try a more specific search criteria.") | ||
} | ||
|
||
r := list.Payload.Results[0] | ||
d.SetId(strconv.FormatInt(r.ID, 10)) | ||
if err = d.Set("content_type", util.ConvertURIContentType(r.URL)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
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
Oops, something went wrong.