(cmd *cobra.Command)
| 38 | } |
| 39 | |
| 40 | func runDestroy(cmd *cobra.Command) error { |
| 41 | ctx := context.Background() |
| 42 | |
| 43 | // Load configuration |
| 44 | configPath, _ := cmd.Flags().GetString("config") |
| 45 | cfg, err := config.LoadCLIConfig(configPath) |
| 46 | if err != nil { |
| 47 | return fmt.Errorf("failed to load configuration: %w", err) |
| 48 | } |
| 49 | |
| 50 | // Apply command line flag overrides |
| 51 | if region, _ := cmd.Flags().GetString("region"); cmd.Flags().Changed("region") { |
| 52 | cfg.AWS.Region = region |
| 53 | } |
| 54 | if stackName, _ := cmd.Flags().GetString("stack-name"); cmd.Flags().Changed("stack-name") { |
| 55 | cfg.Deployment.StackName = stackName |
| 56 | } |
| 57 | |
| 58 | // Validate configuration |
| 59 | if errors := config.ValidateCLIConfig(cfg); len(errors) > 0 { |
| 60 | fmt.Printf("Configuration validation errors:\n") |
| 61 | for _, err := range errors { |
| 62 | fmt.Printf(" - %s\n", err.Error()) |
| 63 | } |
| 64 | return fmt.Errorf("configuration validation failed") |
| 65 | } |
| 66 | |
| 67 | stackName := cfg.Deployment.StackName |
| 68 | |
| 69 | // Create AWS clients |
| 70 | clientFactory, err := awsclients.NewClientFactory(cfg) |
| 71 | if err != nil { |
| 72 | return fmt.Errorf("failed to create AWS clients: %w", err) |
| 73 | } |
| 74 | |
| 75 | // Validate AWS credentials |
| 76 | if err := clientFactory.ValidateCredentials(ctx); err != nil { |
| 77 | return fmt.Errorf("invalid AWS credentials: %w", err) |
| 78 | } |
| 79 | |
| 80 | clients := clientFactory.GetClients() |
| 81 | |
| 82 | // Get stack information first to determine what to clean up |
| 83 | stackDeployer := deploy.NewStackDeployer(clients, cfg) |
| 84 | stackOutput, err := stackDeployer.GetStackOutputs(ctx) |
| 85 | if err != nil { |
| 86 | log.Printf("Warning: Could not get stack information: %v", err) |
| 87 | log.Printf("Will attempt to clean up resources by name...") |
| 88 | } |
| 89 | |
| 90 | // Show what will be destroyed |
| 91 | fmt.Printf("\n🔥 Lambda NAT Proxy Destruction Plan\n") |
| 92 | fmt.Printf("===================================\n\n") |
| 93 | fmt.Printf("The following resources will be PERMANENTLY DELETED:\n\n") |
| 94 | |
| 95 | if stackOutput != nil { |
| 96 | fmt.Printf("📦 CloudFormation Stack: %s\n", stackOutput.StackName) |
| 97 | fmt.Printf("🪣 S3 Bucket: %s\n", stackOutput.CoordinationBucketName) |
no test coverage detected