File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,13 +31,21 @@ func (c *ApplyCommand) Run(args []string) int {
3131 return 1
3232 }
3333
34+ var configPath string
3435 args = cmdFlags .Args ()
3536 if len (args ) > 1 {
3637 c .Ui .Error ("The apply command expacts at most one argument." )
3738 cmdFlags .Usage ()
3839 return 1
40+ } else if len (args ) == 1 {
41+ configPath = args [0 ]
42+ } else {
43+ var err error
44+ configPath , err = os .Getwd ()
45+ if err != nil {
46+ c .Ui .Error (fmt .Sprintf ("Error getting pwd: %s" , err ))
47+ }
3948 }
40- configPath := args [0 ]
4149
4250 // If we don't specify an output path, default to out normal state
4351 // path.
Original file line number Diff line number Diff line change @@ -190,6 +190,52 @@ func TestApply_error(t *testing.T) {
190190 }
191191}
192192
193+ func TestApply_noArgs (t * testing.T ) {
194+ cwd , err := os .Getwd ()
195+ if err != nil {
196+ t .Fatalf ("err: %s" , err )
197+ }
198+ if err := os .Chdir (testFixturePath ("plan" )); err != nil {
199+ t .Fatalf ("err: %s" , err )
200+ }
201+ defer os .Chdir (cwd )
202+
203+ statePath := testTempFile (t )
204+
205+ p := testProvider ()
206+ ui := new (cli.MockUi )
207+ c := & ApplyCommand {
208+ ContextOpts : testCtxConfig (p ),
209+ Ui : ui ,
210+ }
211+
212+ args := []string {
213+ "-init" ,
214+ "-state" , statePath ,
215+ }
216+ if code := c .Run (args ); code != 0 {
217+ t .Fatalf ("bad: %d\n \n %s" , code , ui .ErrorWriter .String ())
218+ }
219+
220+ if _ , err := os .Stat (statePath ); err != nil {
221+ t .Fatalf ("err: %s" , err )
222+ }
223+
224+ f , err := os .Open (statePath )
225+ if err != nil {
226+ t .Fatalf ("err: %s" , err )
227+ }
228+ defer f .Close ()
229+
230+ state , err := terraform .ReadState (f )
231+ if err != nil {
232+ t .Fatalf ("err: %s" , err )
233+ }
234+ if state == nil {
235+ t .Fatal ("state should not be nil" )
236+ }
237+ }
238+
193239func TestApply_plan (t * testing.T ) {
194240 planPath := testPlanFile (t , & terraform.Plan {
195241 Config : new (config.Config ),
You can’t perform that action at this time.
0 commit comments