(cmd *cobra.Command)
| 32 | } |
| 33 | |
| 34 | func runDeploy(cmd *cobra.Command) error { |
| 35 | ctx := context.Background() |
| 36 | |
| 37 | // Load configuration |
| 38 | configPath, _ := cmd.Flags().GetString("config") |
| 39 | cfg, err := config.LoadCLIConfig(configPath) |
| 40 | if err != nil { |
| 41 | return fmt.Errorf("failed to load configuration: %w", err) |
| 42 | } |
| 43 | |
| 44 | // Apply command line flag overrides |
| 45 | if mode, _ := cmd.Flags().GetString("mode"); cmd.Flags().Changed("mode") { |
| 46 | cfg.Deployment.Mode = config.PerformanceMode(mode) |
| 47 | } |
| 48 | if region, _ := cmd.Flags().GetString("region"); cmd.Flags().Changed("region") { |
| 49 | cfg.AWS.Region = region |
| 50 | } |
| 51 | if stackName, _ := cmd.Flags().GetString("stack-name"); cmd.Flags().Changed("stack-name") { |
| 52 | cfg.Deployment.StackName = stackName |
| 53 | } |
| 54 | |
| 55 | // Validate configuration |
| 56 | if errors := config.ValidateCLIConfig(cfg); len(errors) > 0 { |
| 57 | fmt.Printf("❌ Configuration validation failed:\n\n") |
| 58 | for _, err := range errors { |
| 59 | errMsg := err.Error() |
| 60 | fmt.Printf(" • %s\n", errMsg) |
| 61 | // Add specific guidance based on common configuration issues |
| 62 | if strings.Contains(errMsg, "region") { |
| 63 | fmt.Printf(" 💡 Set region with: --region us-west-2 or in config file\n") |
| 64 | } else if strings.Contains(errMsg, "mode") { |
| 65 | fmt.Printf(" 💡 Valid modes: test, normal, performance\n") |
| 66 | } else if strings.Contains(errMsg, "stack") { |
| 67 | fmt.Printf(" 💡 Stack names must be 1-128 chars, letters/numbers/hyphens only\n") |
| 68 | } |
| 69 | } |
| 70 | fmt.Printf("\n💡 Generate a sample config file with: lambda-nat-proxy config init\n") |
| 71 | return fmt.Errorf("please fix the configuration issues above") |
| 72 | } |
| 73 | |
| 74 | dryRun, _ := cmd.Flags().GetBool("dry-run") |
| 75 | if dryRun { |
| 76 | return runDeployDryRun(cfg) |
| 77 | } |
| 78 | |
| 79 | log.Printf("Starting deployment in %s mode...", cfg.Deployment.Mode) |
| 80 | log.Printf("AWS Region: %s", cfg.AWS.Region) |
| 81 | log.Printf("Stack: %s", cfg.Deployment.StackName) |
| 82 | |
| 83 | // Create AWS clients |
| 84 | clientFactory, err := awsclients.NewClientFactory(cfg) |
| 85 | if err != nil { |
| 86 | return fmt.Errorf("failed to create AWS clients: %w", err) |
| 87 | } |
| 88 | |
| 89 | // Validate AWS credentials |
| 90 | if err := clientFactory.ValidateCredentials(ctx); err != nil { |
| 91 | return fmt.Errorf("invalid AWS credentials: %w", err) |
no test coverage detected