Coder Social home page Coder Social logo

rspec-terraform's Introduction

Rspec-Terraform

Motivation

Terraform is an awesome way of provisioning your infrastructure. However, like with any new tool, the ecosystem surrounding it is very immature. This can cause problems when sharing code or coming up against the rough edges of a tool in active development.

The creation of rspec-terraform was initially intended to smooth the creation and sharing of common Terraform modules. Some sort of basic testing would ensure a stable and clearly defined interface for each module.

Looking Ahead

Eventually, a two-tiered approach to testing would be ideal.

Provisioning non-trivial infrastructure should involve the use of many Terraform modules (rather than defining everything yourself). Taking AWS as an example, this might include VPCs, ASGs, SGs, public/private subnets etc. Each of these modules should be unit tested using rspec-terraform so that the interfaces they expose are well-defined.

Assembling many individual modules into a cohesive platform should also - ideally - be tested. It's unclear at this stage how this might look and is yet to be implemented. Something similar to serverspec may work.

Usage

As outlined above, only simple unit-test type operations are currently supported.

Setup

You will need Ruby and bundler installed.

Create a Gemfile at the root of your Terraform module and add the following:

source 'https://rubygems.org'

gem 'rspec-terraform'

Then install the gem:

bundle

Matchers

N.B. You must set the provider for each test. This is best done in the opening describe block:

describe 'tf-aws-vpc', provider: :aws do
  ...
end

At present, only the AWS provider is available.

The matchers currently implemented are:

  1. require_variables
it 'expects the correct variables to be provided' do
 expected_variables = %w(vpccidr ec2nameserver region account envname domain)
 expect('terraform plan').to require_variables expected_variables
end
  1. create_a_plan
it 'creates a plan' do
  expect('terraform plan -var-file example_variables/test_values.tfvars').to create_a_plan
end

Contributing

  1. Fork it ( https://github.com/bsnape/rspec-terraform/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

rspec-terraform's People

Contributors

bsnape avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.