Google Cloud v8.21.0 published on Wednesday, Mar 5, 2025 by Pulumi
gcp.compute.getSnapshot
Explore with Pulumi AI
To get more information about Snapshot, see:
- API documentation
- How-to Guides
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
//by name 
const snapshot = gcp.compute.getSnapshot({
    name: "my-snapshot",
});
// using a filter
const latest_snapshot = gcp.compute.getSnapshot({
    filter: "name != my-snapshot",
    mostRecent: true,
});
import pulumi
import pulumi_gcp as gcp
#by name 
snapshot = gcp.compute.get_snapshot(name="my-snapshot")
# using a filter
latest_snapshot = gcp.compute.get_snapshot(filter="name != my-snapshot",
    most_recent=True)
package main
import (
	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/compute"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// by name
		_, err := compute.LookupSnapshot(ctx, &compute.LookupSnapshotArgs{
			Name: pulumi.StringRef("my-snapshot"),
		}, nil)
		if err != nil {
			return err
		}
		// using a filter
		_, err = compute.LookupSnapshot(ctx, &compute.LookupSnapshotArgs{
			Filter:     pulumi.StringRef("name != my-snapshot"),
			MostRecent: pulumi.BoolRef(true),
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() => 
{
    //by name 
    var snapshot = Gcp.Compute.GetSnapshot.Invoke(new()
    {
        Name = "my-snapshot",
    });
    // using a filter
    var latest_snapshot = Gcp.Compute.GetSnapshot.Invoke(new()
    {
        Filter = "name != my-snapshot",
        MostRecent = true,
    });
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.ComputeFunctions;
import com.pulumi.gcp.compute.inputs.GetSnapshotArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }
    public static void stack(Context ctx) {
        //by name 
        final var snapshot = ComputeFunctions.getSnapshot(GetSnapshotArgs.builder()
            .name("my-snapshot")
            .build());
        // using a filter
        final var latest-snapshot = ComputeFunctions.getSnapshot(GetSnapshotArgs.builder()
            .filter("name != my-snapshot")
            .mostRecent(true)
            .build());
    }
}
variables:
  #by name
  snapshot:
    fn::invoke:
      function: gcp:compute:getSnapshot
      arguments:
        name: my-snapshot
  # using a filter
  latest-snapshot:
    fn::invoke:
      function: gcp:compute:getSnapshot
      arguments:
        filter: name != my-snapshot
        mostRecent: true
Using getSnapshot
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getSnapshot(args: GetSnapshotArgs, opts?: InvokeOptions): Promise<GetSnapshotResult>
function getSnapshotOutput(args: GetSnapshotOutputArgs, opts?: InvokeOptions): Output<GetSnapshotResult>def get_snapshot(filter: Optional[str] = None,
                 most_recent: Optional[bool] = None,
                 name: Optional[str] = None,
                 project: Optional[str] = None,
                 opts: Optional[InvokeOptions] = None) -> GetSnapshotResult
def get_snapshot_output(filter: Optional[pulumi.Input[str]] = None,
                 most_recent: Optional[pulumi.Input[bool]] = None,
                 name: Optional[pulumi.Input[str]] = None,
                 project: Optional[pulumi.Input[str]] = None,
                 opts: Optional[InvokeOptions] = None) -> Output[GetSnapshotResult]func LookupSnapshot(ctx *Context, args *LookupSnapshotArgs, opts ...InvokeOption) (*LookupSnapshotResult, error)
func LookupSnapshotOutput(ctx *Context, args *LookupSnapshotOutputArgs, opts ...InvokeOption) LookupSnapshotResultOutput> Note: This function is named LookupSnapshot in the Go SDK.
public static class GetSnapshot 
{
    public static Task<GetSnapshotResult> InvokeAsync(GetSnapshotArgs args, InvokeOptions? opts = null)
    public static Output<GetSnapshotResult> Invoke(GetSnapshotInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetSnapshotResult> getSnapshot(GetSnapshotArgs args, InvokeOptions options)
public static Output<GetSnapshotResult> getSnapshot(GetSnapshotArgs args, InvokeOptions options)
fn::invoke:
  function: gcp:compute/getSnapshot:getSnapshot
  arguments:
    # arguments dictionaryThe following arguments are supported:
- Filter string
- A filter to retrieve the compute snapshot.
See API filter parameter documentation for reference.
If multiple compute snapshot match, either adjust the filter or specify most_recent. One ofnameorfiltermust be provided. If you want to use a regular expression, use theeq(equal) orne(not equal) operator against a single un-parenthesized expression with or without quotes or against multiple parenthesized expressions. ExamplesourceDisk eq '.*(.*/data-disk$).*'. More details for golang Snapshots list call filters here.
- MostRecent bool
- If filteris provided, ensures the most recent snapshot is returned when multiple compute snapshot match.
- Name string
- The name of the compute snapshot. One of nameorfiltermust be provided.
- Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- Filter string
- A filter to retrieve the compute snapshot.
See API filter parameter documentation for reference.
If multiple compute snapshot match, either adjust the filter or specify most_recent. One ofnameorfiltermust be provided. If you want to use a regular expression, use theeq(equal) orne(not equal) operator against a single un-parenthesized expression with or without quotes or against multiple parenthesized expressions. ExamplesourceDisk eq '.*(.*/data-disk$).*'. More details for golang Snapshots list call filters here.
- MostRecent bool
- If filteris provided, ensures the most recent snapshot is returned when multiple compute snapshot match.
- Name string
- The name of the compute snapshot. One of nameorfiltermust be provided.
- Project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- filter String
- A filter to retrieve the compute snapshot.
See API filter parameter documentation for reference.
If multiple compute snapshot match, either adjust the filter or specify most_recent. One ofnameorfiltermust be provided. If you want to use a regular expression, use theeq(equal) orne(not equal) operator against a single un-parenthesized expression with or without quotes or against multiple parenthesized expressions. ExamplesourceDisk eq '.*(.*/data-disk$).*'. More details for golang Snapshots list call filters here.
- mostRecent Boolean
- If filteris provided, ensures the most recent snapshot is returned when multiple compute snapshot match.
- name String
- The name of the compute snapshot. One of nameorfiltermust be provided.
- project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- filter string
- A filter to retrieve the compute snapshot.
See API filter parameter documentation for reference.
If multiple compute snapshot match, either adjust the filter or specify most_recent. One ofnameorfiltermust be provided. If you want to use a regular expression, use theeq(equal) orne(not equal) operator against a single un-parenthesized expression with or without quotes or against multiple parenthesized expressions. ExamplesourceDisk eq '.*(.*/data-disk$).*'. More details for golang Snapshots list call filters here.
- mostRecent boolean
- If filteris provided, ensures the most recent snapshot is returned when multiple compute snapshot match.
- name string
- The name of the compute snapshot. One of nameorfiltermust be provided.
- project string
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- filter str
- A filter to retrieve the compute snapshot.
See API filter parameter documentation for reference.
If multiple compute snapshot match, either adjust the filter or specify most_recent. One ofnameorfiltermust be provided. If you want to use a regular expression, use theeq(equal) orne(not equal) operator against a single un-parenthesized expression with or without quotes or against multiple parenthesized expressions. ExamplesourceDisk eq '.*(.*/data-disk$).*'. More details for golang Snapshots list call filters here.
- most_recent bool
- If filteris provided, ensures the most recent snapshot is returned when multiple compute snapshot match.
- name str
- The name of the compute snapshot. One of nameorfiltermust be provided.
- project str
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
- filter String
- A filter to retrieve the compute snapshot.
See API filter parameter documentation for reference.
If multiple compute snapshot match, either adjust the filter or specify most_recent. One ofnameorfiltermust be provided. If you want to use a regular expression, use theeq(equal) orne(not equal) operator against a single un-parenthesized expression with or without quotes or against multiple parenthesized expressions. ExamplesourceDisk eq '.*(.*/data-disk$).*'. More details for golang Snapshots list call filters here.
- mostRecent Boolean
- If filteris provided, ensures the most recent snapshot is returned when multiple compute snapshot match.
- name String
- The name of the compute snapshot. One of nameorfiltermust be provided.
- project String
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
getSnapshot Result
The following output properties are available:
- ChainName string
- CreationTimestamp string
- Description string
- DiskSize intGb 
- EffectiveLabels Dictionary<string, string>
- Id string
- The provider-assigned unique ID for this managed resource.
- LabelFingerprint string
- Labels Dictionary<string, string>
- Licenses List<string>
- PulumiLabels Dictionary<string, string>
- SelfLink string
- SnapshotEncryption List<GetKeys Snapshot Snapshot Encryption Key> 
- SnapshotId int
- SourceDisk string
- SourceDisk List<GetEncryption Keys Snapshot Source Disk Encryption Key> 
- StorageBytes int
- StorageLocations List<string>
- Zone string
- Filter string
- MostRecent bool
- Name string
- Project string
- ChainName string
- CreationTimestamp string
- Description string
- DiskSize intGb 
- EffectiveLabels map[string]string
- Id string
- The provider-assigned unique ID for this managed resource.
- LabelFingerprint string
- Labels map[string]string
- Licenses []string
- PulumiLabels map[string]string
- SelfLink string
- SnapshotEncryption []GetKeys Snapshot Snapshot Encryption Key 
- SnapshotId int
- SourceDisk string
- SourceDisk []GetEncryption Keys Snapshot Source Disk Encryption Key 
- StorageBytes int
- StorageLocations []string
- Zone string
- Filter string
- MostRecent bool
- Name string
- Project string
- chainName String
- creationTimestamp String
- description String
- diskSize IntegerGb 
- effectiveLabels Map<String,String>
- id String
- The provider-assigned unique ID for this managed resource.
- labelFingerprint String
- labels Map<String,String>
- licenses List<String>
- pulumiLabels Map<String,String>
- selfLink String
- snapshotEncryption List<GetKeys Snapshot Snapshot Encryption Key> 
- snapshotId Integer
- sourceDisk String
- sourceDisk List<GetEncryption Keys Snapshot Source Disk Encryption Key> 
- storageBytes Integer
- storageLocations List<String>
- zone String
- filter String
- mostRecent Boolean
- name String
- project String
- chainName string
- creationTimestamp string
- description string
- diskSize numberGb 
- effectiveLabels {[key: string]: string}
- id string
- The provider-assigned unique ID for this managed resource.
- labelFingerprint string
- labels {[key: string]: string}
- licenses string[]
- pulumiLabels {[key: string]: string}
- selfLink string
- snapshotEncryption GetKeys Snapshot Snapshot Encryption Key[] 
- snapshotId number
- sourceDisk string
- sourceDisk GetEncryption Keys Snapshot Source Disk Encryption Key[] 
- storageBytes number
- storageLocations string[]
- zone string
- filter string
- mostRecent boolean
- name string
- project string
- chain_name str
- creation_timestamp str
- description str
- disk_size_ intgb 
- effective_labels Mapping[str, str]
- id str
- The provider-assigned unique ID for this managed resource.
- label_fingerprint str
- labels Mapping[str, str]
- licenses Sequence[str]
- pulumi_labels Mapping[str, str]
- self_link str
- snapshot_encryption_ Sequence[Getkeys Snapshot Snapshot Encryption Key] 
- snapshot_id int
- source_disk str
- source_disk_ Sequence[Getencryption_ keys Snapshot Source Disk Encryption Key] 
- storage_bytes int
- storage_locations Sequence[str]
- zone str
- filter str
- most_recent bool
- name str
- project str
- chainName String
- creationTimestamp String
- description String
- diskSize NumberGb 
- effectiveLabels Map<String>
- id String
- The provider-assigned unique ID for this managed resource.
- labelFingerprint String
- labels Map<String>
- licenses List<String>
- pulumiLabels Map<String>
- selfLink String
- snapshotEncryption List<Property Map>Keys 
- snapshotId Number
- sourceDisk String
- sourceDisk List<Property Map>Encryption Keys 
- storageBytes Number
- storageLocations List<String>
- zone String
- filter String
- mostRecent Boolean
- name String
- project String
Supporting Types
GetSnapshotSnapshotEncryptionKey    
- KmsKey stringSelf Link 
- The name of the encryption key that is stored in Google Cloud KMS.
- KmsKey stringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- RawKey string
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- Sha256 string
- The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
- KmsKey stringSelf Link 
- The name of the encryption key that is stored in Google Cloud KMS.
- KmsKey stringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- RawKey string
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- Sha256 string
- The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
- kmsKey StringSelf Link 
- The name of the encryption key that is stored in Google Cloud KMS.
- kmsKey StringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- rawKey String
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- sha256 String
- The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
- kmsKey stringSelf Link 
- The name of the encryption key that is stored in Google Cloud KMS.
- kmsKey stringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- rawKey string
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- sha256 string
- The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
- kms_key_ strself_ link 
- The name of the encryption key that is stored in Google Cloud KMS.
- kms_key_ strservice_ account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- raw_key str
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- sha256 str
- The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
- kmsKey StringSelf Link 
- The name of the encryption key that is stored in Google Cloud KMS.
- kmsKey StringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- rawKey String
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- sha256 String
- The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.
GetSnapshotSourceDiskEncryptionKey     
- KmsKey stringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- RawKey string
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- KmsKey stringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- RawKey string
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- kmsKey StringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- rawKey String
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- kmsKey stringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- rawKey string
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- kms_key_ strservice_ account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- raw_key str
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
- kmsKey StringService Account 
- The service account used for the encryption request for the given KMS key. If absent, the Compute Engine Service Agent service account is used.
- rawKey String
- Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource.
Package Details
- Repository
- Google Cloud (GCP) Classic pulumi/pulumi-gcp
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the google-betaTerraform Provider.