Cloudspin rake task reference

As introduced in the guide to creating a simple stack, you can include cloudspin tasks in a Rakefile to help you manage stack instances according to the stack project structure.

Installing the gem in your project

To use the cloudspin rake tasks, you’ll need to add a Gemfile and Rakefile to your project. The Gemfile should add the cloudspin-stack-rake gem:

gem 'cloudspin-stack-rake'

This gem has cloudspin-stack as a dependency, so that gem will also be installed by default, along with a few other dependencies. See the source code for cloudspin-stack and cloudspin-stack-rake.

Run bundle install to actually install the gems into your project. This will create a Gemfile.lock file, which you can add to your project in source control so that consistent versions of the gems are used wherever the project is checked out and run.

Basic rake tasks for a single stack instance

By creating an instance of the ruby StackTask class in your Rakefile, a set of tasks are created to manage a stack instance.

require 'cloudspin/stack/rake' 'test-network').instance

This assumes that the ./src/stack-definition.yaml exists. It will also look for ./stack-instance-defaults.yaml and ./stack-instance-local.yaml, and use these for parameters to pass to terraform. If the Terraform source code under ./src declares variables without defaults, they will need to be declared in one of these files.

Simplifying StackTask declarations

If you include the module in your rakefile, the code to declare the tasks becomes simpler, which helps if you go beyond the very simple example:

require 'cloudspin/stack/rake'
include Cloudspin::Stack::Rake 'test-network').instance


In the above example, the tasks are created in the root namespace. But as you add more things to your rakefile, namespaces are useful to organize code and tasks. Simply wrap the StackTask declaration in a namespace:

require 'rake/clean'
require 'cloudspin/stack/rake'


include Cloudspin::Stack::Rake

namespace :network do 'test-network').instance

This makes the task list a bit more organized:

$ rake -T
rake clean          # Remove any temporary products
rake clobber        # Remove any generated files
rake network:down   # Destroy stack test-network
rake network:dry    # Show command line to be run for stack test-network
rake network:plan   # Plan changes to stack test-network
rake network:up     # Create or update stack test-network

Multiple instances

Inspec task for testing

The cloudspin-stack-rake library includes a task for running Inspec tests against a stack instance. It assumes the inspec profile(s) are in ./test/inspec.

Including the inspec task in the rakfile:

include Cloudspin::Stack::Rake

stack = 'test-network').instance stack)

Inspec attributes

All stack instance attributes (as described in the project structure reference guide) defined for the stack instance to be tested are made available as Inspec attributes, so they can be used in tests.

aws_region = attribute('region', description: 'aws region')
describe aws_region do
  it 'region attribute should be available' do
    expect(subject).not_to eq('')

Files generated by the inspec task:

An inspec attribute file is automatically generated in ./work/inspec/attributes-for-stack-INSTANCE_NAME.yml.

The log output from the inspec run, including stack traces, is generated in ./work/inspec/results-for-stack-INSTANCE_NAME-profile-PROFILE_NAME.json. PROFILE_NAME is set in the inspec profile file (./test/inspec/inspec.yml).

Artefact management

results matching ""

    No results matching ""