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 equinix_fabric_network terraform provider #482

Closed
39 changes: 39 additions & 0 deletions equinix/data_source_fabric_network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package equinix

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func readFabricNetworkResourceSchema() map[string]*schema.Schema {
sch := FabricNetworkResourceSchema()
for key, _ := range sch {
if key == "uuid" {
sch[key].Required = true
sch[key].Optional = false
sch[key].Computed = false
} else {
sch[key].Required = false
sch[key].Optional = false
sch[key].Computed = true
sch[key].MaxItems = 0
sch[key].ValidateFunc = nil
}
}
return sch
}
func dataSourceNetwork() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceNetworkRead,
Schema: readFabricNetworkResourceSchema(),
Description: "Fabric V4 API compatible data resource that allow user to fetch Fabric Network for a given UUID\n\n~> **Note** Equinix Fabric v4 resources and datasources are currently in Beta. The interfaces related to `equinix_fabric_` resources and datasources may change ahead of general availability. Please, do not hesitate to report any problems that you experience by opening a new [issue](https://github.com/equinix/terraform-provider-equinix/issues/new?template=bug.md)",
}
}

func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
uuid, _ := d.Get("uuid").(string)
d.SetId(uuid)
return resourceFabricNetworkRead(ctx, d, meta)
}
16 changes: 9 additions & 7 deletions equinix/fabric_mapping_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package equinix

import (
"fmt"
"log"

v4 "github.com/equinix-labs/fabric-go/fabric/v4"
"github.com/equinix/terraform-provider-equinix/internal/converters"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
)

func serviceTokenToFabric(serviceTokenRequest []interface{}) (v4.ServiceToken, error) {
Expand Down Expand Up @@ -538,14 +537,17 @@ func notificationToTerra(notifications []v4.SimplifiedNotification) []map[string
}

func locationToTerra(location *v4.SimplifiedLocation) *schema.Set {
if location == nil {
return nil
}
locations := []*v4.SimplifiedLocation{location}
mappedLocations := make([]interface{}, len(locations))
for i, location := range locations {
for i, loc := range locations {
mappedLocations[i] = map[string]interface{}{
"region": location.Region,
"metro_name": location.MetroName,
"metro_code": location.MetroCode,
"ibx": location.Ibx,
"region": loc.Region,
"metro_name": loc.MetroName,
"metro_code": loc.MetroCode,
"ibx": loc.Ibx,
}
}
locationSet := schema.NewSet(
Expand Down
2 changes: 2 additions & 0 deletions equinix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func Provider() *schema.Provider {
"equinix_fabric_routing_protocol": dataSourceRoutingProtocol(),
"equinix_fabric_connection": dataSourceFabricConnection(),
"equinix_fabric_cloud_router": dataSourceCloudRouter(),
"equinix_fabric_network": dataSourceNetwork(),
"equinix_fabric_port": dataSourceFabricPort(),
"equinix_fabric_ports": dataSourceFabricGetPortsByName(),
"equinix_fabric_service_profile": dataSourceFabricServiceProfileReadByUuid(),
Expand Down Expand Up @@ -120,6 +121,7 @@ func Provider() *schema.Provider {
"equinix_ecx_l2_connection_accepter": resourceECXL2ConnectionAccepter(),
"equinix_ecx_l2_serviceprofile": resourceECXL2ServiceProfile(),
"equinix_fabric_cloud_router": resourceCloudRouter(),
"equinix_fabric_network": resourceNetwork(),
"equinix_fabric_connection": resourceFabricConnection(),
"equinix_fabric_routing_protocol": resourceFabricRoutingProtocol(),
"equinix_fabric_service_profile": resourceFabricServiceProfile(),
Expand Down
Loading
Loading