Ruby::Terraform

A ruby wrapper around terraform.

Installation

Add this line to your application's Gemfile:

gem 'rake-terraform-wrapper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ruby-terraform

Usage

require 'rake-terraform-wrapper'

# specify the following optional config
Ruby::Terraform.config do |c|
  c.binary = "/path/to/terraform" # or `terraform.exe` on windows

  # if you prefer that the binary is downloaded automatically, specify the version of the terraform binary
  c.terraform_version = '13.0' #Default version

  # optionally, specifiy the location where you want the terraform zip file to be downloaded
  c.download_path = "~/.terraform-bin/#{terraform_version}" #default path
end

# to force download, if not specified, terraform will be downloaded automatically on first usage
task :download_terraform do
  executable = Ruby::Terraform::Executable.new
  executable.download(verbose: true)
  executable.extract(verbose: true)
end

namespace :network do
  Ruby::Terraform::Tasks::AllTasks.new(:network) do |tf|
    tf.dir = File.absolute_path("infra/network")
    tf.backend = 's3'
    tf.build_dir = 'tmp' # optional. This will copy everything in the `tf.dir` into `build_dir` and execute terraform from this directory
    tf.backend_config = {
      bucket: 'some-bucket',
      key: 'network.tfstate',
      region: 'us-west-2'
    }
    tf.vars = {
      image_id: 'ami-something',
      availability_zone_names: ['us-west-2a', 'us-west-2b']
    }
  end
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ketan/rake-terraform-wrapper.

License

The gem is available as open source under the terms of the MIT License.