/
platform.go
141 lines (127 loc) · 3.34 KB
/
platform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package installconfig
import (
"fmt"
"sort"
survey "github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/core"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/bailey84j/terraform_installer/pkg/asset"
awsconfig "github.com/bailey84j/terraform_installer/pkg/asset/installconfig/aws"
//azureconfig "github.com/bailey84j/terraform_installer/pkg/asset/installconfig/azure"
"github.com/bailey84j/terraform_installer/pkg/types"
"github.com/bailey84j/terraform_installer/pkg/types/aws"
// "github.com/bailey84j/terraform_installer/pkg/types/azure"
)
// Platform is an asset that queries the user for the platform on which to install
// the cluster.
type platform struct {
types.Platform
}
var _ asset.Asset = (*platform)(nil)
// Dependencies returns no dependencies.
func (a *platform) Dependencies() []asset.Asset {
return []asset.Asset{}
}
// Generate queries for input from the user.
func (a *platform) Generate(asset.Parents) error {
platform, err := a.queryUserForPlatform()
if err != nil {
return err
}
switch platform {
/*case alibabacloud.Name:
a.AlibabaCloud, err = alibabacloudconfig.Platform()
if err != nil {
return err
}*/
case aws.Name:
logrus.Debugf("Trace Me - In Platform Switch - AWS...")
a.AWS, err = awsconfig.Platform()
if err != nil {
return err
}
/*case azure.Name:
a.Azure, err = azureconfig.Platform()
if err != nil {
return err
}*/
/*case baremetal.Name:
a.BareMetal, err = baremetalconfig.Platform()
if err != nil {
return err
}
case gcp.Name:
a.GCP, err = gcpconfig.Platform()
if err != nil {
return err
}
case ibmcloud.Name:
a.IBMCloud, err = ibmcloudconfig.Platform()
if err != nil {
return err
}
case libvirt.Name:
a.Libvirt, err = libvirtconfig.Platform()
if err != nil {
return err
}
case none.Name:
a.None = &none.Platform{}
case openstack.Name:
a.OpenStack, err = openstackconfig.Platform()
if err != nil {
return err
}
case ovirt.Name:
a.Ovirt, err = ovirtconfig.Platform()
if err != nil {
return err
}
case vsphere.Name:
a.VSphere, err = vsphereconfig.Platform()
if err != nil {
return err
}
case powervs.Name:
a.PowerVS, err = powervsconfig.Platform()
if err != nil {
return err
}
case nutanix.Name:
a.Nutanix, err = nutanixconfig.Platform()
if err != nil {
return err
}*/
default:
return fmt.Errorf("unknown platform type %q", platform)
}
return nil
}
// Name returns the human-friendly name of the asset.
func (a *platform) Name() string {
return "Platform"
}
func (a *platform) queryUserForPlatform() (platform string, err error) {
err = survey.Ask([]*survey.Question{
{
Prompt: &survey.Select{
Message: "Platform",
Options: types.PlatformNames,
Help: "The platform on which the cluster will run. For a full list of platforms, including those not supported by this wizard, see https://github.com/bailey84j/terraform_installer",
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(types.PlatformNames, choice)
if i == len(types.PlatformNames) || types.PlatformNames[i] != choice {
return errors.Errorf("invalid platform %q", choice)
}
return nil
}),
},
}, &platform)
return
}
func (a *platform) CurrentName() string {
return a.Platform.Name()
}