Skip to content

Commit

Permalink
fix suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
jokestax committed Dec 31, 2024
1 parent 181d4d6 commit 1eea540
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 180 deletions.
14 changes: 8 additions & 6 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ func ValidateProvidedFlags(ctx context.Context, cfg aws.Config, gitProvider, ami
log.Info().Msgf("%q %s", "gitlab.com", key.Type())
}

if err := ValidateAMIType(ctx, cfg, amiType, nodeType); err != nil {
ssmClient := ssm.NewFromConfig(cfg)
ec2Client := ec2.NewFromConfig(cfg)
paginator := ec2.NewDescribeInstanceTypesPaginator(ec2Client, &ec2.DescribeInstanceTypesInput{})

if err := ValidateAMIType(ctx, amiType, nodeType, ssmClient, ec2Client, paginator); err != nil {
progress.Error(err.Error())
return fmt.Errorf("failed to validte ami type for node group: %w", err)
}
Expand All @@ -186,18 +190,14 @@ func getSessionCredentials(ctx context.Context, cfg aws.CredentialsProvider) (*a
return &creds, nil
}

func ValidateAMIType(ctx context.Context, cfg aws.Config, amiType, nodeType string) error {
func ValidateAMIType(ctx context.Context, amiType, nodeType string, ssmClient ssmClienter, ec2Client ec2Clienter, paginator paginater) error {
ssmParameterName, ok := ssmTypesID[amiType]
if !ok {
return fmt.Errorf("not a valid ami type: %q", amiType)
}

log.Info().Msgf("ami type is %s", amiType)

ssmClient := ssm.NewFromConfig(cfg)
ec2Client := ec2.NewFromConfig(cfg)
paginator := ec2.NewDescribeInstanceTypesPaginator(ec2Client, &ec2.DescribeInstanceTypesInput{})

amiID, err := GetLatestAMIFromSSM(ctx, ssmClient, ssmParameterName)
if err != nil {
return fmt.Errorf("failed to get AMI ID from SSM: %w", err)
Expand All @@ -213,6 +213,8 @@ func ValidateAMIType(ctx context.Context, cfg aws.Config, amiType, nodeType stri
return fmt.Errorf("failed to get supported instance types: %w", err)
}

fmt.Println("Supported instance types: ", instanceTypes)

for _, instanceType := range instanceTypes {
if instanceType == nodeType {
return nil
Expand Down
Loading

0 comments on commit 1eea540

Please sign in to comment.