Skip to content

Commit 716fcce

Browse files
committed
chore: add command ctx to GetRootOutputValues
1 parent e40bb9b commit 716fcce

File tree

11 files changed

+26
-14
lines changed

11 files changed

+26
-14
lines changed

internal/backend/local/backend_local_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package local
55

66
import (
7+
"context"
78
"fmt"
89
"os"
910
"path/filepath"
@@ -261,7 +262,7 @@ func (s *stateStorageThatFailsRefresh) State() *states.State {
261262
return nil
262263
}
263264

264-
func (s *stateStorageThatFailsRefresh) GetRootOutputValues() (map[string]*states.OutputValue, error) {
265+
func (s *stateStorageThatFailsRefresh) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
265266
return nil, fmt.Errorf("unimplemented")
266267
}
267268

internal/cloud/state.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,7 @@ func (s *State) Delete(force bool) error {
515515
}
516516

517517
// GetRootOutputValues fetches output values from HCP Terraform
518-
func (s *State) GetRootOutputValues() (map[string]*states.OutputValue, error) {
519-
ctx := context.Background()
518+
func (s *State) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
520519

521520
so, err := s.tfeClient.StateVersionOutputs.ReadCurrent(ctx, s.workspace.ID)
522521

internal/cloud/state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestState_GetRootOutputValues(t *testing.T) {
4040
state := &State{tfeClient: b.client, organization: b.Organization, workspace: &tfe.Workspace{
4141
ID: "ws-abcd",
4242
}}
43-
outputs, err := state.GetRootOutputValues()
43+
outputs, err := state.GetRootOutputValues(context.Background())
4444

4545
if err != nil {
4646
t.Fatalf("error returned from GetRootOutputValues: %s", err)

internal/command/output.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ func (c *OutputCommand) Outputs(statePath string) (map[string]*states.OutputValu
6969
return nil, diags
7070
}
7171

72+
// Command can be aborted by interruption signals
73+
ctx, done := c.InterruptibleContext(c.CommandContext())
74+
defer done()
75+
7276
// This is a read-only command
7377
c.ignoreRemoteVersionConflict(b)
7478

@@ -85,7 +89,7 @@ func (c *OutputCommand) Outputs(statePath string) (map[string]*states.OutputValu
8589
return nil, diags
8690
}
8791

88-
output, err := stateStore.GetRootOutputValues()
92+
output, err := stateStore.GetRootOutputValues(ctx)
8993
if err != nil {
9094
return nil, diags.Append(err)
9195
}

internal/states/remote/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package remote
55

66
import (
77
"bytes"
8+
"context"
89
"fmt"
910
"log"
1011
"sync"
@@ -59,7 +60,7 @@ func (s *State) State() *states.State {
5960
return s.state.DeepCopy()
6061
}
6162

62-
func (s *State) GetRootOutputValues() (map[string]*states.OutputValue, error) {
63+
func (s *State) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
6364
if err := s.RefreshState(); err != nil {
6465
return nil, fmt.Errorf("Failed to load state: %s", err)
6566
}

internal/states/remote/state_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package remote
55

66
import (
7+
"context"
78
"log"
89
"sync"
910
"testing"
@@ -408,7 +409,7 @@ func TestState_GetRootOutputValues(t *testing.T) {
408409
},
409410
}
410411

411-
outputs, err := mgr.GetRootOutputValues()
412+
outputs, err := mgr.GetRootOutputValues(context.Background())
412413
if err != nil {
413414
t.Errorf("Expected GetRootOutputValues to not return an error, but it returned %v", err)
414415
}

internal/states/statemgr/filesystem.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package statemgr
55

66
import (
77
"bytes"
8+
"context"
89
"encoding/json"
910
"errors"
1011
"fmt"
@@ -236,7 +237,7 @@ func (s *Filesystem) RefreshState() error {
236237
return s.refreshState()
237238
}
238239

239-
func (s *Filesystem) GetRootOutputValues() (map[string]*states.OutputValue, error) {
240+
func (s *Filesystem) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
240241
err := s.RefreshState()
241242
if err != nil {
242243
return nil, err

internal/states/statemgr/filesystem_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package statemgr
55

66
import (
7+
"context"
78
"io/ioutil"
89
"os"
910
"os/exec"
@@ -417,7 +418,7 @@ func TestFilesystem_refreshWhileLocked(t *testing.T) {
417418
func TestFilesystem_GetRootOutputValues(t *testing.T) {
418419
fs := testFilesystem(t)
419420

420-
outputs, err := fs.GetRootOutputValues()
421+
outputs, err := fs.GetRootOutputValues(context.Background())
421422
if err != nil {
422423
t.Errorf("Expected GetRootOutputValues to not return an error, but it returned %v", err)
423424
}

internal/states/statemgr/lock.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package statemgr
55

66
import (
7+
"context"
8+
79
"github.com/hashicorp/terraform/internal/schemarepo"
810
"github.com/hashicorp/terraform/internal/states"
911
)
@@ -21,8 +23,8 @@ func (s *LockDisabled) State() *states.State {
2123
return s.Inner.State()
2224
}
2325

24-
func (s *LockDisabled) GetRootOutputValues() (map[string]*states.OutputValue, error) {
25-
return s.Inner.GetRootOutputValues()
26+
func (s *LockDisabled) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
27+
return s.Inner.GetRootOutputValues(ctx)
2628
}
2729

2830
func (s *LockDisabled) WriteState(v *states.State) error {

internal/states/statemgr/persistent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package statemgr
55

66
import (
7+
"context"
78
"time"
89

910
version "github.com/hashicorp/go-version"
@@ -33,7 +34,7 @@ type Persistent interface {
3334
// to differentiate reading the state and reading the outputs within the state.
3435
type OutputReader interface {
3536
// GetRootOutputValues fetches the root module output values from state or another source
36-
GetRootOutputValues() (map[string]*states.OutputValue, error)
37+
GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error)
3738
}
3839

3940
// Refresher is the interface for managers that can read snapshots from

0 commit comments

Comments
 (0)