Skip to content

Commit 01cd761

Browse files
committed
command: move remote configuration stuff
1 parent a4bc5ba commit 01cd761

8 files changed

Lines changed: 45 additions & 57 deletions

File tree

command/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (c *InitCommand) Run(args []string) int {
120120
}
121121

122122
// Initialize a blank state file with remote enabled
123-
remoteCmd := &RemoteCommand{
123+
remoteCmd := &RemoteConfigCommand{
124124
Meta: c.Meta,
125125
remoteConf: remoteConf,
126126
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ type remoteCommandConfig struct {
2121
backupPath string
2222
}
2323

24-
// RemoteCommand is a Command implementation that is used to
24+
// RemoteConfigCommand is a Command implementation that is used to
2525
// enable and disable remote state management
26-
type RemoteCommand struct {
26+
type RemoteConfigCommand struct {
2727
Meta
2828
conf remoteCommandConfig
2929
remoteConf terraform.RemoteState
3030
}
3131

32-
func (c *RemoteCommand) Run(args []string) int {
32+
func (c *RemoteConfigCommand) Run(args []string) int {
3333
args = c.Meta.process(args, false)
3434
config := make(map[string]string)
3535
cmdFlags := flag.NewFlagSet("remote", flag.ContinueOnError)
@@ -115,7 +115,7 @@ func (c *RemoteCommand) Run(args []string) int {
115115

116116
// disableRemoteState is used to disable remote state management,
117117
// and move the state file into place.
118-
func (c *RemoteCommand) disableRemoteState() int {
118+
func (c *RemoteConfigCommand) disableRemoteState() int {
119119
if c.stateResult == nil {
120120
c.Ui.Error(fmt.Sprintf(
121121
"Internal error. State() must be called internally before remote\n" +
@@ -173,7 +173,7 @@ func (c *RemoteCommand) disableRemoteState() int {
173173

174174
// validateRemoteConfig is used to verify that the remote configuration
175175
// we have is valid
176-
func (c *RemoteCommand) validateRemoteConfig() error {
176+
func (c *RemoteConfigCommand) validateRemoteConfig() error {
177177
conf := c.remoteConf
178178
_, err := remote.NewClient(conf.Type, conf.Config)
179179
if err != nil {
@@ -184,7 +184,7 @@ func (c *RemoteCommand) validateRemoteConfig() error {
184184

185185
// initBlank state is used to initialize a blank state that is
186186
// remote enabled
187-
func (c *RemoteCommand) initBlankState() int {
187+
func (c *RemoteConfigCommand) initBlankState() int {
188188
// Validate the remote configuration
189189
if err := c.validateRemoteConfig(); err != nil {
190190
return 1
@@ -212,7 +212,7 @@ func (c *RemoteCommand) initBlankState() int {
212212

213213
// updateRemoteConfig is used to update the configuration of the
214214
// remote state store
215-
func (c *RemoteCommand) updateRemoteConfig() int {
215+
func (c *RemoteConfigCommand) updateRemoteConfig() int {
216216
// Validate the remote configuration
217217
if err := c.validateRemoteConfig(); err != nil {
218218
return 1
@@ -240,7 +240,7 @@ func (c *RemoteCommand) updateRemoteConfig() int {
240240

241241
// enableRemoteState is used to enable remote state management
242242
// and to move a state file into place
243-
func (c *RemoteCommand) enableRemoteState() int {
243+
func (c *RemoteConfigCommand) enableRemoteState() int {
244244
// Validate the remote configuration
245245
if err := c.validateRemoteConfig(); err != nil {
246246
return 1
@@ -299,7 +299,7 @@ func (c *RemoteCommand) enableRemoteState() int {
299299
return 0
300300
}
301301

302-
func (c *RemoteCommand) Help() string {
302+
func (c *RemoteConfigCommand) Help() string {
303303
helpText := `
304304
Usage: terraform remote [options]
305305
@@ -334,6 +334,6 @@ Options:
334334
return strings.TrimSpace(helpText)
335335
}
336336

337-
func (c *RemoteCommand) Synopsis() string {
337+
func (c *RemoteConfigCommand) Synopsis() string {
338338
return "Configures remote state management"
339339
}

command/pull.go renamed to command/remote_pull.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"github.com/hashicorp/terraform/state"
99
)
1010

11-
type PullCommand struct {
11+
type RemotePullCommand struct {
1212
Meta
1313
}
1414

15-
func (c *PullCommand) Run(args []string) int {
15+
func (c *RemotePullCommand) Run(args []string) int {
1616
args = c.Meta.process(args, false)
1717
cmdFlags := flag.NewFlagSet("pull", flag.ContinueOnError)
1818
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
@@ -67,7 +67,7 @@ func (c *PullCommand) Run(args []string) int {
6767
return 0
6868
}
6969

70-
func (c *PullCommand) Help() string {
70+
func (c *RemotePullCommand) Help() string {
7171
helpText := `
7272
Usage: terraform pull [options]
7373
@@ -77,6 +77,6 @@ Usage: terraform pull [options]
7777
return strings.TrimSpace(helpText)
7878
}
7979

80-
func (c *PullCommand) Synopsis() string {
80+
func (c *RemotePullCommand) Synopsis() string {
8181
return "Refreshes the local state copy from the remote server"
8282
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
"github.com/mitchellh/cli"
1616
)
1717

18-
func TestPull_noRemote(t *testing.T) {
18+
func TestRemotePull_noRemote(t *testing.T) {
1919
tmp, cwd := testCwd(t)
2020
defer testFixCwd(t, tmp, cwd)
2121

2222
ui := new(cli.MockUi)
23-
c := &PullCommand{
23+
c := &RemotePullCommand{
2424
Meta: Meta{
2525
ContextOpts: testCtxConfig(testProvider()),
2626
Ui: ui,
@@ -33,7 +33,7 @@ func TestPull_noRemote(t *testing.T) {
3333
}
3434
}
3535

36-
func TestPull_local(t *testing.T) {
36+
func TestRemotePull_local(t *testing.T) {
3737
tmp, cwd := testCwd(t)
3838
defer testFixCwd(t, tmp, cwd)
3939

@@ -62,7 +62,7 @@ func TestPull_local(t *testing.T) {
6262
}
6363

6464
ui := new(cli.MockUi)
65-
c := &PullCommand{
65+
c := &RemotePullCommand{
6666
Meta: Meta{
6767
ContextOpts: testCtxConfig(testProvider()),
6868
Ui: ui,

command/push.go renamed to command/remote_push.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"github.com/hashicorp/terraform/state"
99
)
1010

11-
type PushCommand struct {
11+
type RemotePushCommand struct {
1212
Meta
1313
}
1414

15-
func (c *PushCommand) Run(args []string) int {
15+
func (c *RemotePushCommand) Run(args []string) int {
1616
var force bool
1717
args = c.Meta.process(args, false)
1818
cmdFlags := flag.NewFlagSet("push", flag.ContinueOnError)
@@ -71,7 +71,7 @@ func (c *PushCommand) Run(args []string) int {
7171
return 0
7272
}
7373

74-
func (c *PushCommand) Help() string {
74+
func (c *RemotePushCommand) Help() string {
7575
helpText := `
7676
Usage: terraform push [options]
7777
@@ -87,6 +87,6 @@ Options:
8787
return strings.TrimSpace(helpText)
8888
}
8989

90-
func (c *PushCommand) Synopsis() string {
90+
func (c *RemotePushCommand) Synopsis() string {
9191
return "Uploads the the local state to the remote server"
9292
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99
"github.com/mitchellh/cli"
1010
)
1111

12-
func TestPush_noRemote(t *testing.T) {
12+
func TestRemotePush_noRemote(t *testing.T) {
1313
tmp, cwd := testCwd(t)
1414
defer testFixCwd(t, tmp, cwd)
1515

1616
ui := new(cli.MockUi)
17-
c := &PushCommand{
17+
c := &RemotePushCommand{
1818
Meta: Meta{
1919
ContextOpts: testCtxConfig(testProvider()),
2020
Ui: ui,
@@ -27,7 +27,7 @@ func TestPush_noRemote(t *testing.T) {
2727
}
2828
}
2929

30-
func TestPush_local(t *testing.T) {
30+
func TestRemotePush_local(t *testing.T) {
3131
tmp, cwd := testCwd(t)
3232
defer testFixCwd(t, tmp, cwd)
3333

@@ -56,7 +56,7 @@ func TestPush_local(t *testing.T) {
5656
}
5757

5858
ui := new(cli.MockUi)
59-
c := &PushCommand{
59+
c := &RemotePushCommand{
6060
Meta: Meta{
6161
ContextOpts: testCtxConfig(testProvider()),
6262
Ui: ui,

command/remote_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
// Test disabling remote management
16-
func TestRemote_disable(t *testing.T) {
16+
func TestRemoteConfig_disable(t *testing.T) {
1717
tmp, cwd := testCwd(t)
1818
defer testFixCwd(t, tmp, cwd)
1919

@@ -39,7 +39,7 @@ func TestRemote_disable(t *testing.T) {
3939
}
4040

4141
ui := new(cli.MockUi)
42-
c := &RemoteCommand{
42+
c := &RemoteConfigCommand{
4343
Meta: Meta{
4444
ContextOpts: testCtxConfig(testProvider()),
4545
Ui: ui,
@@ -68,7 +68,7 @@ func TestRemote_disable(t *testing.T) {
6868
}
6969

7070
// Test disabling remote management without pulling
71-
func TestRemote_disable_noPull(t *testing.T) {
71+
func TestRemoteConfig_disable_noPull(t *testing.T) {
7272
tmp, cwd := testCwd(t)
7373
defer testFixCwd(t, tmp, cwd)
7474

@@ -94,7 +94,7 @@ func TestRemote_disable_noPull(t *testing.T) {
9494
}
9595

9696
ui := new(cli.MockUi)
97-
c := &RemoteCommand{
97+
c := &RemoteConfigCommand{
9898
Meta: Meta{
9999
ContextOpts: testCtxConfig(testProvider()),
100100
Ui: ui,
@@ -122,12 +122,12 @@ func TestRemote_disable_noPull(t *testing.T) {
122122
}
123123

124124
// Test disabling remote management when not enabled
125-
func TestRemote_disable_notEnabled(t *testing.T) {
125+
func TestRemoteConfig_disable_notEnabled(t *testing.T) {
126126
tmp, cwd := testCwd(t)
127127
defer testFixCwd(t, tmp, cwd)
128128

129129
ui := new(cli.MockUi)
130-
c := &RemoteCommand{
130+
c := &RemoteConfigCommand{
131131
Meta: Meta{
132132
ContextOpts: testCtxConfig(testProvider()),
133133
Ui: ui,
@@ -141,7 +141,7 @@ func TestRemote_disable_notEnabled(t *testing.T) {
141141
}
142142

143143
// Test disabling remote management with a state file in the way
144-
func TestRemote_disable_otherState(t *testing.T) {
144+
func TestRemoteConfig_disable_otherState(t *testing.T) {
145145
tmp, cwd := testCwd(t)
146146
defer testFixCwd(t, tmp, cwd)
147147

@@ -171,7 +171,7 @@ func TestRemote_disable_otherState(t *testing.T) {
171171
}
172172

173173
ui := new(cli.MockUi)
174-
c := &RemoteCommand{
174+
c := &RemoteConfigCommand{
175175
Meta: Meta{
176176
ContextOpts: testCtxConfig(testProvider()),
177177
Ui: ui,
@@ -185,7 +185,7 @@ func TestRemote_disable_otherState(t *testing.T) {
185185
}
186186

187187
// Test the case where both managed and non managed state present
188-
func TestRemote_managedAndNonManaged(t *testing.T) {
188+
func TestRemoteConfig_managedAndNonManaged(t *testing.T) {
189189
tmp, cwd := testCwd(t)
190190
defer testFixCwd(t, tmp, cwd)
191191

@@ -215,7 +215,7 @@ func TestRemote_managedAndNonManaged(t *testing.T) {
215215
}
216216

217217
ui := new(cli.MockUi)
218-
c := &RemoteCommand{
218+
c := &RemoteConfigCommand{
219219
Meta: Meta{
220220
ContextOpts: testCtxConfig(testProvider()),
221221
Ui: ui,
@@ -229,12 +229,12 @@ func TestRemote_managedAndNonManaged(t *testing.T) {
229229
}
230230

231231
// Test initializing blank state
232-
func TestRemote_initBlank(t *testing.T) {
232+
func TestRemoteConfig_initBlank(t *testing.T) {
233233
tmp, cwd := testCwd(t)
234234
defer testFixCwd(t, tmp, cwd)
235235

236236
ui := new(cli.MockUi)
237-
c := &RemoteCommand{
237+
c := &RemoteConfigCommand{
238238
Meta: Meta{
239239
ContextOpts: testCtxConfig(testProvider()),
240240
Ui: ui,
@@ -269,12 +269,12 @@ func TestRemote_initBlank(t *testing.T) {
269269
}
270270

271271
// Test initializing without remote settings
272-
func TestRemote_initBlank_missingRemote(t *testing.T) {
272+
func TestRemoteConfig_initBlank_missingRemote(t *testing.T) {
273273
tmp, cwd := testCwd(t)
274274
defer testFixCwd(t, tmp, cwd)
275275

276276
ui := new(cli.MockUi)
277-
c := &RemoteCommand{
277+
c := &RemoteConfigCommand{
278278
Meta: Meta{
279279
ContextOpts: testCtxConfig(testProvider()),
280280
Ui: ui,
@@ -288,7 +288,7 @@ func TestRemote_initBlank_missingRemote(t *testing.T) {
288288
}
289289

290290
// Test updating remote config
291-
func TestRemote_updateRemote(t *testing.T) {
291+
func TestRemoteConfig_updateRemote(t *testing.T) {
292292
tmp, cwd := testCwd(t)
293293
defer testFixCwd(t, tmp, cwd)
294294

@@ -310,7 +310,7 @@ func TestRemote_updateRemote(t *testing.T) {
310310
}
311311

312312
ui := new(cli.MockUi)
313-
c := &RemoteCommand{
313+
c := &RemoteConfigCommand{
314314
Meta: Meta{
315315
ContextOpts: testCtxConfig(testProvider()),
316316
Ui: ui,
@@ -345,7 +345,7 @@ func TestRemote_updateRemote(t *testing.T) {
345345
}
346346

347347
// Test enabling remote state
348-
func TestRemote_enableRemote(t *testing.T) {
348+
func TestRemoteConfig_enableRemote(t *testing.T) {
349349
tmp, cwd := testCwd(t)
350350
defer testFixCwd(t, tmp, cwd)
351351

@@ -365,7 +365,7 @@ func TestRemote_enableRemote(t *testing.T) {
365365
}
366366

367367
ui := new(cli.MockUi)
368-
c := &RemoteCommand{
368+
c := &RemoteConfigCommand{
369369
Meta: Meta{
370370
ContextOpts: testCtxConfig(testProvider()),
371371
Ui: ui,

commands.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ func init() {
8080
}, nil
8181
},
8282

83-
"pull": func() (cli.Command, error) {
84-
return &command.PullCommand{
85-
Meta: meta,
86-
}, nil
87-
},
88-
89-
"push": func() (cli.Command, error) {
90-
return &command.PushCommand{
91-
Meta: meta,
92-
}, nil
93-
},
94-
9583
"refresh": func() (cli.Command, error) {
9684
return &command.RefreshCommand{
9785
Meta: meta,

0 commit comments

Comments
 (0)