Skip to content

Commit bad0ac7

Browse files
authored
docs: updated scope to use enumeration values in description (#894)
Updated scope to use enumeration values in description along with a note for REGIONAL extra steps
2 parents d2365c6 + d4951ca commit bad0ac7

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

docs/data-sources/fabric_network.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ output "region" {
5757
- `notifications` (List of Object) Preferences for notifications on Fabric Network configuration or status changes (see [below for nested schema](#nestedatt--notifications))
5858
- `operation` (Set of Object) Network operation information that is associated with this Fabric Network (see [below for nested schema](#nestedatt--operation))
5959
- `project` (Set of Object) Fabric Network project (see [below for nested schema](#nestedatt--project))
60-
- `scope` (String) Fabric Network scope
60+
- `scope` (String) Fabric Network scope. Valid values: [REGIONAL GLOBAL LOCAL]. Note: When scope is REGIONAL, the location.region field is required.
6161
- `state` (String) Fabric Network overall state
6262
- `type` (String) Supported Network types - EVPLAN, EPLAN, IPWAN, EVPTREE, EPTREE
6363

docs/resources/fabric_network.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ resource "equinix_fabric_network" "new_network" {
3535
- `name` (String) Fabric Network name. An alpha-numeric 24 characters string which can include only hyphens and underscores
3636
- `notifications` (Block List, Min: 1) Preferences for notifications on Fabric Network configuration or status changes (see [below for nested schema](#nestedblock--notifications))
3737
- `project` (Block Set, Min: 1) Fabric Network project (see [below for nested schema](#nestedblock--project))
38-
- `scope` (String) Fabric Network scope
38+
- `scope` (String) Fabric Network scope. Valid values: [REGIONAL GLOBAL LOCAL]. Note: When scope is REGIONAL, the location.region field is required.
3939
- `type` (String) Supported Network types - EVPLAN, EPLAN, IPWAN, EVPTREE, EPTREE
4040

4141
### Optional

internal/converters/converters.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package converters contains functions to convert between different data types and formats.
12
package converters
23

34
import (
@@ -8,6 +9,7 @@ import (
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
)
1011

12+
// StringArrToIfArr converts a slice of strings to a slice of any
1113
func StringArrToIfArr(sli []string) []interface{} {
1214
var arr []interface{}
1315
for _, v := range sli {
@@ -16,6 +18,7 @@ func StringArrToIfArr(sli []string) []interface{} {
1618
return arr
1719
}
1820

21+
// IfArrToStringArr converts a slice of any to a slice of strings
1922
func IfArrToStringArr(ifaceArr []interface{}) []string {
2023
arr := make([]string, len(ifaceArr))
2124
for i, v := range ifaceArr {
@@ -24,6 +27,7 @@ func IfArrToStringArr(ifaceArr []interface{}) []string {
2427
return arr
2528
}
2629

30+
// IfArrToIntStringArr converts a slice of any to a slice of strings, where each element is an int
2731
func IfArrToIntStringArr(ifaceArr []interface{}) []string {
2832
var arr []string
2933
for _, v := range ifaceArr {
@@ -35,6 +39,7 @@ func IfArrToIntStringArr(ifaceArr []interface{}) []string {
3539
return arr
3640
}
3741

42+
// IfArrToIntArr converts a slice of any to a slice of ints
3843
func IfArrToIntArr(ifaceArr []interface{}) []int {
3944
var arr []int
4045
for _, v := range ifaceArr {
@@ -46,10 +51,12 @@ func IfArrToIntArr(ifaceArr []interface{}) []int {
4651
return arr
4752
}
4853

54+
// ToLowerIf converts an any to a string and converts it to lowercase
4955
func ToLowerIf(v interface{}) string {
5056
return strings.ToLower(v.(string))
5157
}
5258

59+
// Difference returns the difference between two slices of strings.
5360
// from https://stackoverflow.com/a/45428032
5461
func Difference(a, b []string) []string {
5562
mb := make(map[string]struct{}, len(b))
@@ -65,6 +72,7 @@ func Difference(a, b []string) []string {
6572
return diff
6673
}
6774

75+
// ListToInt32List converts a slice of any to a slice of int32
6876
func ListToInt32List(list []interface{}) []int32 {
6977
result := make([]int32, len(list))
7078
for i, v := range list {
@@ -73,15 +81,26 @@ func ListToInt32List(list []interface{}) []int32 {
7381
return result
7482
}
7583

84+
// SetToStringList converts a schema.Set to a slice of strings
7685
func SetToStringList(set *schema.Set) []string {
7786
list := set.List()
7887
return IfArrToStringArr(list)
7988
}
8089

90+
// InterfaceMapToStringMap converts a string map of any values to a string map of strings
8191
func InterfaceMapToStringMap(mapIn map[string]interface{}) map[string]string {
8292
mapOut := make(map[string]string)
8393
for k, v := range mapIn {
8494
mapOut[k] = fmt.Sprintf("%v", v)
8595
}
8696
return mapOut
8797
}
98+
99+
// EnumArrayToStringArray converts a slice of string-like enums to a slice of strings
100+
func EnumArrayToStringArray[T ~string, S []T](list S) []string {
101+
arr := make([]string, len(list))
102+
for i, v := range list {
103+
arr[i] = string(v)
104+
}
105+
return arr
106+
}

internal/resources/fabric/network/resource_schema.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package network
22

33
import (
4+
"fmt"
5+
6+
"github.com/equinix/equinix-sdk-go/services/fabricv4"
7+
"github.com/equinix/terraform-provider-equinix/internal/converters"
48
equinix_fabric_schema "github.com/equinix/terraform-provider-equinix/internal/fabric/schema"
59

610
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -68,9 +72,15 @@ func fabricNetworkResourceSchema() map[string]*schema.Schema {
6872
Description: "Fabric Network overall state",
6973
},
7074
"scope": {
71-
Type: schema.TypeString,
72-
Required: true,
73-
Description: "Fabric Network scope",
75+
Type: schema.TypeString,
76+
Required: true,
77+
ValidateFunc: validation.StringInSlice(
78+
converters.EnumArrayToStringArray(fabricv4.AllowedNetworkScopeEnumValues),
79+
true,
80+
),
81+
Description: fmt.Sprintf("Fabric Network scope. Valid values: %v. Note: When scope is REGIONAL, the location.region field is required.",
82+
fabricv4.AllowedNetworkScopeEnumValues,
83+
),
7484
},
7585
"type": {
7686
Type: schema.TypeString,

0 commit comments

Comments
 (0)