|
5 | 5 | "fmt" |
6 | 6 | "os" |
7 | 7 | "os/exec" |
8 | | - "sort" |
9 | 8 | "strings" |
10 | 9 |
|
11 | 10 | "github.com/AlecAivazis/survey/v2" |
@@ -113,32 +112,21 @@ func mkAWS(conf config.Config) (provider *AWSProvider, err error) { |
113 | 112 | return |
114 | 113 | } |
115 | 114 |
|
116 | | - account, err := GetAwsAccount(ctx) |
117 | | - if err != nil { |
118 | | - err = plrlErrors.ErrorWrap(err, "Failed to get aws account (is your aws cli configured?)") |
119 | | - return |
120 | | - } |
121 | | - |
122 | | - if len(account) == 0 { |
| 115 | + provider.project = lo.FromPtr(callerIdentity.Account) |
| 116 | + if len(provider.project) == 0 { |
123 | 117 | err = plrlErrors.ErrorWrap(fmt.Errorf("unable to find AWS account ID, make sure that your AWS CLI is configured"), "AWS cli error:") |
124 | 118 | return |
125 | 119 | } |
126 | 120 |
|
127 | | - provider.project = account |
128 | 121 | provider.storageClient = client |
129 | 122 |
|
130 | | - azones, err := getAvailabilityZones(ctx, provider.Region()) |
131 | | - if err != nil { |
132 | | - return |
133 | | - } |
134 | | - |
135 | 123 | projectManifest := manifest.ProjectManifest{ |
136 | 124 | Cluster: provider.Cluster(), |
137 | 125 | Project: provider.Project(), |
138 | 126 | Provider: api.ProviderAWS, |
139 | 127 | Region: provider.Region(), |
140 | 128 | Context: provider.Context(), |
141 | | - AvailabilityZones: azones, |
| 129 | + AvailabilityZones: []string{}, |
142 | 130 | Owner: &manifest.Owner{Email: conf.Email, Endpoint: conf.Endpoint}, |
143 | 131 | } |
144 | 132 |
|
@@ -167,56 +155,6 @@ func getClient(region string, context context.Context) (*s3.Client, error) { |
167 | 155 | return s3.NewFromConfig(cfg), nil |
168 | 156 | } |
169 | 157 |
|
170 | | -func getEC2Client(ctx context.Context, region string) (*ec2.Client, error) { |
171 | | - cfg, err := awsConfig.LoadDefaultConfig(ctx) |
172 | | - if err != nil { |
173 | | - return nil, err |
174 | | - } |
175 | | - cfg.Region = region |
176 | | - return ec2.NewFromConfig(cfg), nil |
177 | | -} |
178 | | - |
179 | | -func getAvailabilityZones(ctx context.Context, region string) ([]string, error) { |
180 | | - return fetchAZ(ctx, region, true) |
181 | | -} |
182 | | - |
183 | | -func fetchAZ(context context.Context, region string, sorted bool) ([]string, error) { |
184 | | - ec2Client, err := getEC2Client(context, region) |
185 | | - if err != nil { |
186 | | - return nil, err |
187 | | - } |
188 | | - allAvailabilityZones := true |
189 | | - dryRun := false |
190 | | - regionName := "region-name" |
191 | | - azones, err := ec2Client.DescribeAvailabilityZones(context, &ec2.DescribeAvailabilityZonesInput{ |
192 | | - AllAvailabilityZones: &allAvailabilityZones, |
193 | | - DryRun: &dryRun, |
194 | | - Filters: []ec2Types.Filter{ |
195 | | - { |
196 | | - Name: ®ionName, |
197 | | - Values: []string{region}, |
198 | | - }, |
199 | | - }, |
200 | | - }) |
201 | | - if err != nil { |
202 | | - return nil, err |
203 | | - } |
204 | | - result := []string{} |
205 | | - for _, az := range azones.AvailabilityZones { |
206 | | - if az.ParentZoneId == nil { |
207 | | - result = append(result, *az.ZoneName) |
208 | | - } |
209 | | - } |
210 | | - // append when there are fewer zones than 3 |
211 | | - for i := 0; (3 - len(result)) > 0; i++ { |
212 | | - result = append(result, result[i]) |
213 | | - } |
214 | | - if sorted { |
215 | | - sort.Strings(result) |
216 | | - } |
217 | | - return result, nil |
218 | | -} |
219 | | - |
220 | 158 | func getAwsConfig(ctx context.Context) (aws.Config, error) { |
221 | 159 | cfg, err := awsConfig.LoadDefaultConfig(ctx) |
222 | 160 | return cfg, plrlErrors.ErrorWrap(err, "Failed to initialize aws client: ") |
@@ -334,20 +272,6 @@ func (prov *AWSProvider) Decommision(node *v1.Node) error { |
334 | 272 | return plrlErrors.ErrorWrap(err, "failed to terminate instance") |
335 | 273 | } |
336 | 274 |
|
337 | | -func GetAwsAccount(ctx context.Context) (string, error) { |
338 | | - cfg, err := getAwsConfig(ctx) |
339 | | - if err != nil { |
340 | | - return "", err |
341 | | - } |
342 | | - svc := sts.NewFromConfig(cfg) |
343 | | - result, err := svc.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{}) |
344 | | - if err != nil { |
345 | | - return "", plrlErrors.ErrorWrap(err, "Error finding iam identity: ") |
346 | | - } |
347 | | - |
348 | | - return *result.Account, nil |
349 | | -} |
350 | | - |
351 | 275 | func ValidateAWSDomainRegistration(ctx context.Context, domain, region string) error { |
352 | 276 | cfg, err := getAwsConfig(ctx) |
353 | 277 | if err != nil { |
|
0 commit comments