Skip to content

Commit

Permalink
Extract resourceAttributePrivatePublic schema
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Oct 30, 2019
1 parent 2fd2c0a commit 10190a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
21 changes: 21 additions & 0 deletions megaport/common.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package megaport

import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/utilitywarehouse/terraform-provider-megaport/megaport/api"
)

func resourceAttributePrivatePublic() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "private",
StateFunc: func(v interface{}) string {
return strings.ToLower(v.(string))
},
ValidateFunc: func(v interface{}, k string) (warns []string, errs []error) {
vv := strings.ToLower(v.(string))
if vv != "public" && vv != "private" {
errs = append(errs, fmt.Errorf("%s must be either 'public' or 'private', got %s", k, vv))
}
return
},
}
}

func resourceMegaportVxcEndElem() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
18 changes: 1 addition & 17 deletions megaport/resource_megaport_port.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package megaport

import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/utilitywarehouse/terraform-provider-megaport/megaport/api"
Expand Down Expand Up @@ -49,21 +47,7 @@ func resourceMegaportPort() *schema.Resource {
Elem: resourceMegaportPrivateVxc(),
Set: schema.HashResource(resourceMegaportPrivateVxc()),
},
"marketplace_visibility": {
Type: schema.TypeString,
Optional: true,
Default: "private",
StateFunc: func(v interface{}) string {
return strings.ToLower(v.(string))
},
ValidateFunc: func(v interface{}, k string) (warns []string, errs []error) {
vv := strings.ToLower(v.(string))
if vv != "public" && vv != "private" {
errs = append(errs, fmt.Errorf("%s must be either 'public' or 'private', got %s", k, vv))
}
return
},
},
"marketplace_visibility": resourceAttributePrivatePublic(),
// TODO: LAG ports
},
}
Expand Down

0 comments on commit 10190a1

Please sign in to comment.