-
Notifications
You must be signed in to change notification settings - Fork 321
feat: add gcp get vm instance component #5011
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
Open
WashingtonKK
wants to merge
7
commits into
superplanehq:main
Choose a base branch
from
WashingtonKK:gcp/get-vm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+714
−10
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7a6b5d0
feat: add gcp get vm instance component
WashingtonKK 31889f0
feat: add "Get VM Instance" component to Google Cloud documentation
WashingtonKK 91c396e
fix: resolve duplicate symbols between GetVMInstance and DeleteVMInst…
WashingtonKK b4ede3d
Merge branch 'main' into gcp/get-vm
WashingtonKK 0958a2a
Merge branch 'main' into gcp/get-vm
WashingtonKK 07ba0bc
refactor: consolidate GetVMInstance onto shared event/metadata helpers
WashingtonKK 1979b43
refactor: share parseInstancePath helper across GCP VM mappers
WashingtonKK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
pkg/integrations/gcp/compute/example_output_get_vm_instance.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "type": "gcp.compute.vmInstance.fetched", | ||
| "data": { | ||
| "instanceId": "1234567890123456789", | ||
| "selfLink": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/my-vm", | ||
| "internalIP": "10.0.0.2", | ||
| "externalIP": "34.1.2.3", | ||
| "status": "RUNNING", | ||
| "zone": "us-central1-a", | ||
| "name": "my-vm", | ||
| "machineType": "e2-medium" | ||
| }, | ||
| "timestamp": "2025-02-14T12:00:00Z" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| package compute | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/mitchellh/mapstructure" | ||
| "github.com/superplanehq/superplane/pkg/configuration" | ||
| "github.com/superplanehq/superplane/pkg/core" | ||
| ) | ||
|
|
||
| type GetVMInstance struct{} | ||
|
|
||
| type GetVMInstanceSpec struct { | ||
| Instance string `mapstructure:"instance"` | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Name() string { | ||
| return "gcp.getVMInstance" | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Label() string { | ||
| return "Compute • Get VM Instance" | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Description() string { | ||
| return "Fetch the current state of a Google Compute Engine VM instance" | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Documentation() string { | ||
| return `The Get VM Instance component reads the current state of a Compute Engine VM | ||
| instance and emits its details on the default output channel. | ||
|
|
||
| ## Use Cases | ||
|
|
||
| - **Status checks**: Verify a VM is in the expected state (e.g. ` + "`RUNNING`" + `) before | ||
| proceeding with downstream work. | ||
| - **Detail lookup**: Fetch IPs, machine type, or selfLink for use in later workflow steps. | ||
| - **Health gates**: Pair with a condition to branch a workflow based on instance status. | ||
|
|
||
| ## Configuration | ||
|
|
||
| - **VM Instance**: Pick from the list of VMs in your project, or pass an expression chained | ||
| from an upstream node (e.g. ` + "`selfLink`" + ` from ` + "`gcp.createVM`" + `). The | ||
| selection encodes both the zone and the instance name. | ||
|
|
||
| ## Output | ||
|
|
||
| The emitted payload contains the full instance summary: | ||
|
|
||
| - **instanceId**, **selfLink**, **status**, **zone**, **name**, **machineType** | ||
| - **internalIP**, **externalIP** (when present) | ||
|
|
||
| ## Important Notes | ||
|
|
||
| - If the instance is not found at the resolved zone/name, the action fails so that | ||
| misconfigured or stale expressions do not silently mask a missing resource. | ||
| - The integration's bound project is authoritative; a chained ` + "`selfLink`" + ` pointing | ||
| at a different project is rejected rather than silently rewritten.` | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Icon() string { | ||
| return "search" | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Color() string { | ||
| return "blue" | ||
| } | ||
|
|
||
| func (g *GetVMInstance) OutputChannels(configuration any) []core.OutputChannel { | ||
| return []core.OutputChannel{core.DefaultOutputChannel} | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Configuration() []configuration.Field { | ||
| return []configuration.Field{ | ||
| { | ||
| Name: "instance", | ||
| Label: "VM Instance", | ||
| Type: configuration.FieldTypeIntegrationResource, | ||
| Required: true, | ||
| Description: "The VM instance to fetch. Lists every VM in your project across all zones.", | ||
| Placeholder: "Select instance", | ||
| TypeOptions: &configuration.TypeOptions{ | ||
| Resource: &configuration.ResourceTypeOptions{ | ||
| Type: ResourceTypeInstance, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Setup(ctx core.SetupContext) error { | ||
| spec := GetVMInstanceSpec{} | ||
| if err := mapstructure.Decode(ctx.Configuration, &spec); err != nil { | ||
| return fmt.Errorf("error decoding configuration: %v", err) | ||
| } | ||
|
|
||
| instanceValue := strings.TrimSpace(spec.Instance) | ||
| if instanceValue == "" { | ||
| return fmt.Errorf("instance is required") | ||
| } | ||
|
|
||
| // Reuse the shared instance-metadata resolver (see instance_helpers.go), | ||
| // which the delete/power/update/metrics components also use. | ||
| return resolveInstanceNodeMetadata(ctx, instanceValue) | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Execute(ctx core.ExecutionContext) error { | ||
| spec := GetVMInstanceSpec{} | ||
| if err := mapstructure.Decode(ctx.Configuration, &spec); err != nil { | ||
| return ctx.ExecutionState.Fail("error", fmt.Sprintf("failed to decode configuration: %v", err)) | ||
| } | ||
|
|
||
| urlProject, zone, instanceName, err := parseInstancePath(spec.Instance) | ||
| if err != nil { | ||
| return ctx.ExecutionState.Fail("error", err.Error()) | ||
| } | ||
|
|
||
| client, err := getClient(ctx) | ||
| if err != nil { | ||
| return ctx.ExecutionState.Fail("error", fmt.Sprintf("failed to create GCP client: %v", err)) | ||
| } | ||
|
|
||
| project := client.ProjectID() | ||
| // If the value carried an explicit project (selfLink form), it must match | ||
| // the integration's bound project. Silently rewriting could fetch the | ||
| // wrong VM in a different project that happens to share the same name. | ||
| if urlProject != "" && urlProject != project { | ||
| return ctx.ExecutionState.Fail("error", fmt.Sprintf( | ||
| "instance belongs to project %q but this GCP integration is bound to project %q; cross-project reads are not supported", | ||
| urlProject, project, | ||
| )) | ||
| } | ||
|
|
||
| body, err := GetInstance(context.Background(), client, project, zone, instanceName) | ||
| if err != nil { | ||
| return ctx.ExecutionState.Fail("error", fmt.Sprintf("failed to get VM instance: %v", err)) | ||
| } | ||
|
|
||
| payload, err := InstancePayloadFromGetResponse(body, zone) | ||
| if err != nil { | ||
| return ctx.ExecutionState.Fail("error", fmt.Sprintf("parse instance response: %v", err)) | ||
| } | ||
|
|
||
| return ctx.ExecutionState.Emit( | ||
| core.DefaultOutputChannel.Name, | ||
| "gcp.compute.vmInstance.fetched", | ||
| []any{payload}, | ||
| ) | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Cancel(ctx core.ExecutionContext) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (g *GetVMInstance) ProcessQueueItem(ctx core.ProcessQueueContext) (*uuid.UUID, error) { | ||
| return ctx.DefaultProcessing() | ||
| } | ||
|
|
||
| func (g *GetVMInstance) HandleWebhook(ctx core.WebhookRequestContext) (int, *core.WebhookResponseBody, error) { | ||
| return http.StatusOK, nil, nil | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Cleanup(ctx core.SetupContext) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (g *GetVMInstance) Hooks() []core.Hook { | ||
| return []core.Hook{} | ||
| } | ||
|
|
||
| func (g *GetVMInstance) HandleHook(ctx core.ActionHookContext) error { | ||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.