infrablocks / ruby_terraform

A simple Ruby wrapper for invoking terraform commands.
MIT License
109 stars 33 forks source link

Pass plan file to apply command #14

Closed unthar closed 5 years ago

unthar commented 6 years ago

Hey, Toby, I was trying to figure out a way to pass a plan file that was created with the 'plan' command to the 'apply' command. I didn't see an option to 'apply' for this. I started messing around with the apply.rb code to add a plan file option. Since the 'directory' option is required my changes failed, however, I realized then that I could just pass the plan file to the 'directory' option and it worked.

RubyTerraform.apply(
    directory: '_path/plan_file_'
  )

Is this the intended use for the 'directory' option with apply? If so, should the README be updated to reflect that? I read it as the directory of the terraform code just like with the plan command.

Thanks for the great module!

Kevin

tobyclemson commented 6 years ago

Hey Kevin,

When I wrote the original version of RubyTerraform I was only using the plan command as a manual dry run so didn't think to include the fact that a plan could be passed in the name of the parameter to apply. You are indeed right that passing the path to a plan as the :directory will achieve your desired result.

I may additionally add a :plan parameter so that the usage can be more specific but ultimately, they'd map to the same thing in terms of the generated command line. This would require some validation to make sure both aren't supplied but that shouldn't be too tricky.

This would additionally have the benefit of aligning well with the usage text from the terraform command:

Usage: terraform apply [options] [DIR-OR-PLAN]

Builds or changes infrastructure according to Terraform configuration
  files in DIR.

...

Happy to take a PR for it if you would like it sooner rather than later.

Thanks, Toby

unthar commented 6 years ago

Hey, Toby, Sorry I haven't gotten back to you sooner. I'll try and get a PR together when I get a chance.

Thanks!

tobyclemson commented 6 years ago

No problem, whenever you get a chance.

In terms of directory being required I think we can make it optional in this PR or maybe even just check for the presence of one of directory or plan.

Thanks, Toby

tobyclemson commented 5 years ago

I've added this in version 0.32.0.