Split Meta back out of StateMeta
Removing the call to StateMeta.Env, so that it doesn't need an embedded Meta field. Embed Meta and StateMeta separately in all State commands.
This commit is contained in:
parent
4dac986a91
commit
39a5ddd381
|
@ -90,7 +90,7 @@ func (c *EnvDeleteCommand) Run(args []string) int {
|
|||
|
||||
// Lock the state if we can
|
||||
lockInfo := state.NewLockInfo()
|
||||
lockInfo.Operation = "env new"
|
||||
lockInfo.Operation = "env delete"
|
||||
lockID, err := clistate.Lock(sMgr, lockInfo, c.Ui, c.Colorize())
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error locking state: %s", err))
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
// StateListCommand is a Command implementation that lists the resources
|
||||
// within a state file.
|
||||
type StateListCommand struct {
|
||||
Meta
|
||||
StateMeta
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,10 @@ func TestStateList(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateListCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -49,12 +47,10 @@ func TestStateList_backendState(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateListCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
|
@ -77,12 +73,10 @@ func TestStateList_noState(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateListCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
|
|
|
@ -11,13 +11,12 @@ import (
|
|||
)
|
||||
|
||||
// StateMeta is the meta struct that should be embedded in state subcommands.
|
||||
type StateMeta struct {
|
||||
Meta
|
||||
}
|
||||
type StateMeta struct{}
|
||||
|
||||
// State returns the state for this meta. This is different then Meta.State
|
||||
// in the way that backups are done. This configures backups to be timestamped
|
||||
// rather than just the original state path plus a backup path.
|
||||
// State returns the state for this meta. This gets the appropriate state from
|
||||
// the backend, but changes the way that backups are done. This configures
|
||||
// backups to be timestamped rather than just the original state path plus a
|
||||
// backup path.
|
||||
func (c *StateMeta) State(m *Meta) (state.State, error) {
|
||||
// Load the backend
|
||||
b, err := m.Backend(nil)
|
||||
|
@ -25,7 +24,7 @@ func (c *StateMeta) State(m *Meta) (state.State, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
env := c.Env()
|
||||
env := m.Env()
|
||||
// Get the state
|
||||
s, err := b.State(env)
|
||||
if err != nil {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
// StateMvCommand is a Command implementation that shows a single resource.
|
||||
type StateMvCommand struct {
|
||||
Meta
|
||||
StateMeta
|
||||
}
|
||||
|
||||
|
|
|
@ -46,12 +46,10 @@ func TestStateMv(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -115,12 +113,10 @@ func TestStateMv_backupExplicit(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -172,12 +168,10 @@ func TestStateMv_stateOutNew(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -246,12 +240,10 @@ func TestStateMv_stateOutExisting(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -289,12 +281,10 @@ func TestStateMv_noState(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"from", "to"}
|
||||
|
@ -352,12 +342,10 @@ func TestStateMv_stateOutNew_count(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -532,12 +520,10 @@ func TestStateMv_stateOutNew_largeCount(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -615,12 +601,10 @@ func TestStateMv_stateOutNew_nestedModule(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateMvCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
// StatePullCommand is a Command implementation that shows a single resource.
|
||||
type StatePullCommand struct {
|
||||
Meta
|
||||
StateMeta
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,10 @@ func TestStatePull(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StatePullCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
// StatePushCommand is a Command implementation that shows a single resource.
|
||||
type StatePushCommand struct {
|
||||
Meta
|
||||
StateMeta
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,10 @@ func TestStatePush_empty(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StatePushCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"replace.tfstate"}
|
||||
|
@ -51,12 +49,10 @@ func TestStatePush_replaceMatch(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StatePushCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"replace.tfstate"}
|
||||
|
@ -82,12 +78,10 @@ func TestStatePush_lineageMismatch(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StatePushCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"replace.tfstate"}
|
||||
|
@ -113,12 +107,10 @@ func TestStatePush_serialNewer(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StatePushCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"replace.tfstate"}
|
||||
|
@ -144,12 +136,10 @@ func TestStatePush_serialOlder(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StatePushCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{"replace.tfstate"}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
// StateRmCommand is a Command implementation that shows a single resource.
|
||||
type StateRmCommand struct {
|
||||
Meta
|
||||
StateMeta
|
||||
}
|
||||
|
||||
|
|
|
@ -46,12 +46,10 @@ func TestStateRm(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateRmCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -114,12 +112,10 @@ func TestStateRm_backupExplicit(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateRmCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -150,12 +146,10 @@ func TestStateRm_noState(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateRmCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
// StateShowCommand is a Command implementation that shows a single resource.
|
||||
type StateShowCommand struct {
|
||||
Meta
|
||||
StateMeta
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,10 @@ func TestStateShow(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateShowCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -94,12 +92,10 @@ func TestStateShow_multi(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateShowCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -118,12 +114,10 @@ func TestStateShow_noState(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateShowCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
|
@ -140,12 +134,10 @@ func TestStateShow_emptyState(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateShowCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -171,12 +163,10 @@ func TestStateShow_emptyStateWithModule(t *testing.T) {
|
|||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &StateShowCommand{
|
||||
StateMeta: StateMeta{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
|
21
commands.go
21
commands.go
|
@ -46,11 +46,6 @@ func init() {
|
|||
"debug": struct{}{}, // includes all subcommands
|
||||
}
|
||||
|
||||
// meta struct used in state commands
|
||||
stateMeta := command.StateMeta{
|
||||
Meta: meta,
|
||||
}
|
||||
|
||||
Commands = map[string]cli.CommandFactory{
|
||||
"apply": func() (cli.Command, error) {
|
||||
return &command.ApplyCommand{
|
||||
|
@ -221,44 +216,42 @@ func init() {
|
|||
},
|
||||
|
||||
"state": func() (cli.Command, error) {
|
||||
return &command.StateCommand{
|
||||
StateMeta: stateMeta,
|
||||
}, nil
|
||||
return &command.StateCommand{}, nil
|
||||
},
|
||||
|
||||
"state list": func() (cli.Command, error) {
|
||||
return &command.StateListCommand{
|
||||
StateMeta: stateMeta,
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
|
||||
"state rm": func() (cli.Command, error) {
|
||||
return &command.StateRmCommand{
|
||||
StateMeta: stateMeta,
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
|
||||
"state mv": func() (cli.Command, error) {
|
||||
return &command.StateMvCommand{
|
||||
StateMeta: stateMeta,
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
|
||||
"state pull": func() (cli.Command, error) {
|
||||
return &command.StatePullCommand{
|
||||
StateMeta: stateMeta,
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
|
||||
"state push": func() (cli.Command, error) {
|
||||
return &command.StatePushCommand{
|
||||
StateMeta: stateMeta,
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
|
||||
"state show": func() (cli.Command, error) {
|
||||
return &command.StateShowCommand{
|
||||
StateMeta: stateMeta,
|
||||
Meta: meta,
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue