InSpec Language Support in Atom and VS Code

During the webinar “Better Tools for a Better Life” I stressed the importance of code snippets to increase your efficiency. I found that two of the editors I used during the presentation, and in my every day practice, were lacking support for InSpec. So I added support in the form of an:

Open up the Settings View using Cmd/Ctrl+, click on the “Install” tab and type in “language-inspec” into the box under Install Packages.

Bring up the Extensions view by clicking on the Extensions icon in the View Bar on the side of VS Code.  Search for “InSpec”.

InSpec’s ability to express expectations about the state of your infrastructure within RSpec is powerful. It does this through a large set of resources each with their own specific examples and expectations. When I sat down to write some InSpec recently, I felt like my editor should be helping me do a better job by providing code snippets and proper syntax highlighting.

Code Snippets

The Package/Extension defines code snippets. These allow you to write a small amount of text that is then expanded out to a full definition. A snippet exists for every resource (e.g. command,  package, service, user). These snippets can also provide tab stops to allow you to quickly move through each of the essential places within the expanded definition to customize it to your needs.

Visual Studio Code - InSpec Extension
Visual Studio Code with InSpec Extension

InSpec’s Grammar

A package or extension may define a grammar to help identify the syntax of the language. For Atom I was able to leverage the RSpec package’s grammar as a starting point and then define the additional ‘keywords’ (e.g. control, impact) to recognize. For VS Code I borrowed an initial grammar from RSpec bundle defined for TextMate and again add in InSpec.

Atom with InSpec Package
Atom with InSpec Package

Conclusion

Let’s all work smarter and more efficiently. I encourage you to install the Atom package or Code extension to increase your productivity. You can also help make them better by providing feedback, issues, and requests for Atom package or Code extension on GitHub.

Franklin Webber

College dropout, turned instructor who found software development because everything else in his life was going too well. Forged by the fires of tech support, quality assurance and software development, he now brings technology to the hungry, sullied masses with raw energy, immeasurable empathy and a strong injection of humor.