Skip to content

Commit 508ca1e

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 c8c81c4 commit 508ca1e

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 != nil {
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
@@ -12,9 +12,33 @@ import (
1212
)
1313

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

1634
// Prepare plan
1735
plan := &Plan{
36+
StateStore: &StateStore{
37+
Type: "pluggable_foobar",
38+
Provider: provider,
39+
Config: config,
40+
Workspace: "default",
41+
},
1842
VariableValues: map[string]DynamicValue{},
1943
Changes: &ChangesSrc{
2044
Resources: []*ResourceInstanceChangeSrc{
@@ -67,6 +91,11 @@ func TestProviderAddrs(t *testing.T) {
6791
Module: addrs.RootModule,
6892
Provider: addrs.NewDefaultProvider("test"),
6993
},
94+
// Provider used for pluggable state storage
95+
{
96+
Module: addrs.RootModule,
97+
Provider: addrs.NewDefaultProvider("pluggable"),
98+
},
7099
}
71100

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

0 commit comments

Comments
 (0)