-
Notifications
You must be signed in to change notification settings - Fork 159
feat(vpc-gw): add interactive question to delete the IP when deleting gw #5296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -366,7 +366,7 @@ scw vpc-gw gateway delete <gateway-id ...> [arg=value ...] | |
| | Name | | Description | | ||
| |------|---|-------------| | ||
| | gateway-id | Required | ID of the gateway to delete | | ||
| | delete-ip | | Defines whether the PGW's IP should be deleted | | ||
| | with-ip | Default: `prompt`<br />One of: `prompt`, `true`, `false` | Delete the IP attached to the gateway | | ||
| | zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `nl-ams-1`, `nl-ams-2`, `nl-ams-3`, `pl-waw-1`, `pl-waw-2`, `pl-waw-3` | Zone to target. If none is passed will use default zone from the config | | ||
|
Comment on lines
368
to
370
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,11 +2,13 @@ package vpcgw | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "reflect" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/fatih/color" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/scaleway/scaleway-cli/v2/core" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/scaleway/scaleway-cli/v2/core/human" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/scaleway/scaleway-cli/v2/internal/interactive" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/scaleway/scaleway-sdk-go/api/vpcgw/v2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/scaleway/scaleway-sdk-go/scw" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -63,3 +65,106 @@ func gatewayMarshalerFunc(i any, opt *human.MarshalOpt) (string, error) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return str, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Custom delete gateway command with interactive IP deletion confirmation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| type customDeleteGatewayRequest struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Zone scw.Zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| GatewayID string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeleteIP bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| DeleteIP bool |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This override renames the CLI arg from delete-ip (generated command) to with-ip, which will break existing scripts. Consider keeping delete-ip as a deprecated alias (e.g., same OneOfGroup as with-ip to prevent both being set) and translating it to with-ip=true/false behavior internally.
| Name: "with-ip", | |
| Short: "Delete the IP attached to the gateway", | |
| Default: core.DefaultValueSetter(withIPPrompt), | |
| EnumValues: []string{ | |
| withIPPrompt, | |
| withIPTrue, | |
| withIPFalse, | |
| }, | |
| }, | |
| Name: "with-ip", | |
| Short: "Delete the IP attached to the gateway", | |
| Default: core.DefaultValueSetter(withIPPrompt), | |
| EnumValues: []string{ | |
| withIPPrompt, | |
| withIPTrue, | |
| withIPFalse, | |
| }, | |
| OneOfGroup: "gateway-delete-ip-mode", | |
| }, | |
| { | |
| Name: "delete-ip", | |
| Short: "Delete the IP attached to the gateway (deprecated, use with-ip instead)", | |
| Deprecated: "use with-ip instead", | |
| OneOfGroup: "gateway-delete-ip-mode", | |
| }, |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetGateway is called unconditionally before deleting. If with-ip is explicitly true or false, this extra API call is unnecessary and can introduce extra latency / permission failures. Consider only fetching the gateway (and prompting) when with-ip=prompt is selected (or when using the deprecated alias, if kept).
| // Get gateway info to check if it has an IP | |
| gateway, err := api.GetGateway(&vpcgw.GetGatewayRequest{ | |
| Zone: args.Zone, | |
| GatewayID: args.GatewayID, | |
| }) | |
| if err != nil { | |
| return nil, err | |
| var gateway *vpcgw.Gateway | |
| var err error | |
| // Only fetch gateway info when we may need to prompt about deleting the IP | |
| if args.WithIP == withIPPrompt { | |
| gateway, err = api.GetGateway(&vpcgw.GetGatewayRequest{ | |
| Zone: args.Zone, | |
| GatewayID: args.GatewayID, | |
| }) | |
| if err != nil { | |
| return nil, err | |
| } |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In shouldDeleteIP, the default case silently returns (false, nil). This can hide unexpected values and change behavior without surfacing an error. Other tri-state flags in the codebase return an error for unsupported values (e.g. internal/namespaces/instance/v1/custom_server_action.go with-block handling). Return a descriptive error here instead of silently defaulting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there is a way to avoid a breaking change here