Skip to content

Commit

Permalink
fix: Updating fabric network schema resources & data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
srushti-patl committed Jan 31, 2024
1 parent 427b127 commit b8f3994
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 330 deletions.
21 changes: 19 additions & 2 deletions equinix/data_source_fabric_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@ import (
"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: readNetworkResourceSchema(),
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 resourceNetworkRead(ctx, d, meta)
return resourceFabricNetworkRead(ctx, d, meta)
}
52 changes: 0 additions & 52 deletions equinix/fabric_mapping_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,25 +437,6 @@ func operationToTerra(operation *v4.ConnectionOperation) *schema.Set {
return operationSet
}

func networkOperationToTerra(operation *v4.NetworkOperation) *schema.Set {
if operation == nil {
return nil
}
operations := []*v4.NetworkOperation{operation}
mappedOperations := make([]interface{}, len(operations))
for _, operation := range operations {
mappedOperation := make(map[string]interface{})
mappedOperation["equinix_status"] = string(*operation.EquinixStatus)
mappedOperations = append(mappedOperations, mappedOperation)
}

operationSet := schema.NewSet(
schema.HashResource(createNetworkOperationSchRes),
mappedOperations,
)
return operationSet
}

func orderMappingToTerra(order *v4.Order) *schema.Set {
if order == nil {
return nil
Expand Down Expand Up @@ -840,24 +821,6 @@ func simplifiedServiceProfileToTerra(profile *v4.SimplifiedServiceProfile) *sche
return profileSet
}

func simplifiedNetworkChangeToTerra(networkChange *v4.SimplifiedNetworkChange) *schema.Set {
changes := []*v4.SimplifiedNetworkChange{networkChange}
mappedChanges := make([]interface{}, len(changes))
for _, change := range changes {
mappedChange := make(map[string]interface{})
mappedChange["href"] = change.Href
mappedChange["type"] = string(*change.Type_)
mappedChange["uuid"] = change.Uuid
mappedChanges = append(mappedChanges, mappedChange)
}

changeSet := schema.NewSet(
schema.HashResource(createNetworkChangeRes),
mappedChanges,
)
return changeSet
}

func accessPointTypeConfigToTerra(spAccessPointTypes []v4.ServiceProfileAccessPointType) []interface{} {
mappedSpAccessPointTypes := make([]interface{}, len(spAccessPointTypes))
for index, spAccessPointType := range spAccessPointTypes {
Expand Down Expand Up @@ -1294,18 +1257,3 @@ func getCloudRouterUpdateRequest(conn v4.CloudRouter, d *schema.ResourceData) (v
}
return changeOps, nil
}

func getNetworkUpdateRequest(network v4.Network, d *schema.ResourceData) (v4.NetworkChangeOperation, error) {
changeOps := v4.NetworkChangeOperation{}
existingName := network.Name
updateNameVal := d.Get("name")

log.Printf("existing name %s, Update Name Request %s ", existingName, updateNameVal)

if existingName != updateNameVal {
changeOps = v4.NetworkChangeOperation{Op: "replace", Path: "/name", Value: &updateNameVal}
} else {
return changeOps, fmt.Errorf("nothing to update for the Fabric Network: %s", existingName)
}
return changeOps, nil
}
105 changes: 0 additions & 105 deletions equinix/fabric_network_read_schema.go

This file was deleted.

148 changes: 0 additions & 148 deletions equinix/fabric_network_schema.go

This file was deleted.

Loading

0 comments on commit b8f3994

Please sign in to comment.