@@ -14,135 +14,318 @@ type StateStoreMetadata struct {
1414 TypeName string
1515}
1616
17- // StateStoreServer is an interface containing the methods an list resource
18- // implementation needs to fill.
17+ // StateStoreServer is an interface containing the methods a state store implementation needs to fill.
1918type StateStoreServer interface {
20- // ValidateStateStoreConfig performs configuration validation
19+ // ValidateStateStoreConfig performs configuration validation for the state store.
2120 ValidateStateStoreConfig (context.Context , * ValidateStateStoreConfigRequest ) (* ValidateStateStoreConfigResponse , error )
2221
23- // ConfigureStateStore configures the state store, such as S3 connection in the context of already configured provider
22+ // ConfigureStateStore is called to pass the user-specified state store configuration to the provider, typically to store
23+ // and reference in future RPC calls.
2424 ConfigureStateStore (context.Context , * ConfigureStateStoreRequest ) (* ConfigureStateStoreResponse , error )
2525
26- // ReadStateBytes streams byte chunks of a given state file from a state store
26+ // ReadStateBytes returns a stream of byte chunks, for a given state, from a state store. The size of the byte chunks
27+ // are negotiated between Terraform and the provider in the ConfigureStateStore RPC.
2728 ReadStateBytes (context.Context , * ReadStateBytesRequest ) (* ReadStateBytesStream , error )
2829
30+ // WriteStateBytes receives a stream of byte chunks, for a given state, from Terraform to persist. The size of the
31+ // byte chunks are negotiated between Terraform and the provider in the ConfigureStateStore RPC.
2932 WriteStateBytes (context.Context , * WriteStateBytesStream ) (* WriteStateBytesResponse , error )
3033
31- // GetStates returns a list of all states (i.e. CE workspaces) managed by a given state store
34+ // GetStates returns a list of all states (i.e. CE workspaces) managed by a given state store.
3235 GetStates (context.Context , * GetStatesRequest ) (* GetStatesResponse , error )
3336
34- // DeleteState instructs a given state store to delete a specific state (i.e. a CE workspace)
37+ // DeleteState instructs a given state store to delete a specific state. (i.e. a CE workspace)
3538 DeleteState (context.Context , * DeleteStateRequest ) (* DeleteStateResponse , error )
3639
37- // LockState instructs a given state store to lock a specific state (i.e. a CE workspace)
40+ // LockState instructs a given state store to lock a specific state. (i.e. a CE workspace)
3841 LockState (context.Context , * LockStateRequest ) (* LockStateResponse , error )
3942
40- // UnlockState instructs a given state store to unlock a specific state (i.e. a CE workspace)
43+ // UnlockState instructs a given state store to unlock a specific state. (i.e. a CE workspace)
4144 UnlockState (context.Context , * UnlockStateRequest ) (* UnlockStateResponse , error )
4245}
4346
47+ // ValidateStateStoreConfigRequest is the request Terraform sends when it
48+ // wants to validate a state store's configuration.
4449type ValidateStateStoreConfigRequest struct {
50+ // TypeName is the name of the state store.
4551 TypeName string
46- Config * DynamicValue
52+
53+ // Config is the configuration the user supplied for the state store. See
54+ // the documentation on `DynamicValue` for more information about
55+ // safely accessing the configuration.
56+ //
57+ // The configuration is represented as a tftypes.Object, with each
58+ // attribute and nested block getting its own key and value.
59+ Config * DynamicValue
4760}
4861
62+ // ValidateStateStoreConfigResponse is the response from the provider about
63+ // the validity of a state store's configuration.
4964type ValidateStateStoreConfigResponse struct {
65+ // Diagnostics report errors or warnings related to the given
66+ // configuration. Returning an empty slice indicates a successful
67+ // validation with no warnings or errors generated.
5068 Diagnostics []* Diagnostic
5169}
5270
71+ // ConfigureStateStoreRequest is the request Terraform sends to supply the
72+ // provider with information about what the user entered in the state store's
73+ // configuration block as well as negotiate capabilities with the state store implementation.
74+ // This allows the provider to store and reference this information in future RPC calls.
5375type ConfigureStateStoreRequest struct {
54- TypeName string
55- Config * DynamicValue
76+ // TypeName is the name of the state store.
77+ TypeName string
78+
79+ // Config is the configuration the user supplied for the state store. This
80+ // information should usually be persisted to the underlying type
81+ // that's implementing the StateStoreServer interface, for use in later
82+ // RPC requests. See the documentation on `DynamicValue` for more
83+ // information about safely accessing the configuration.
84+ //
85+ // The configuration is represented as a tftypes.Object, with each
86+ // attribute and nested block getting its own key and value.
87+ Config * DynamicValue
88+
89+ // Capabilities defines protocol features for the ConfigureStateStore RPC,
90+ // such as forward-compatible Terraform behavior changes and size limitations
91+ // for the client.
5692 Capabilities * ConfigureStateStoreClientCapabilities
5793}
5894
95+ // ConfigureStateStoreResponse is the response from the provider about the
96+ // state store configuration that Terraform supplied for the provider and
97+ // the state store's capabilities.
5998type ConfigureStateStoreResponse struct {
60- Diagnostics []* Diagnostic
99+ // Diagnostics report errors or warnings related to the state store's
100+ // configuration. Returning an empty slice indicates success, with no
101+ // errors or warnings generated.
102+ Diagnostics []* Diagnostic
103+
104+ // Capabilities defines protocol features for the ConfigureStateStore RPC,
105+ // such as forward-compatible Terraform behavior changes and size limitations
106+ // for the server (state store implementation).
61107 Capabilities * StateStoreServerCapabilities
62108}
63109
110+ // StateStoreServerCapabilities allows providers to communicate supported
111+ // protocol features related to state stores, such as forward-compatible
112+ // Terraform behavior changes. StateStoreServerCapabilities is also used to communicate
113+ // the provider chosen chunk size for future state store operations with Terraform.
64114type StateStoreServerCapabilities struct {
65- ChunkSize int64 // chosen chunk size by plugin
115+ // ChunkSize is the provider-chosen size of state byte chunks that will be sent between Terraform and
116+ // the provider in the ReadStateBytes and WriteStateBytes RPC calls. In most cases, provider implementations
117+ // can simply accept the provided ChunkSize from the client [ConfigureStateStoreRequest.Capabilities] request,
118+ // which for Terraform, will default to 8 MB.
119+ ChunkSize int64
66120}
67121
122+ // ReadStateBytesRequest is the request Terraform sends when Terraform needs to read state
123+ // from a configured state store.
68124type ReadStateBytesRequest struct {
125+ // TypeName is the name of the state store.
69126 TypeName string
70- StateID string
127+
128+ // StateID is the ID of the state to read.
129+ //
130+ // Typically this is the name of the Terraform workspace the practitioner is
131+ // running Terraform in: https://developer.hashicorp.com/terraform/language/state/workspaces
132+ StateID string
71133}
72134
135+ // ReadStateBytesStream represents a streaming response to a ReadStateBytesRequest. The provider should
136+ // set a Chunks iterator function that pushes state byte chunks of type ReadStateByteChunk.
73137type ReadStateBytesStream struct {
138+ // Chunks is an iterator for returning state bytes, which can be chunked into smaller pieces if the overall size of the state
139+ // exceeds the max chunk size negotiated during ConfigureStateStore. Each chunk will be immediately sent to Terraform when
140+ // pushed to the iterator.
141+ //
142+ // Diagnostics that occur during the read operation can be returned by sending a chunk
143+ // with [ReadStateByteChunk.Diagnostics] set. Chunk sizes should not exceed the returned
144+ // ChunkSize capability during the ConfigureStateStore RPC.
74145 Chunks iter.Seq [ReadStateByteChunk ]
75146}
76147
148+ // ReadStateByteChunk is a chunk of state byte data streamed from the provider to Terraform during the ReadStateBytes RPC.
149+ //
150+ // Diagnostics that occur during the read operation can be returned by setting the
151+ // [ReadStateByteChunk.Diagnostics] field with no StateByteChunk data. The chunk size
152+ // should not exceed the returned ChunkSize capability during the ConfigureStateStore RPC.
153+ type ReadStateByteChunk struct {
154+ // StateByteChunk contains all of the necessary information about a chunk of state byte data.
155+ StateByteChunk
156+
157+ // Diagnostics report errors or warnings related to retrieving the
158+ // state represented by the given state ID. Returning an empty slice
159+ // indicates success, with no errors or warnings generated.
160+ //
161+ // As diagnostics can be returned with each chunk, the error or warning can
162+ // be related to either the entire state or state store (returned with the first chunk), or
163+ // related to a specific chunk of data in the state.
164+ Diagnostics []* Diagnostic
165+ }
166+
167+ // StateByteChunk represents a chunk of state byte data.
168+ type StateByteChunk struct {
169+ // Bytes represents the state data for this chunk.
170+ Bytes []byte
171+
172+ // TotalLength is the overall size of all of the state byte chunks that will be sent or received
173+ // for a given state.
174+ TotalLength int64
175+
176+ // Range represents the start and end location of the [Bytes] for this chunk, in the context of
177+ // all of the chunks sent or received for a given state.
178+ Range StateByteRange
179+ }
180+
181+ // StateByteRange represents the start and end location for a [StateByteChunk] in the context of
182+ // all of the chunks sent or received for a given state.
183+ type StateByteRange struct {
184+ // Start is the starting byte index for a [StateByteChunk].
185+ Start int64
186+
187+ // End is the ending byte index for a [StateByteChunk].
188+ End int64
189+ }
190+
191+ // WriteStateBytesStream represents a stream of state byte data sent from Terraform to the provider when it requests state be
192+ // written to a configured state store. The iterator will continue producing [WriteStateBytesChunk] until all chunks have been
193+ // sent from Terraform.
77194type WriteStateBytesStream struct {
195+ // Chunks represents a stream of state byte data chunks produced by Terraform. Consumers of this iterator should
196+ // always check the diagnostics before reading the [WriteStateBytesChunk] data. Diagnostics produced by this iterator would
197+ // indicate either invalid chunk data or GRPC communication errors.
78198 Chunks iter.Seq2 [* WriteStateBytesChunk , []* Diagnostic ]
79199}
80200
81- // WriteStateBytesChunk contains a chunk of state data, received from Terraform core to be persisted.
201+ // WriteStateBytesChunk is a chunk of state byte data, received from Terraform to be persisted. The chunk size should not exceed the returned
202+ // ChunkSize capability during the ConfigureStateStore RPC.
82203type WriteStateBytesChunk struct {
204+ // Meta contains additional information about the WriteStateBytes RPC call necessary for routing the request in a provider.
205+ //
206+ // This field is only set with the first chunk sent from Terraform.
83207 Meta * WriteStateChunkMeta
208+
209+ // StateByteChunk contains all of the necessary information about a chunk of state byte data.
84210 StateByteChunk
85211}
86212
213+ // WriteStateChunkMeta represents the additional information communicated during a WriteStateBytes RPC call. This information
214+ // is required by providers to route the request and persist the state byte data with the corresponding state ID.
87215type WriteStateChunkMeta struct {
216+ // TypeName is the name of the state store.
88217 TypeName string
89- StateID string
90- }
91218
92- type WriteStateBytesResponse struct {
93- Diagnostics []* Diagnostic
219+ // StateID is the ID of the state to write.
220+ //
221+ // Typically this is the name of the Terraform workspace the practitioner is
222+ // running Terraform in: https://developer.hashicorp.com/terraform/language/state/workspaces
223+ StateID string
94224}
95225
96- type ReadStateByteChunk struct {
97- StateByteChunk
226+ // WriteStateBytesResponse is the response from the provider after writing all chunks streamed from
227+ // Terraform in a [WriteStateBytesStream] to a given state.
228+ type WriteStateBytesResponse struct {
229+ // Diagnostics report errors or warnings related to writing the
230+ // state represented by the given state ID. Returning an empty slice
231+ // indicates success, with no errors or warnings generated.
98232 Diagnostics []* Diagnostic
99233}
100234
101- type StateByteChunk struct {
102- Bytes []byte
103- TotalLength int64
104- Range StateByteRange
105- }
106-
107- type StateByteRange struct {
108- Start , End int64
109- }
110-
235+ // GetStatesRequest is the request Terraform sends when it needs to retrieve all peristed states
236+ // in a configured state store.
111237type GetStatesRequest struct {
238+ // TypeName is the name of the state store.
112239 TypeName string
113240}
114241
242+ // GetStatesResponse is the response from the provider when retrieving all peristed states in a configured
243+ // state store.
115244type GetStatesResponse struct {
116- StateIDs []string
245+ // StateIDs is a list of the states persisted to the configured state store.
246+ //
247+ // Typically these are the names of the Terraform workspaces the practitioner has persisted
248+ // in the state store: https://developer.hashicorp.com/terraform/language/state/workspaces
249+ StateIDs []string
250+
251+ // Diagnostics report errors or warnings related to retrieving all
252+ // state IDs stored by the configured state store. Returning an empty
253+ // slice indicates success, with no errors or warnings generated.
117254 Diagnostics []* Diagnostic
118255}
119256
257+ // DeleteStateRequest is the request Terraform sends when it needs to delete a given state
258+ // in a configured state store.
120259type DeleteStateRequest struct {
260+ // TypeName is the name of the state store.
121261 TypeName string
122- StateID string
262+
263+ // StateID is the ID of the state to delete.
264+ //
265+ // Typically this is the name of the Terraform workspace the practitioner is
266+ // running Terraform in: https://developer.hashicorp.com/terraform/language/state/workspaces
267+ StateID string
123268}
124269
270+ // DeleteStateResponse is the response from the provider after deleting a state in the configured state store.
125271type DeleteStateResponse struct {
272+ // Diagnostics report errors or warnings related to deleting the state
273+ // represented by the given state ID. Returning an empty slice indicates
274+ // success, with no errors or warnings generated.
126275 Diagnostics []* Diagnostic
127276}
128277
278+ // LockStateRequest is the request Terraform sends when it needs to lock a given state in a configured state store.
129279type LockStateRequest struct {
130- TypeName string
131- StateID string
280+ // TypeName is the name of the state store.
281+ TypeName string
282+
283+ // StateID is the ID of the state to lock.
284+ //
285+ // Typically this is the name of the Terraform workspace the practitioner is
286+ // running Terraform in: https://developer.hashicorp.com/terraform/language/state/workspaces
287+ StateID string
288+
289+ // Operation is a string representing the type of operation Terraform is currently running. (refresh, plan, apply, etc.)
132290 Operation string
133291}
134292
293+ // LockStateResponse is the response from the provider after locking a state in a configured state store.
135294type LockStateResponse struct {
136- LockID string
295+ // LockID is an opaque string representing a new lock that has been persisted in the configured state store
296+ // for a given state. LockID is determined by the provider and will be passed to [UnlockStateRequest.LockID]
297+ // to release the lock.
298+ //
299+ // If the lock already exists, the provider should return an error diagnostic.
300+ LockID string
301+
302+ // Diagnostics report errors or warnings related to locking the state
303+ // represented by the given state ID. Returning an empty slice indicates
304+ // success, with no errors or warnings generated.
137305 Diagnostics []* Diagnostic
138306}
139307
308+ // UnlockStateRequest is the request Terraform sends when it needs to unlock a given state in a configured state store.
140309type UnlockStateRequest struct {
310+ // TypeName is the name of the state store.
141311 TypeName string
142- StateID string
143- LockID string
312+
313+ // StateID is the ID of the state to unlock.
314+ //
315+ // Typically this is the name of the Terraform workspace the practitioner is
316+ // running Terraform in: https://developer.hashicorp.com/terraform/language/state/workspaces
317+ StateID string
318+
319+ // LockID is the ID of the lock to be released (unlocked) for a given state in the configured state store.
320+ // This is the same value that is returned when originally acquiring the lock from the LockState RPC call,
321+ // i.e. the [LockStateResponse.LockID] field.
322+ LockID string
144323}
145324
325+ // UnlockStateResponse is the response from the provider after unlocking a state in the configured state store.
146326type UnlockStateResponse struct {
327+ // Diagnostics report errors or warnings related to unlocking the state
328+ // represented by the given state ID. Returning an empty slice indicates
329+ // success, with no errors or warnings generated.
147330 Diagnostics []* Diagnostic
148331}
0 commit comments