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

feat: add a resource for VRF BGP dynamic neighbors #746

Closed
wants to merge 4 commits into from
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
27 changes: 17 additions & 10 deletions docs/resources/metal_vrf.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,27 @@ resource "equinix_metal_virtual_circuit" "example" {
}
```

## Argument Reference
<!-- schema generated by tfplugindocs -->
## Schema

The following arguments are supported:
### Required

* `name` - (Required) User-supplied name of the VRF, unique to the project
* `metro` - (Required) Metro ID or Code where the VRF will be deployed.
* `project_id` - (Required) Project ID where the VRF will be deployed.
* `description` - (Optional) Description of the VRF.
* `local_asn` - (Optional) The 4-byte ASN set on the VRF.
* `ip_ranges` - (Optional) All IPv4 and IPv6 Ranges that will be available to BGP Peers. IPv4 addresses must be /8 or smaller with a minimum size of /29. IPv6 must be /56 or smaller with a minimum size of /64. Ranges must not overlap other ranges within the VRF.
- `metro` (String) Metro ID or Code where the VRF will be deployed
- `name` (String) User-supplied name of the VRF, unique to the project
- `project_id` (String) Project ID where the VRF will be deployed

## Attributes Reference
### Optional

No additional attributes are exported.
- `bgp_dynamic_neighbors_bfd_enabled` (Boolean) Toggle BFD on dynamic bgp neighbors sessions
- `bgp_dynamic_neighbors_enabled` (Boolean) Toggle to enable the dynamic bgp neighbors feature on the VRF
- `bgp_dynamic_neighbors_export_route_map` (Boolean) Toggle to export the VRF route-map to the dynamic bgp neighbors
- `description` (String) Description of the VRF
- `ip_ranges` (Set of String) All IPv4 and IPv6 Ranges that will be available to BGP Peers. IPv4 addresses must be /8 or smaller with a minimum size of /29. IPv6 must be /56 or smaller with a minimum size of /64. Ranges must not overlap other ranges within the VRF.
- `local_asn` (Number) The 4-byte ASN set on the VRF

### Read-Only

- `id` (String) The ID of this resource.

## Import

Expand Down
65 changes: 65 additions & 0 deletions docs/resources/metal_vrf_bgp_dynamic_neighbor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
subcategory: "Metal"
---

# equinix_metal_vrf_bgp_dynamic_neighbor (Resource)

This resource manages BGP dynamic neighbor ranges for an Equinix Metal VRF, but with markdown
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"but with markdown"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this comment thread


## Example Usage

```terraform
resource "equinix_metal_vlan" "example" {
description = "proj-vrf-bgp-neighbor-example VLAN in SV"
metro = "sv"
project_id = local.project_id
}

resource "equinix_metal_vrf" "example" {
description = "proj-vrf-bgp-neighbor-example VRF in SV"
name = "tfacc-vrf-example"
metro = "sv"
local_asn = "65000"
ip_ranges = ["2001:d78::/59"]
project_id = local.project_id
}

resource "equinix_metal_reserved_ip_block" "example" {
project_id = local.project_id
type = "vrf"
vrf_id = equinix_metal_vrf.example.id
network = "2001:d78::"
metro = "sv"
cidr = 64
}

resource "equinix_metal_gateway" "example" {
project_id = local.project_id
vlan_id = equinix_metal_vlan.example.id
ip_reservation_id = equinix_metal_reserved_ip_block.example.id
}

resource "equinix_metal_vrf_bgp_dynamic_neighbor" "example" {
gateway_id = equinix_metal_gateway.example.id
range = "2001:d78:0:0:4000::/66"
asn = "56789"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `asn` (Number) The ASN of the dynamic BGP neighbor
- `gateway_id` (String) The ID of the Equinix Metal VRF gateway for this dynamic BGP neighbor range
- `range` (String) Network range of the dynamic BGP neighbor in CIDR format

### Optional

- `tags` (List of String) Tags attached to the dynamic BGP neighbor

### Read-Only

- `id` (String) The unique identifier for this the dynamic BGP neighbor
- `state` (String) The state of the dynamic BGP neighbor
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
resource "equinix_metal_vlan" "example" {
description = "proj-vrf-bgp-neighbor-example VLAN in SV"
metro = "sv"
project_id = local.project_id
}

resource "equinix_metal_vrf" "example" {
description = "proj-vrf-bgp-neighbor-example VRF in SV"
name = "tfacc-vrf-example"
metro = "sv"
local_asn = "65000"
ip_ranges = ["2001:d78::/59"]
project_id = local.project_id
}

resource "equinix_metal_reserved_ip_block" "example" {
project_id = local.project_id
type = "vrf"
vrf_id = equinix_metal_vrf.example.id
network = "2001:d78::"
metro = "sv"
cidr = 64
}

resource "equinix_metal_gateway" "example" {
project_id = local.project_id
vlan_id = equinix_metal_vlan.example.id
ip_reservation_id = equinix_metal_reserved_ip_block.example.id
}

resource "equinix_metal_vrf_bgp_dynamic_neighbor" "example" {
gateway_id = equinix_metal_gateway.example.id
range = "2001:d78:0:0:4000::/66"
asn = "56789"
}
8 changes: 5 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
metalproject "github.com/equinix/terraform-provider-equinix/internal/resources/metal/project"
metalprojectsshkey "github.com/equinix/terraform-provider-equinix/internal/resources/metal/project_ssh_key"
metalsshkey "github.com/equinix/terraform-provider-equinix/internal/resources/metal/ssh_key"
"github.com/equinix/terraform-provider-equinix/internal/resources/metal/vlan"
metalvlan "github.com/equinix/terraform-provider-equinix/internal/resources/metal/vlan"
metalvrfbgpdynamicneighbor "github.com/equinix/terraform-provider-equinix/internal/resources/metal/vrf_bgp_dynamic_neighbor"
equinix_validation "github.com/equinix/terraform-provider-equinix/internal/validation"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand Down Expand Up @@ -121,7 +122,8 @@ func (p *FrameworkProvider) Resources(ctx context.Context) []func() resource.Res
metalconnection.NewResource,
metalorganization.NewResource,
metalorganizationmember.NewResource,
vlan.NewResource,
metalvlan.NewResource,
metalvrfbgpdynamicneighbor.NewResource,
}
}

Expand All @@ -132,6 +134,6 @@ func (p *FrameworkProvider) DataSources(ctx context.Context) []func() datasource
metalprojectsshkey.NewDataSource,
metalconnection.NewDataSource,
metalorganization.NewDataSource,
vlan.NewDataSource,
metalvlan.NewDataSource,
}
}
28 changes: 28 additions & 0 deletions internal/resources/metal/vrf/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@ func DataSource() *schema.Resource {
Computed: true,
Description: "Project ID",
},
"bgp_dynamic_neighbors": {
Type: schema.TypeList,
Description: "BGP dynamic neighbor settings for this VRF",
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Toggle to enable the dynamic bgp neighbors feature on the VRF",
},
"export_route_map": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Toggle to export the VRF route-map to the dynamic bgp neighbors",
},
"bfd_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Toggle BFD on dynamic bgp neighbors sessions",
},
},
},
},
},
}
}
Expand Down
59 changes: 50 additions & 9 deletions internal/resources/metal/vrf/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ func Resource() *schema.Resource {
"metro": {
Type: schema.TypeString,
Required: true,
Description: "Metro Code",
ForceNew: true,
Description: "Metro ID or Code where the VRF will be deployed",
},
"local_asn": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The 4-byte ASN set on the VRF.",
Description: "The 4-byte ASN set on the VRF",
},
"ip_ranges": {
Type: schema.TypeSet,
Expand All @@ -55,7 +56,26 @@ func Resource() *schema.Resource {
"project_id": {
Type: schema.TypeString,
Required: true,
Description: "Project ID",
ForceNew: true,
Description: "Project ID where the VRF will be deployed",
},
"bgp_dynamic_neighbors_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Toggle to enable the dynamic bgp neighbors feature on the VRF",
},
"bgp_dynamic_neighbors_export_route_map": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Toggle to export the VRF route-map to the dynamic bgp neighbors",
},
"bgp_dynamic_neighbors_bfd_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Toggle BFD on dynamic bgp neighbors sessions",
},
// TODO: created_by, created_at, updated_at, href
},
Expand All @@ -75,6 +95,15 @@ func resourceMetalVRFCreate(ctx context.Context, d *schema.ResourceData, meta in
if value, ok := d.GetOk("local_asn"); ok {
createRequest.LocalAsn = metalv1.PtrInt64(int64(value.(int)))
}
if value, ok := d.GetOk("bgp_dynamic_neighbors_enabled"); ok {
createRequest.SetBgpDynamicNeighborsEnabled(value.(bool))
}
if value, ok := d.GetOk("bgp_dynamic_neighbors_export_route_map"); ok {
createRequest.SetBgpDynamicNeighborsExportRouteMap(value.(bool))
}
if value, ok := d.GetOk("bgp_dynamic_neighbors_bfd_enabled"); ok {
createRequest.SetBgpDynamicNeighborsBfdEnabled(value.(bool))
}

projectId := d.Get("project_id").(string)
vrf, _, err := client.VRFsApi.
Expand Down Expand Up @@ -107,6 +136,15 @@ func resourceMetalVRFUpdate(ctx context.Context, d *schema.ResourceData, meta in
ipRanges := converters.SetToStringList(d.Get("ip_ranges").(*schema.Set))
updateRequest.SetIpRanges(ipRanges)
}
if d.HasChange("bgp_dynamic_neighbors_enabled") {
updateRequest.SetBgpDynamicNeighborsEnabled(d.Get("bgp_dynamic_neighbors_enabled").(bool))
}
if d.HasChange("bgp_dynamic_neighbors_export_route_map") {
updateRequest.SetBgpDynamicNeighborsExportRouteMap(d.Get("bgp_dynamic_neighbors_export_route_map").(bool))
}
if d.HasChange("bgp_dynamic_neighbors_bfd_enabled") {
updateRequest.SetBgpDynamicNeighborsBfdEnabled(d.Get("bgp_dynamic_neighbors_bfd_enabled").(bool))
}

_, _, err := client.VRFsApi.
UpdateVrf(ctx, d.Id()).
Expand Down Expand Up @@ -136,12 +174,15 @@ func resourceMetalVRFRead(ctx context.Context, d *schema.ResourceData, meta inte
return diag.FromErr(err)
}
m := map[string]interface{}{
"name": vrf.GetName(),
"description": vrf.GetDescription(),
"metro": vrf.Metro.GetCode(),
"local_asn": vrf.GetLocalAsn(),
"ip_ranges": vrf.GetIpRanges(),
"project_id": vrf.Project.GetId(),
"name": vrf.GetName(),
"description": vrf.GetDescription(),
"metro": vrf.Metro.GetCode(),
"local_asn": vrf.GetLocalAsn(),
"ip_ranges": vrf.GetIpRanges(),
"project_id": vrf.Project.GetId(),
"bgp_dynamic_neighbors_enabled": vrf.GetBgpDynamicNeighborsEnabled(),
"bgp_dynamic_neighbors_export_route_map": vrf.GetBgpDynamicNeighborsExportRouteMap(),
"bgp_dynamic_neighbors_bfd_enabled": vrf.GetBgpDynamicNeighborsBfdEnabled(),
}

return diag.FromErr(equinix_schema.SetMap(d, m))
Expand Down
Loading
Loading