diff --git a/pkg/ctl/create/cluster.go b/pkg/ctl/create/cluster.go index 8d7a842c0f..b71032c1c8 100644 --- a/pkg/ctl/create/cluster.go +++ b/pkg/ctl/create/cluster.go @@ -3,6 +3,7 @@ package create import ( "fmt" "os" + "strings" "github.com/kubicorn/kubicorn/pkg/logger" "github.com/pkg/errors" @@ -101,9 +102,10 @@ func createClusterCmd() *cobra.Command { func doCreateCluster(cfg *api.ClusterConfig, ng *api.NodeGroup, name string) error { ctl := eks.New(cfg) - if cfg.Region != api.EKSRegionUSWest2 && cfg.Region != api.EKSRegionUSEast1 && cfg.Region != api.EKSRegionEUWest1 { - return fmt.Errorf("%s is not supported only %s, %s and %s are supported", cfg.Region, api.EKSRegionUSWest2, api.EKSRegionUSEast1, api.EKSRegionEUWest1) + if !cfg.IsSupportedRegion() { + return fmt.Errorf("--region=%s is not supported - use one of: %s", cfg.Region, strings.Join(api.SupportedRegions(), ", ")) } + logger.Info("using region %s", cfg.Region) if err := ctl.CheckAuth(); err != nil { return err diff --git a/pkg/eks/api.go b/pkg/eks/api.go index ab3eb6347f..117f60d952 100644 --- a/pkg/eks/api.go +++ b/pkg/eks/api.go @@ -248,7 +248,6 @@ func newSession(clusterConfig *api.ClusterConfig, endpoint string, credentials * } } - logger.Info("using region %s", clusterConfig.Region) return s } diff --git a/pkg/eks/api/api.go b/pkg/eks/api/api.go index d671e14839..58e43fb847 100644 --- a/pkg/eks/api/api.go +++ b/pkg/eks/api/api.go @@ -27,10 +27,12 @@ const ( ) // SupportedRegions are the regions where EKS is available -var SupportedRegions = []string{ - EKSRegionUSWest2, - EKSRegionUSEast1, - EKSRegionEUWest1, +func SupportedRegions() []string { + return []string{ + EKSRegionUSWest2, + EKSRegionUSEast1, + EKSRegionEUWest1, + } } // DefaultWaitTimeout defines the default wait timeout @@ -85,6 +87,16 @@ func NewClusterConfig() *ClusterConfig { return cfg } +// IsSupportedRegion check if given region is supported +func (c *ClusterConfig) IsSupportedRegion() bool { + for _, supportedRegion := range SupportedRegions() { + if c.Region == supportedRegion { + return true + } + } + return false +} + // NewNodeGroup crears new nodegroup inside cluster config, // it returns pointer to the nodegroup for convenience func (c *ClusterConfig) NewNodeGroup() *NodeGroup {