{"modulePath":"github.com/newstack-cloud/deploy-cli-sdk","version":"v0.10.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package stateio\n\n## Constants\n\n```go\nconst (\n\tObjectStoreProviderS3        = \"s3\"\n\tObjectStoreProviderGCS       = \"gcs\"\n\tObjectStoreProviderAzureBlob = \"azureblob\"\n)\n```\nThe object storage services the objectstore storage engine can keep state in, as set in ObjectStoreConfig.Provider.\n\n```go\nconst (\n\tStorageEngineMemfile     = \"memfile\"\n\tStorageEnginePostgres    = \"postgres\"\n\tStorageEngineObjectstore = \"objectstore\"\n)\n```\n\n## Functions\n\n```go\nfunc BuildPostgresDatabaseURL(config *StateConfig) string\n```\nBuildPostgresDatabaseURL constructs a postgres connection URL from config. The user, password and database name are escaped, so a password containing characters such as \"@\", \"/\" or \"#\" connects as it is written.\n\n```go\nfunc CreateTestTarGz(t *testing.T, files map[string][]byte) []byte\n```\nCreateTestTarGz creates a valid tar.gz archive with the given file contents. This is exported for use by tests in other packages.\n\n```go\nfunc DescribeState(config *StateConfig) string\n```\nDescribeState returns a one-line description of where the engine config says state lives and whether it is encrypted at rest, for showing to the person running an import or export. It never includes credentials.\n\n```go\nfunc DownloadRemoteFile(ctx context.Context, filePath string, opts *RemoteDownloadOptions) ([]byte, error)\n```\nDownloadRemoteFile downloads a file from a remote storage location. Supports s3://, gcs://, and azureblob:// URL schemes.\n\n```go\nfunc FindEngineConfigFile() (string, error)\n```\nFindEngineConfigFile returns the deploy engine config file the deploy engine itself would read: config.json in the default config directory, or else in the directory BLUELINK\\_DEPLOY\\_ENGINE\\_CONFIG\\_PATH names. It returns an empty path when there is none, in which case the deploy engine runs on its environment variables and defaults alone.\n\nThe deploy engine also reads config files in other formats, which this package cannot parse, so finding one of those is an error rather than a reason to fall back to the defaults and use the wrong state. The deploy engine's working directory is searched first too, but it is not searched here: it is rarely the directory the CLI runs in, and another project's config.json there would be taken for the engine's.\n\n```go\nfunc GetDefaultEngineConfigPath() string\n```\nGetDefaultEngineConfigPath returns the default engine config file path.\n\n```go\nfunc GetDefaultStateDir() string\n```\nGetDefaultStateDir returns the default state directory based on the OS.\n\n```go\nfunc IsRemoteFile(filePath string) bool\n```\nIsRemoteFile returns true if the file path refers to a remote storage location.\n\n```go\nfunc ParseInstancesJSON(data []byte) ([]state.InstanceState, error)\n```\nParseInstancesJSON parses a JSON array of instances from raw bytes.\n\n```go\nfunc SerializeInstancesJSON(instances []state.InstanceState) ([]byte, error)\n```\nSerializeInstancesJSON serializes instances to a JSON byte array.\n\n```go\nfunc UploadRemoteFile(ctx context.Context, filePath string, data []byte, opts *RemoteUploadOptions) error\n```\nUploadRemoteFile uploads a file to a remote storage location. Supports s3://, gcs://, and azureblob:// URL schemes.\n\n## Types\n\n```go\ntype ContainerStateExporter struct {\n\t// contains filtered or unexported fields\n}\n```\nContainerStateExporter implements StateExporter using a state.Container. This works with any backend that implements the state.Container interface.\n\n```go\nfunc NewContainerStateExporter(container state.Container) *ContainerStateExporter\n```\nNewContainerStateExporter creates a new exporter that uses the given container.\n\n```go\nfunc (e *ContainerStateExporter) ExportInstances(\n\tctx context.Context,\n\tinstanceFilters []string,\n) ([]state.InstanceState, error)\n```\nExportInstances retrieves instances using the container's batch get operation. If instanceFilters is empty, all instances are exported.\n\nAn instance nested under another exported instance is exported only there, and an instance the filters name more than once is exported once.\n\n```go\ntype ContainerStateImporter struct {\n\t// contains filtered or unexported fields\n}\n```\nContainerStateImporter implements StateImporter using a state.Container. This works with any backend that implements the state.Container interface. It uses the container's SaveBatch method for efficient bulk operations.\n\n```go\nfunc NewContainerStateImporter(\n\tcontainer state.Container,\n\topts ...ContainerStateImporterOption,\n) *ContainerStateImporter\n```\nNewContainerStateImporter creates a new importer that uses the given container.\n\n```go\nfunc (i *ContainerStateImporter) ImportInstances(ctx context.Context, instances []state.InstanceState) error\n```\nImportInstances saves the instances and their nested child blueprints, checking each child as an instance in its own right. Nothing is written unless every instance passes the checks: a new instance can't take another's name, an existing one can't be renamed, and an existing one with an operation in progress is refused unless the importer was created WithForce.\n\nExisting instances get a version past both the stored and the imported one, so an objectstore engine holding the old version conflicts rather than writing over the import. Stop a memfile engine while importing; on postgres, only the in-progress check protects against a running engine.\n\n```go\ntype ContainerStateImporterOption func(*ContainerStateImporter)\n```\nContainerStateImporterOption configures a ContainerStateImporter.\n\n```go\nfunc WithForce(force bool) ContainerStateImporterOption\n```\nWithForce allows importing over instances that have an operation in progress. It exists for a deployment that was lost or abandoned without its status being updated, which would otherwise leave the instance blocked from being imported over.\n\n```go\ntype EngineConfig struct {\n\tState StateConfig `json:\"state\"`\n}\n```\nEngineConfig represents the deploy engine configuration file structure. Only the state-related fields are parsed.\n\n```go\nfunc LoadEngineConfig(configFilePath string) (*EngineConfig, error)\n```\nLoadEngineConfig loads and parses a deploy engine configuration file.\n\nState settings provided through the deploy engine's environment variables (BLUELINK\\_DEPLOY\\_ENGINE\\_STATE\\_\\*) take precedence over the file, matching how the deploy engine resolves its own configuration. Secrets such as encryption passphrases and storage credentials are commonly supplied this way.\n\n```go\nfunc LoadEngineConfigFromEnv() (*EngineConfig, error)\n```\nLoadEngineConfigFromEnv builds a deploy engine configuration from the deploy engine's environment variables (BLUELINK\\_DEPLOY\\_ENGINE\\_STATE\\_\\*) and defaults alone, for a deploy engine that runs without a config file, as the deploy engine itself can.\n\n```go\ntype ErrorExplanation struct {\n\t// Code is the error's code, such as \"state_decryption_failed\", or empty for an error\n\t// that is not from this package.\n\tCode string\n\t// Summary is a short description of what failed. It can span several lines, such as\n\t// the list of problems that stopped an import.\n\tSummary string\n\t// Hint says what to check or change to fix the error, or is empty.\n\tHint string\n\t// Cause is the innermost error behind the summary, or is empty when there is none\n\t// or it says nothing the summary does not.\n\tCause string\n}\n```\nErrorExplanation splits an import or export error into the parts a person reads: what failed, what to do about it, and the underlying cause.\n\n```go\nfunc ExplainError(err error) ErrorExplanation\n```\nExplainError explains an error returned by Import or Export. Errors from this package are split into their summary, hint and innermost cause; any other error is returned whole as the summary.\n\n```go\ntype ExportError struct {\n\tCode    ExportErrorCode\n\tMessage string\n\t// Hint says what to check or change to fix the error, if anything.\n\tHint string\n\tErr  error\n}\n```\nExportError represents an error that occurred during export.\n\n```go\nfunc (e *ExportError) Error() string\n```\n\n```go\nfunc (e *ExportError) Unwrap() error\n```\n\n```go\ntype ExportErrorCode string\n```\nExportErrorCode represents the type of export error.\n\n```go\nconst (\n\t// ErrCodeExportFailed indicates a general export failure.\n\tErrCodeExportFailed ExportErrorCode = \"export_failed\"\n\t// ErrCodeInstanceNotFound indicates one or more instances were not found.\n\tErrCodeInstanceNotFound ExportErrorCode = \"not_found\"\n\t// ErrCodeRemoteUploadFailed indicates a remote upload failed.\n\tErrCodeRemoteUploadFailed ExportErrorCode = \"remote_upload_failed\"\n\t// ErrCodeFileEncryptionFailed indicates the output file could not be encrypted\n\t// with the provided key.\n\tErrCodeFileEncryptionFailed ExportErrorCode = \"file_encryption_failed\"\n)\n```\n\n```go\ntype ExportInstancesResult struct {\n\tInstancesCount int\n\tData           []byte\n}\n```\nExportInstancesResult contains the result of an instances export.\n\n```go\nfunc ExecuteInstancesExport(\n\tctx context.Context,\n\texporter StateExporter,\n\tinstanceFilters []string,\n) (*ExportInstancesResult, error)\n```\nExecuteInstancesExport performs the instances export using the provided exporter.\n\n```go\ntype ExportParams struct {\n\t// FilePath is the path to the output file (local or remote URL).\n\tFilePath string\n\t// InstanceFilters is a list of instance IDs or names to export.\n\t// If empty, all instances are exported.\n\tInstanceFilters []string\n\t// EngineConfig contains the deploy engine configuration.\n\t// Used to determine the storage backend (memfile or postgres).\n\tEngineConfig *EngineConfig\n\t// FileSystem is the filesystem to use for local file operations.\n\tFileSystem afero.Fs\n\t// Logger is the logger to use for logging.\n\tLogger core.Logger\n\t// RemoteOptions contains options for uploading to remote storage.\n\tRemoteOptions *RemoteUploadOptions\n\t// Exporter is an optional StateExporter for export.\n\t// If not provided, a default exporter will be created based on EngineConfig.\n\tExporter StateExporter\n\t// FileEncryption is the key the output file is encrypted with.\n\t// When nil, the file is written as plaintext JSON.\n\tFileEncryption *StateEncryptionKeyConfig\n}\n```\nExportParams contains the parameters for an export operation.\n\n```go\ntype ExportResult struct {\n\tSuccess        bool   `json:\"success\"`\n\tInstancesCount int    `json:\"instancesCount,omitempty\"`\n\tFilePath       string `json:\"filePath,omitempty\"`\n\tMessage        string `json:\"message\"`\n\t// Encrypted is true when the output file was encrypted.\n\tEncrypted bool `json:\"encrypted,omitempty\"`\n\t// Warnings holds anything the caller should be told about the exported file,\n\t// such as it holding state in plaintext that is encrypted at rest.\n\tWarnings []string `json:\"warnings,omitempty\"`\n}\n```\nExportResult contains the result of an export operation.\n\n```go\nfunc Export(params ExportParams) (*ExportResult, error)\n```\nExport performs a state export operation based on the provided parameters. The output is a JSON array of blueprint instances.\n\n```go\ntype FileEncryptionKeyOptions struct {\n\t// Key names a key held outside the CLI as \"\u003cprovider\u003e:\u003cid\u003e\", for example\n\t// \"awskms:alias/state-export\", \"gcpkms:projects/p/locations/l/keyRings/r/cryptoKeys/k\",\n\t// \"azurekeyvault:https://vault.vault.azure.net/keys/name\" or \"localkey:/path/to/key\".\n\tKey string\n\t// PassphraseFile is the path to a file holding the passphrase.\n\tPassphraseFile string\n\t// Passphrase is a passphrase taken from the environment. It is never accepted as a\n\t// command line flag value, which would leave it in shell history and CI logs.\n\tPassphrase string\n}\n```\nFileEncryptionKeyOptions holds the ways a CLI can name the key an export file is encrypted or decrypted with.\n\n```go\ntype ImportError struct {\n\tCode    ImportErrorCode\n\tMessage string\n\t// Hint says what to check or change to fix the error, if anything.\n\tHint string\n\tErr  error\n}\n```\nImportError represents an error that occurred during import.\n\n```go\nfunc (e *ImportError) Error() string\n```\n\n```go\nfunc (e *ImportError) Unwrap() error\n```\n\n```go\ntype ImportErrorCode string\n```\nImportErrorCode represents the type of import error.\n\n```go\nconst (\n\t// ErrCodeInvalidJSON indicates the JSON input is malformed.\n\tErrCodeInvalidJSON ImportErrorCode = \"invalid_json\"\n\t// ErrCodeFileNotFound indicates the input file was not found.\n\tErrCodeFileNotFound ImportErrorCode = \"file_not_found\"\n\t// ErrCodeRemoteAccessFail indicates a remote file could not be accessed.\n\tErrCodeRemoteAccessFail ImportErrorCode = \"remote_access_failed\"\n\t// ErrCodeFileKeyRequired indicates the input file is encrypted and no key was provided.\n\tErrCodeFileKeyRequired ImportErrorCode = \"file_key_required\"\n\t// ErrCodeFileDecryptionFailed indicates the input file could not be decrypted\n\t// with the provided key.\n\tErrCodeFileDecryptionFailed ImportErrorCode = \"file_decryption_failed\"\n\t// ErrCodeFileNotEncrypted indicates the input file is plaintext although the import\n\t// required an encrypted one.\n\tErrCodeFileNotEncrypted ImportErrorCode = \"file_not_encrypted\"\n\t// ErrCodeInstanceNameConflict indicates a new instance in the input uses a name\n\t// another instance already has.\n\tErrCodeInstanceNameConflict ImportErrorCode = \"instance_name_conflict\"\n\t// ErrCodeInstanceNameImmutable indicates the input renames an existing instance.\n\tErrCodeInstanceNameImmutable ImportErrorCode = \"instance_name_immutable\"\n\t// ErrCodeInstanceOperationInProgress indicates the input would overwrite an instance\n\t// an engine is still working on.\n\tErrCodeInstanceOperationInProgress ImportErrorCode = \"instance_operation_in_progress\"\n\t// ErrCodeChildBlueprintCycle indicates instances in the input are children of each\n\t// other in a cycle, so none of them is a top-level instance to import them under.\n\tErrCodeChildBlueprintCycle ImportErrorCode = \"child_blueprint_cycle\"\n\t// ErrCodeInstanceCopiesDiffer indicates an instance appears more than once in the\n\t// input and the copies are not the same.\n\tErrCodeInstanceCopiesDiffer ImportErrorCode = \"instance_copies_differ\"\n\t// ErrCodeChildBlueprintMultipleParents indicates the input lists an instance as a child\n\t// blueprint of more than one parent, or under more than one name in one parent.\n\tErrCodeChildBlueprintMultipleParents ImportErrorCode = \"child_blueprint_multiple_parents\"\n)\n```\n\n```go\ntype ImportInstancesResult struct {\n\tInstancesCount int\n}\n```\nImportInstancesResult contains the result of an instances import.\n\n```go\nfunc ExecuteInstancesImport(\n\tctx context.Context,\n\timporter StateImporter,\n\tdata []byte,\n) (*ImportInstancesResult, error)\n```\nExecuteInstancesImport performs the instances import using the provided importer.\n\n```go\ntype ImportParams struct {\n\t// FilePath is the path to the input file (local or remote URL).\n\tFilePath string\n\t// EngineConfig contains the deploy engine configuration.\n\t// Used to determine the storage backend (memfile or postgres).\n\tEngineConfig *EngineConfig\n\t// FileSystem is the filesystem to use for operations.\n\tFileSystem afero.Fs\n\t// Logger is the logger to use for logging.\n\tLogger core.Logger\n\t// FileData contains the raw file data to import.\n\t// If provided, FilePath is ignored for reading (but may be used for logging).\n\tFileData []byte\n\t// RemoteOptions contains options for downloading from remote storage.\n\tRemoteOptions *RemoteDownloadOptions\n\t// Importer is an optional StateImporter for import.\n\t// If not provided, a default importer will be created based on EngineConfig.\n\tImporter StateImporter\n\t// FileEncryption is the key to decrypt the input file with when it is encrypted.\n\t// Encrypted files are detected, so this is only needed for those.\n\tFileEncryption *StateEncryptionKeyConfig\n\t// RequireEncryptedFile refuses an input file that is not encrypted. Set it when a key\n\t// was given for this import in particular, so that a file someone replaced with a\n\t// plaintext one is not imported as if it had been decrypted. A key that applies to\n\t// every import, such as a passphrase in a pipeline's environment, should not set it.\n\tRequireEncryptedFile bool\n\t// Force allows importing over instances that have an operation in progress.\n\t// See WithForce. It does not apply to a custom Importer, which is created with its\n\t// own options.\n\tForce bool\n}\n```\nImportParams contains the parameters for an import operation.\n\n```go\ntype ImportResult struct {\n\tSuccess        bool   `json:\"success\"`\n\tInstancesCount int    `json:\"instancesCount,omitempty\"`\n\tMessage        string `json:\"message\"`\n\t// Encrypted is true when the input file was an encrypted export file.\n\tEncrypted bool `json:\"encrypted,omitempty\"`\n\t// FileExportedAt is when an encrypted input file was exported. It is bound to the\n\t// file's encryption, so it can be relied on to tell an older export from the one\n\t// expected. It is zero for a plaintext file.\n\tFileExportedAt time.Time `json:\"fileExportedAt,omitzero\"`\n}\n```\nImportResult contains the result of an import operation.\n\n```go\nfunc Import(params ImportParams) (*ImportResult, error)\n```\nImport performs a state import operation based on the provided parameters. The input file must be a JSON array of blueprint instances.\n\n```go\ntype ObjectStoreAzureBlobConfig struct {\n\tServiceURL  string `json:\"service_url\"`\n\tAccountName string `json:\"account_name\"`\n\tAccountKey  string `json:\"account_key\"`\n\tContainer   string `json:\"container\"`\n}\n```\nObjectStoreAzureBlobConfig configures the Azure Blob Storage-backed objectstore storage engine.\n\n```go\ntype ObjectStoreConfig struct {\n\t// Provider is one of \"s3\", \"gcs\" or \"azureblob\".\n\tProvider string `json:\"provider\"`\n\t// Prefix is prepended to every storage key in the bucket or container.\n\tPrefix    string                     `json:\"prefix\"`\n\tS3        ObjectStoreS3Config        `json:\"s3\"`\n\tGCS       ObjectStoreGCSConfig       `json:\"gcs\"`\n\tAzureBlob ObjectStoreAzureBlobConfig `json:\"azureblob\"`\n}\n```\nObjectStoreConfig mirrors the deploy engine's objectstore storage engine configuration.\n\n```go\ntype ObjectStoreGCSConfig struct {\n\tBucket                string `json:\"bucket\"`\n\tEndpoint              string `json:\"endpoint\"`\n\tWithoutAuthentication bool   `json:\"without_authentication\"`\n}\n```\nObjectStoreGCSConfig configures the Google Cloud Storage-backed objectstore storage engine.\n\n```go\ntype ObjectStoreS3Config struct {\n\tBucket          string `json:\"bucket\"`\n\tRegion          string `json:\"region\"`\n\tEndpoint        string `json:\"endpoint\"`\n\tUsePathStyle    bool   `json:\"use_path_style\"`\n\tAccessKeyID     string `json:\"access_key_id\"`\n\tSecretAccessKey string `json:\"secret_access_key\"`\n}\n```\nObjectStoreS3Config configures the S3-backed objectstore storage engine.\n\n```go\ntype RemoteDownloadOptions struct {\n\t// S3Endpoint overrides the default S3 endpoint (useful for testing with LocalStack).\n\tS3Endpoint string\n\t// S3UsePathStyle enables path-style addressing for S3 (required for LocalStack).\n\tS3UsePathStyle bool\n\t// GCSEndpoint overrides the default GCS endpoint (useful for testing with fake-gcs-server).\n\tGCSEndpoint string\n\t// AzureConnectionString is the connection string for Azure Blob Storage.\n\t// If empty, DefaultAzureCredential will be used.\n\tAzureConnectionString string\n}\n```\nRemoteDownloadOptions contains options for downloading files from remote storage.\n\n```go\ntype RemoteUploadOptions struct {\n\t// S3Endpoint overrides the default S3 endpoint (useful for testing with LocalStack).\n\tS3Endpoint string\n\t// S3UsePathStyle enables path-style addressing for S3 (required for LocalStack).\n\tS3UsePathStyle bool\n\t// GCSEndpoint overrides the default GCS endpoint (useful for testing with fake-gcs-server).\n\tGCSEndpoint string\n\t// AzureConnectionString is the connection string for Azure Blob Storage.\n\t// If empty, DefaultAzureCredential will be used.\n\tAzureConnectionString string\n}\n```\nRemoteUploadOptions contains options for uploading files to remote storage.\n\n```go\ntype StateAccessError struct {\n\tCode StateAccessErrorCode\n\t// Message is a short summary of what failed.\n\tMessage string\n\t// Hint says what to check or change to fix the error, if anything.\n\tHint string\n\tErr  error\n}\n```\nStateAccessError represents an error opening the state an import or export works on.\n\n```go\nfunc (e *StateAccessError) Error() string\n```\n\n```go\nfunc (e *StateAccessError) Unwrap() error\n```\n\n```go\ntype StateAccessErrorCode string\n```\nStateAccessErrorCode represents the reason state could not be opened for an import or export.\n\n```go\nconst (\n\t// ErrCodeEncryptionKeyUnavailable indicates the key state is encrypted with\n\t// could not be built from the engine config, for example a missing passphrase,\n\t// an unreadable key file or an unreachable key management service.\n\tErrCodeEncryptionKeyUnavailable StateAccessErrorCode = \"encryption_key_unavailable\"\n\t// ErrCodeStateDecryptionFailed indicates encrypted state could not be decrypted\n\t// with the configured key.\n\tErrCodeStateDecryptionFailed StateAccessErrorCode = \"state_decryption_failed\"\n\t// ErrCodeStateConfigInvalid indicates the deploy engine's state configuration, from its\n\t// config file or environment variables, cannot be used as it is.\n\tErrCodeStateConfigInvalid StateAccessErrorCode = \"state_config_invalid\"\n\t// ErrCodeStateUnavailable indicates the configured state could not be reached or loaded,\n\t// for example a database or bucket that cannot be connected to.\n\tErrCodeStateUnavailable StateAccessErrorCode = \"state_unavailable\"\n)\n```\n\n```go\ntype StateConfig struct {\n\tStorageEngine               string `json:\"storage_engine\"`\n\tMemFileStateDir             string `json:\"memfile_state_dir\"`\n\tPostgresUser                string `json:\"postgres_user\"`\n\tPostgresPassword            string `json:\"postgres_password\"`\n\tPostgresHost                string `json:\"postgres_host\"`\n\tPostgresPort                int    `json:\"postgres_port\"`\n\tPostgresDatabase            string `json:\"postgres_database\"`\n\tPostgresSSLMode             string `json:\"postgres_ssl_mode\"`\n\tPostgresPoolMaxConns        int    `json:\"postgres_pool_max_conns\"`\n\tPostgresPoolMaxConnLifetime string `json:\"postgres_pool_max_conn_lifetime\"`\n\t// Encryption holds the configuration for encrypting persisted state at rest.\n\t// The deploy engine only supports this for the memfile storage engine.\n\tEncryption StateEncryptionConfig `json:\"encryption\"`\n\t// ObjectStore holds the configuration for the objectstore storage engine.\n\tObjectStore ObjectStoreConfig `json:\"objectstore\"`\n}\n```\nStateConfig holds the state-related configuration from an engine config file. This is a subset of the deploy engine's StateConfig, containing only the fields needed for state import/export operations.\n\n```go\ntype StateEncryptionAWSKMSConfig struct {\n\tKeyID           string `json:\"key_id\"`\n\tRegion          string `json:\"region\"`\n\tEndpoint        string `json:\"endpoint\"`\n\tAccessKeyID     string `json:\"access_key_id\"`\n\tSecretAccessKey string `json:\"secret_access_key\"`\n}\n```\nStateEncryptionAWSKMSConfig configures state encryption against AWS KMS.\n\n```go\ntype StateEncryptionAzureKeyVaultConfig struct {\n\tVaultURL   string `json:\"vault_url\"`\n\tKeyName    string `json:\"key_name\"`\n\tKeyVersion string `json:\"key_version\"`\n\tAlgorithm  string `json:\"algorithm\"`\n}\n```\nStateEncryptionAzureKeyVaultConfig configures state encryption against Azure Key Vault.\n\n```go\ntype StateEncryptionConfig struct {\n\tEnabled bool `json:\"enabled\"`\n\t// StateEncryptionKeyConfig is embedded so the active key's fields sit directly\n\t// under \"encryption\", matching the deploy engine's config file layout.\n\tStateEncryptionKeyConfig\n\t// PreviousKeys holds keys that state is no longer encrypted with but that\n\t// objects written before a key change may still be sealed with.\n\tPreviousKeys []StateEncryptionKeyConfig `json:\"previous_keys\"`\n}\n```\nStateEncryptionConfig mirrors the deploy engine's state encryption configuration.\n\n```go\ntype StateEncryptionGCPKMSConfig struct {\n\tKeyName         string `json:\"key_name\"`\n\tCredentialsFile string `json:\"credentials_file\"`\n}\n```\nStateEncryptionGCPKMSConfig configures state encryption against Google Cloud KMS.\n\n```go\ntype StateEncryptionKeyConfig struct {\n\t// Provider is one of \"passphrase\", \"localkey\", \"awskms\", \"gcpkms\" or \"azurekeyvault\".\n\tProvider       string                             `json:\"provider\"`\n\tPassphrase     string                             `json:\"passphrase\"`\n\tPassphraseFile string                             `json:\"passphrase_file\"`\n\tLocalKeyFile   string                             `json:\"local_key_file\"`\n\tAWSKMS         StateEncryptionAWSKMSConfig        `json:\"awskms\"`\n\tGCPKMS         StateEncryptionGCPKMSConfig        `json:\"gcpkms\"`\n\tAzureKeyVault  StateEncryptionAzureKeyVaultConfig `json:\"azurekeyvault\"`\n}\n```\nStateEncryptionKeyConfig identifies one key that state is, or was, encrypted with.\n\n```go\nfunc ResolveFileEncryptionKey(opts FileEncryptionKeyOptions) (*StateEncryptionKeyConfig, error)\n```\nResolveFileEncryptionKey returns the key configuration an export file is encrypted or decrypted with, or nil when no key was given.\n\nA key or passphrase file given explicitly takes precedence over a passphrase from the environment, which may be set for every job in a pipeline. Giving both a key and a passphrase file is an error, since it is unclear which was meant.\n\n```go\ntype StateExporter interface {\n\t// ExportInstances exports instances by their IDs or names.\n\t// If instanceFilters is empty, exports all instances.\n\t// Returns the full instance state including child blueprints. Each instance is\n\t// returned once: one nested under another returned instance is only returned there.\n\tExportInstances(ctx context.Context, instanceFilters []string) ([]state.InstanceState, error)\n}\n```\nStateExporter defines the interface for exporting instance state data. This abstraction allows different storage backends to implement their own export logic with optimal performance characteristics.\n\n```go\ntype StateImporter interface {\n\t// ImportInstances imports a slice of instance states.\n\t// Implementations should handle batch operations efficiently where possible.\n\tImportInstances(ctx context.Context, instances []state.InstanceState) error\n}\n```\nStateImporter defines the interface for importing instance state data. This abstraction allows different storage backends to implement their own import logic with optimal performance characteristics.\n\n","path":"github.com/newstack-cloud/deploy-cli-sdk/stateio","name":"stateio","synopsis":"","isRedistributable":true}
