Skip to content

Commit 9d43b8e

Browse files
committed
refactor: Move chunk size limit constants to new chunks package
1 parent 053738f commit 9d43b8e

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

internal/backend/pluggable/chunks.go renamed to internal/backend/pluggable/chunks/chunks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: BUSL-1.1
33

4-
package pluggable
4+
package chunks
55

66
const (
77
// DefaultStateStoreChunkSize is the default chunk size proposed

internal/backend/pluggable/pluggable.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88

99
"github.com/hashicorp/terraform/internal/backend"
10+
"github.com/hashicorp/terraform/internal/backend/pluggable/chunks"
1011
"github.com/hashicorp/terraform/internal/configs/configschema"
1112
"github.com/hashicorp/terraform/internal/providers"
1213
"github.com/hashicorp/terraform/internal/states/remote"
@@ -106,7 +107,8 @@ func (p *Pluggable) Configure(config cty.Value) tfdiags.Diagnostics {
106107
TypeName: p.typeName,
107108
Config: config,
108109
Capabilities: providers.StateStoreClientCapabilities{
109-
ChunkSize: DefaultStateStoreChunkSize,
110+
// The core binary will always request the default chunk size from the provider to start
111+
ChunkSize: chunks.DefaultStateStoreChunkSize,
110112
},
111113
}
112114
resp := p.provider.ConfigureStateStore(req)

internal/command/meta_backend.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
backendInit "github.com/hashicorp/terraform/internal/backend/init"
3232
backendLocal "github.com/hashicorp/terraform/internal/backend/local"
3333
backendPluggable "github.com/hashicorp/terraform/internal/backend/pluggable"
34+
"github.com/hashicorp/terraform/internal/backend/pluggable/chunks"
3435
"github.com/hashicorp/terraform/internal/cloud"
3536
"github.com/hashicorp/terraform/internal/command/arguments"
3637
"github.com/hashicorp/terraform/internal/command/clistate"
@@ -2071,7 +2072,7 @@ func (m *Meta) savedStateStore(sMgr *clistate.LocalState, factory providers.Fact
20712072
TypeName: s.StateStore.Type,
20722073
Config: stateStoreConfigVal,
20732074
Capabilities: providers.StateStoreClientCapabilities{
2074-
ChunkSize: backendPluggable.DefaultStateStoreChunkSize,
2075+
ChunkSize: chunks.DefaultStateStoreChunkSize,
20752076
},
20762077
})
20772078
diags = diags.Append(cfgStoreResp.Diagnostics)
@@ -2080,10 +2081,10 @@ func (m *Meta) savedStateStore(sMgr *clistate.LocalState, factory providers.Fact
20802081
}
20812082

20822083
chunkSize := cfgStoreResp.Capabilities.ChunkSize
2083-
if chunkSize == 0 || chunkSize > backendPluggable.MaxStateStoreChunkSize {
2084+
if chunkSize == 0 || chunkSize > chunks.MaxStateStoreChunkSize {
20842085
diags = diags.Append(fmt.Errorf("Failed to negotiate acceptable chunk size. "+
20852086
"Expected size > 0 and <= %d bytes, provider wants %d bytes",
2086-
backendPluggable.MaxStateStoreChunkSize, chunkSize,
2087+
chunks.MaxStateStoreChunkSize, chunkSize,
20872088
))
20882089
return nil, diags
20892090
}

internal/grpcwrap/provider6.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
"google.golang.org/grpc/status"
1919
"google.golang.org/protobuf/types/known/timestamppb"
2020

21+
"github.com/hashicorp/terraform/internal/backend/pluggable/chunks"
2122
proto6 "github.com/hashicorp/terraform/internal/tfplugin6"
2223

23-
backendPluggable "github.com/hashicorp/terraform/internal/backend/pluggable"
2424
"github.com/hashicorp/terraform/internal/plugin6/convert"
2525
"github.com/hashicorp/terraform/internal/providers"
2626
"github.com/hashicorp/terraform/internal/tfplugin6"
@@ -966,17 +966,17 @@ func (p *provider6) ConfigureStateStore(ctx context.Context, req *tfplugin6.Conf
966966
TypeName: req.TypeName,
967967
Config: configVal,
968968
Capabilities: providers.StateStoreClientCapabilities{
969-
ChunkSize: backendPluggable.DefaultStateStoreChunkSize,
969+
ChunkSize: chunks.DefaultStateStoreChunkSize,
970970
},
971971
})
972972

973973
// Validate the returned chunk size value
974-
if configureResp.Capabilities.ChunkSize == 0 || configureResp.Capabilities.ChunkSize > backendPluggable.MaxStateStoreChunkSize {
974+
if configureResp.Capabilities.ChunkSize == 0 || configureResp.Capabilities.ChunkSize > chunks.MaxStateStoreChunkSize {
975975
diag := &tfplugin6.Diagnostic{
976976
Severity: tfplugin6.Diagnostic_ERROR,
977977
Summary: "Failed to negotiate acceptable chunk size",
978978
Detail: fmt.Sprintf("Expected size > 0 and <= %d bytes, provider wants %d bytes",
979-
backendPluggable.MaxStateStoreChunkSize, configureResp.Capabilities.ChunkSize),
979+
chunks.MaxStateStoreChunkSize, configureResp.Capabilities.ChunkSize),
980980
}
981981
resp.Diagnostics = append(resp.Diagnostics, diag)
982982
return resp, nil

0 commit comments

Comments
 (0)