MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / runDestroy

Function runDestroy

cmd/lambda-nat-proxy/cmd_destroy.go:40–175  ·  view source on GitHub ↗
(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

38}
39
40func 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)

Callers 1

cmd_destroy.goFile · 0.85

Calls 12

ValidateCredentialsMethod · 0.95
GetClientsMethod · 0.95
GetStackOutputsMethod · 0.95
DeleteLambdaFunctionMethod · 0.95
DeleteStackMethod · 0.95
LoadCLIConfigFunction · 0.92
ValidateCLIConfigFunction · 0.92
NewStackDeployerFunction · 0.92
NewLambdaDeployerFunction · 0.92
cleanupS3ResourcesFunction · 0.85
deleteCloudWatchLogsFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected