Skip to content

Commit d7cb4cb

Browse files
committed
feat: A plan file will report the state storage provider among its required providers, if PSS is in use.
See the code comment added in this commit. This addition does not impact an apply command as the missing provider will be detected before this code is executed. However I'm making this change so that the method is still accurate is being able to return a complete list of providers needed by the plan.
1 parent 4cee419 commit d7cb4cb

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

internal/plans/plan.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,30 @@ func (p *Plan) ProviderAddrs() []addrs.AbsProviderConfig {
181181
}
182182

183183
m := map[string]addrs.AbsProviderConfig{}
184+
185+
// Get all provider requirements from resources.
184186
for _, rc := range p.Changes.Resources {
185187
m[rc.ProviderAddr.String()] = rc.ProviderAddr
186188
}
189+
190+
// Get the provider required for pluggable state storage, if that's in use.
191+
//
192+
// This check should be redundant as:
193+
// 1) Any provider used for state storage would be in required_providers, which is checked separately elsewhere.
194+
// 2) An apply operation that uses the planfile only checks the providers needed for the plan _after_ the operations backend
195+
// for the operation is set up, and that process will detect if the provider needed for state storage is missing.
196+
//
197+
// However, for completeness when describing the providers needed by a plan, it is included here.
198+
if !p.StateStore.Empty() {
199+
address := addrs.AbsProviderConfig{
200+
Module: addrs.RootModule, // A state_store block is only ever in the root module
201+
Provider: *p.StateStore.Provider.Source,
202+
// Alias: aliases are not permitted when using a provider for PSS.
203+
}
204+
205+
m[p.StateStore.Provider.Source.String()] = address
206+
}
207+
187208
if len(m) == 0 {
188209
return nil
189210
}

internal/plans/plan_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,33 @@ import (
1515
)
1616

1717
func TestProviderAddrs(t *testing.T) {
18+
// Inputs for plan
19+
provider := &Provider{}
20+
err := provider.SetSource("registry.terraform.io/hashicorp/pluggable")
21+
if err != nil {
22+
panic(err)
23+
}
24+
err = provider.SetVersion("9.9.9")
25+
if err != nil {
26+
panic(err)
27+
}
28+
config, err := NewDynamicValue(cty.ObjectVal(map[string]cty.Value{
29+
"foo": cty.StringVal("bar"),
30+
}), cty.Object(map[string]cty.Type{
31+
"foo": cty.String,
32+
}))
33+
if err != nil {
34+
panic(err)
35+
}
1836

1937
// Prepare plan
2038
plan := &Plan{
39+
StateStore: StateStore{
40+
Type: "pluggable_foobar",
41+
Provider: provider,
42+
Config: config,
43+
Workspace: "default",
44+
},
2145
VariableValues: map[string]DynamicValue{},
2246
Changes: &ChangesSrc{
2347
Resources: []*ResourceInstanceChangeSrc{
@@ -70,6 +94,11 @@ func TestProviderAddrs(t *testing.T) {
7094
Module: addrs.RootModule,
7195
Provider: addrs.NewDefaultProvider("test"),
7296
},
97+
// Provider used for pluggable state storage
98+
{
99+
Module: addrs.RootModule,
100+
Provider: addrs.NewDefaultProvider("pluggable"),
101+
},
73102
}
74103

75104
for _, problem := range deep.Equal(got, want) {

0 commit comments

Comments
 (0)