Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Include provider config when writing a plan file using pluggable…
… state storage
  • Loading branch information
SarahFrench committed Dec 2, 2025
commit aaffae2661e30c57df4739f4dbdde821dcb81c4e
13 changes: 9 additions & 4 deletions internal/backend/local/backend_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,20 +940,25 @@ func TestLocal_plan_withStateStore(t *testing.T) {
op.PlanMode = plans.NormalMode
op.PlanRefresh = true
op.PlanOutPath = planPath
cfg := cty.ObjectVal(map[string]cty.Value{
storeCfg := cty.ObjectVal(map[string]cty.Value{
"path": cty.StringVal(b.StatePath),
})
cfgRaw, err := plans.NewDynamicValue(cfg, cfg.Type())
storeCfgRaw, err := plans.NewDynamicValue(storeCfg, storeCfg.Type())
if err != nil {
t.Fatal(err)
}
providerCfg := cty.ObjectVal(map[string]cty.Value{}) // Empty as the mock provider has no schema for the provider
providerCfgRaw, err := plans.NewDynamicValue(providerCfg, providerCfg.Type())
if err != nil {
t.Fatal(err)
}
op.PlanOutStateStore = &plans.StateStore{
Type: storeType,
Config: cfgRaw,
Config: storeCfgRaw,
Provider: &plans.Provider{
Source: &mockAddr,
Version: providerVersion,
// No config as the mock provider has no schema for the provider
Config: providerCfgRaw,
},
Workspace: defaultWorkspace,
}
Expand Down
18 changes: 13 additions & 5 deletions internal/plans/planfile/tfplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ func readTfplan(r io.Reader) (*plans.Plan, error) {
}
case rawPlan.StateStore != nil:
rawStateStore := rawPlan.StateStore
config, err := valueFromTfplan(rawStateStore.Config)
if err != nil {
return nil, fmt.Errorf("plan file has invalid state_store configuration: %s", err)
}

provider := &plans.Provider{}
err = provider.SetSource(rawStateStore.Provider.Source)
if err != nil {
Expand All @@ -242,11 +239,21 @@ func readTfplan(r io.Reader) (*plans.Plan, error) {
if err != nil {
return nil, fmt.Errorf("plan file has invalid state_store provider version: %s", err)
}
providerConfig, err := valueFromTfplan(rawStateStore.Provider.Config)
if err != nil {
return nil, fmt.Errorf("plan file has invalid state_store configuration: %s", err)
}
provider.Config = providerConfig

storeConfig, err := valueFromTfplan(rawStateStore.Config)
if err != nil {
return nil, fmt.Errorf("plan file has invalid state_store configuration: %s", err)
}

plan.StateStore = &plans.StateStore{
Type: rawStateStore.Type,
Provider: provider,
Config: config,
Config: storeConfig,
Workspace: rawStateStore.Workspace,
}
}
Expand Down Expand Up @@ -759,6 +766,7 @@ func writeTfplan(plan *plans.Plan, w io.Writer) error {
Provider: &planproto.Provider{
Version: plan.StateStore.Provider.Version.String(),
Source: plan.StateStore.Provider.Source.String(),
Config: valueToTfplan(plan.StateStore.Provider.Config),
},
Config: valueToTfplan(plan.StateStore.Config),
Workspace: plan.StateStore.Workspace,
Expand Down
14 changes: 14 additions & 0 deletions internal/plans/planfile/tfplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ func TestTFPlanRoundTrip(t *testing.T) {
Namespace: "foobar",
Type: "foo",
},
// Imagining a provider that has nothing in its schema
Config: mustNewDynamicValue(
cty.EmptyObjectVal,
cty.Object(nil),
),
},
// Imagining a state store with a field called `foo` in its schema
Config: mustNewDynamicValue(
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
Expand Down Expand Up @@ -136,6 +142,14 @@ func Test_writeTfplan_validation(t *testing.T) {
Namespace: "foobar",
Type: "foo",
},
Config: mustNewDynamicValue(
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
}),
cty.Object(map[string]cty.Type{
"foo": cty.String,
}),
),
},
Config: mustNewDynamicValue(
cty.ObjectVal(map[string]cty.Value{
Expand Down
86 changes: 48 additions & 38 deletions internal/plans/planproto/planfile.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/plans/planproto/planfile.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ message StateStore {
message Provider {
string source = 1;
string version = 2;
DynamicValue config = 3;
}

// Action describes the type of action planned for an object.
Expand Down