Integration Testing with InSpec

Joaquín Menchaca (智裕)
2 min readFeb 20, 2018

InSpec is a framework to create infrastructure tests for integration or compliance testing and is marketed as compliance as code. InSpec uses a similar syntax to ServerSpec. Currently, it is not feature parity with ServerSpec.

Tests are orchestrated using the inspec command. There is no further automation to integrate or further orchestrate tests directly on vagrant or docker using ruby workflow with rake or spec. For more advanced orchestration needs, you can use TestKitchen.

Getting Started with InSpec

With ruby installed, you can install everything needed for InSpec with:

gem install inspec
inspec init profile $PROFILENAME

This will create the following structure, where $PROFILENAME matches the name of your choosing:

.
└─── $PROFILENAME
├── controls
│ └── example.rb
├── inspec.yml
├── libraries
└── README.md

Test Script Example

In the control directory, you can add your test like the following below:

Running the Tests

InSpec can use SSH to log into your systems and run tests. With vagrant you can run the tests by specifying the port, path to ssh private key, and the user name and host. You can get these values from values by typing vagrant ssh-config, and then replace the variables below with the required values.

inspec exec $PROFILENAME/ \
-t ssh://$TARGET_USER@$TARGET_HOST \
-p $TARGET_PORT \
-i $TARGET_IDENTITYFILE

--

--

Joaquín Menchaca (智裕)
Joaquín Menchaca (智裕)

Written by Joaquín Menchaca (智裕)

DevOps/SRE/PlatformEng — k8s, o11y, vault, terraform, ansible

No responses yet