Skip to content

Commit ce75ff8

Browse files
Fix lint issues
1 parent eccc58e commit ce75ff8

24 files changed

Lines changed: 380 additions & 358 deletions

cmd/create/hecate_terraform.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -404,102 +404,108 @@ type HecateConfig struct {
404404

405405
func generateHecateTerraform(rc *eos_io.RuntimeContext, cmd *cobra.Command) error {
406406
logger := otelzap.Ctx(rc.Ctx)
407-
407+
408408
if err := terraform.CheckTerraformInstalled(); err != nil {
409409
return fmt.Errorf("terraform is required but not installed. Run 'eos create terraform' first: %w", err)
410410
}
411-
411+
412412
outputDir, _ := cmd.Flags().GetString("output-dir")
413413
useCloud, _ := cmd.Flags().GetBool("cloud")
414414
serverType, _ := cmd.Flags().GetString("server-type")
415415
location, _ := cmd.Flags().GetString("location")
416416
domain, _ := cmd.Flags().GetString("domain")
417-
417+
418418
// Interactive prompts for missing values
419419
if domain == "" {
420420
fmt.Print("Enter domain name for mail server: ")
421-
fmt.Scanln(&domain)
421+
if _, err := fmt.Scanln(&domain); err != nil {
422+
return err
423+
}
422424
}
423-
425+
424426
serverName := "hecate-mail"
425427
if useCloud {
426428
fmt.Printf("Enter server name [%s]: ", serverName)
427429
var input string
428-
fmt.Scanln(&input)
430+
if _, err := fmt.Scanln(&input); err != nil {
431+
return err
432+
}
429433
if input != "" {
430434
serverName = input
431435
}
432436
}
433-
437+
434438
config := HecateConfig{
435439
UseHetzner: useCloud,
436440
ServerName: serverName,
437441
ServerType: serverType,
438442
Location: location,
439443
Domain: domain,
440444
}
441-
442-
logger.Info("Generating Hecate Terraform configuration",
445+
446+
logger.Info("Generating Hecate Terraform configuration",
443447
zap.String("domain", domain),
444448
zap.Bool("cloud", useCloud),
445449
zap.String("output_dir", outputDir))
446-
450+
447451
tfManager := terraform.NewManager(rc, outputDir)
448-
452+
449453
// Generate main.tf
450454
if err := tfManager.GenerateFromString(HecateTerraformTemplate, "main.tf", config); err != nil {
451455
return fmt.Errorf("failed to generate main.tf: %w", err)
452456
}
453-
457+
454458
// Generate cloud-init if using cloud
455459
if useCloud {
456460
if err := tfManager.GenerateFromString(HecateCloudInitTemplate, "hecate-cloud-init.yaml", config); err != nil {
457461
return fmt.Errorf("failed to generate cloud-init.yaml: %w", err)
458462
}
459463
}
460-
464+
461465
// Generate terraform.tfvars
462466
tfvarsContent := fmt.Sprintf(`# Terraform variables for Hecate deployment
463467
domain = "%s"`, domain)
464-
468+
465469
if useCloud {
466470
tfvarsContent += fmt.Sprintf(`
467471
# hcloud_token = "your-hetzner-cloud-token"
468472
ssh_key_name = "your-ssh-key"
469473
server_type = "%s"
470474
location = "%s"`, serverType, location)
471475
}
472-
476+
473477
if err := os.WriteFile(filepath.Join(outputDir, "terraform.tfvars"), []byte(tfvarsContent), 0644); err != nil {
474478
return fmt.Errorf("failed to generate terraform.tfvars: %w", err)
475479
}
476-
480+
477481
// Copy existing files if they exist
478482
configFiles := []string{"nginx.conf", "Caddyfile"}
479483
for _, file := range configFiles {
480484
if _, err := os.Stat(file); err == nil {
481485
content, err := os.ReadFile(file)
482486
if err == nil {
483487
destPath := filepath.Join(outputDir, file)
484-
os.WriteFile(destPath, content, 0644)
488+
if err := os.WriteFile(destPath, content, 0644); err != nil {
489+
return fmt.Errorf("failed to copy %s: %w", file, err)
490+
}
485491
logger.Info("Copied configuration file", zap.String("file", file))
486492
}
487493
}
488494
}
489-
495+
490496
// Initialize and validate
491497
if err := tfManager.Init(rc); err != nil {
492498
return fmt.Errorf("failed to initialize terraform: %w", err)
493499
}
494-
500+
495501
if err := tfManager.Validate(rc); err != nil {
496502
return fmt.Errorf("terraform configuration validation failed: %w", err)
497503
}
498-
504+
499505
if err := tfManager.Format(rc); err != nil {
500506
logger.Warn("Failed to format terraform files", zap.Error(err))
501507
}
502-
508+
503509
fmt.Printf("\n✅ Hecate Terraform configuration generated in: %s\n", outputDir)
504510
fmt.Println("\nNext steps:")
505511
if useCloud {
@@ -509,16 +515,16 @@ location = "%s"`, serverType, location)
509515
fmt.Printf("3. Review the configuration: cd %s\n", outputDir)
510516
fmt.Println("4. Plan the deployment: terraform plan")
511517
fmt.Println("5. Apply the configuration: terraform apply")
512-
518+
513519
return nil
514520
}
515521

516522
func init() {
517523
CreateCmd.AddCommand(hecateTerraformCmd)
518-
524+
519525
hecateTerraformCmd.Flags().String("output-dir", "./terraform-hecate", "Output directory for Terraform files")
520526
hecateTerraformCmd.Flags().Bool("cloud", false, "Deploy to cloud infrastructure")
521527
hecateTerraformCmd.Flags().String("server-type", "cx21", "Server type for cloud instance")
522528
hecateTerraformCmd.Flags().String("location", "nbg1", "Location for cloud instance")
523529
hecateTerraformCmd.Flags().String("domain", "", "Domain name for the mail server")
524-
}
530+
}

0 commit comments

Comments
 (0)