chore: add command ctx to GetRootOutputValues

pull/35143/head
Brandon Croft 2 years ago
parent e40bb9b018
commit 716fcce239
No known key found for this signature in database
GPG Key ID: B01E32423322EB9D

@ -4,6 +4,7 @@
package local
import (
"context"
"fmt"
"os"
"path/filepath"
@ -261,7 +262,7 @@ func (s *stateStorageThatFailsRefresh) State() *states.State {
return nil
}
func (s *stateStorageThatFailsRefresh) GetRootOutputValues() (map[string]*states.OutputValue, error) {
func (s *stateStorageThatFailsRefresh) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
return nil, fmt.Errorf("unimplemented")
}

@ -515,8 +515,7 @@ func (s *State) Delete(force bool) error {
}
// GetRootOutputValues fetches output values from HCP Terraform
func (s *State) GetRootOutputValues() (map[string]*states.OutputValue, error) {
ctx := context.Background()
func (s *State) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
so, err := s.tfeClient.StateVersionOutputs.ReadCurrent(ctx, s.workspace.ID)

@ -40,7 +40,7 @@ func TestState_GetRootOutputValues(t *testing.T) {
state := &State{tfeClient: b.client, organization: b.Organization, workspace: &tfe.Workspace{
ID: "ws-abcd",
}}
outputs, err := state.GetRootOutputValues()
outputs, err := state.GetRootOutputValues(context.Background())
if err != nil {
t.Fatalf("error returned from GetRootOutputValues: %s", err)

@ -69,6 +69,10 @@ func (c *OutputCommand) Outputs(statePath string) (map[string]*states.OutputValu
return nil, diags
}
// Command can be aborted by interruption signals
ctx, done := c.InterruptibleContext(c.CommandContext())
defer done()
// This is a read-only command
c.ignoreRemoteVersionConflict(b)
@ -85,7 +89,7 @@ func (c *OutputCommand) Outputs(statePath string) (map[string]*states.OutputValu
return nil, diags
}
output, err := stateStore.GetRootOutputValues()
output, err := stateStore.GetRootOutputValues(ctx)
if err != nil {
return nil, diags.Append(err)
}

@ -5,6 +5,7 @@ package remote
import (
"bytes"
"context"
"fmt"
"log"
"sync"
@ -59,7 +60,7 @@ func (s *State) State() *states.State {
return s.state.DeepCopy()
}
func (s *State) GetRootOutputValues() (map[string]*states.OutputValue, error) {
func (s *State) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
if err := s.RefreshState(); err != nil {
return nil, fmt.Errorf("Failed to load state: %s", err)
}

@ -4,6 +4,7 @@
package remote
import (
"context"
"log"
"sync"
"testing"
@ -408,7 +409,7 @@ func TestState_GetRootOutputValues(t *testing.T) {
},
}
outputs, err := mgr.GetRootOutputValues()
outputs, err := mgr.GetRootOutputValues(context.Background())
if err != nil {
t.Errorf("Expected GetRootOutputValues to not return an error, but it returned %v", err)
}

@ -5,6 +5,7 @@ package statemgr
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@ -236,7 +237,7 @@ func (s *Filesystem) RefreshState() error {
return s.refreshState()
}
func (s *Filesystem) GetRootOutputValues() (map[string]*states.OutputValue, error) {
func (s *Filesystem) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
err := s.RefreshState()
if err != nil {
return nil, err

@ -4,6 +4,7 @@
package statemgr
import (
"context"
"io/ioutil"
"os"
"os/exec"
@ -417,7 +418,7 @@ func TestFilesystem_refreshWhileLocked(t *testing.T) {
func TestFilesystem_GetRootOutputValues(t *testing.T) {
fs := testFilesystem(t)
outputs, err := fs.GetRootOutputValues()
outputs, err := fs.GetRootOutputValues(context.Background())
if err != nil {
t.Errorf("Expected GetRootOutputValues to not return an error, but it returned %v", err)
}

@ -4,6 +4,8 @@
package statemgr
import (
"context"
"github.com/hashicorp/terraform/internal/schemarepo"
"github.com/hashicorp/terraform/internal/states"
)
@ -21,8 +23,8 @@ func (s *LockDisabled) State() *states.State {
return s.Inner.State()
}
func (s *LockDisabled) GetRootOutputValues() (map[string]*states.OutputValue, error) {
return s.Inner.GetRootOutputValues()
func (s *LockDisabled) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
return s.Inner.GetRootOutputValues(ctx)
}
func (s *LockDisabled) WriteState(v *states.State) error {

@ -4,6 +4,7 @@
package statemgr
import (
"context"
"time"
version "github.com/hashicorp/go-version"
@ -33,7 +34,7 @@ type Persistent interface {
// to differentiate reading the state and reading the outputs within the state.
type OutputReader interface {
// GetRootOutputValues fetches the root module output values from state or another source
GetRootOutputValues() (map[string]*states.OutputValue, error)
GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error)
}
// Refresher is the interface for managers that can read snapshots from

@ -4,6 +4,7 @@
package statemgr
import (
"context"
"errors"
"sync"
@ -69,7 +70,7 @@ func (m *fakeFull) PersistState(schemas *schemarepo.Schemas) error {
return m.fakeP.WriteState(m.t.State())
}
func (m *fakeFull) GetRootOutputValues() (map[string]*states.OutputValue, error) {
func (m *fakeFull) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
return m.State().RootOutputValues, nil
}
@ -119,7 +120,7 @@ func (m *fakeErrorFull) State() *states.State {
return nil
}
func (m *fakeErrorFull) GetRootOutputValues() (map[string]*states.OutputValue, error) {
func (m *fakeErrorFull) GetRootOutputValues(ctx context.Context) (map[string]*states.OutputValue, error) {
return nil, errors.New("fake state manager error")
}

Loading…
Cancel
Save