diff --git a/internal/interconnections/create.go b/internal/interconnections/create.go index 2b4b9c5b..0b20252c 100644 --- a/internal/interconnections/create.go +++ b/internal/interconnections/create.go @@ -28,20 +28,16 @@ func (c *Client) Create() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { cmd.SilenceUsage = true - if projectID == "" && organizationID == "" { - return errors.New("could you provide at least either of projectID OR organizationID") - } - - if vlanFabricVcCreate(vlans) || vrfsFabricVcCreate(vrfs) && svcTokenType == "" { - return errors.New("flag 'service-token-type' is required for vlan or vrfs fabric VC create") - } - var interconn *metal.Interconnection var err error + if err := validInputArgs(projectID, organizationID, vlans, vrfs, svcTokenType); err != nil { + return err + } + createOrganizationInterconnectionRequest := metal.CreateOrganizationInterconnectionRequest{} - switch true { + switch { case vlanFabricVcCreate(vlans): in := metal.NewVlanFabricVcCreateInput( metro, name, redundancy, metal.VlanFabricVcCreateInputServiceTokenType(svcTokenType), @@ -131,3 +127,19 @@ func (c *Client) handleCreate(projectID, organizationID string, Execute() return interconn, err } + +func validInputArgs(projectID, organizationID string, vlans []int32, vrfs []string, svcTokenType string) error { + if projectID == "" && organizationID == "" { + return errors.New("could you provide at least either of projectID OR organizationID") + } + + if vlanFabricVcCreate(vlans) || vrfsFabricVcCreate(vrfs) && svcTokenType == "" { + return errors.New("flag 'service-token-type' is required for vlan or vrfs fabric VC create") + } + + if vlanFabricVcCreate(vlans) && vrfsFabricVcCreate(vrfs) { + return errors.New("vLans and vrfs both are provided. Please provide any one type of interconnection") + } + + return nil +}