In this blog, we’ll run through the new features of Cloudify’s VS Code extension and how developers can use it to write better and more consistent blueprints. This will ultimately improve the overall user experience.
VS Code is a cross-platform text editor created by Microsoft. Developers can use VS Code as an Integrated Development Environment (IDE) for just about any language. Part of VS Code’s appeal is in the ease of developing extensions, which can expand its applications. It is also available for in-browser editing in GitHub.
Two of the coolest extension APIs for VS code are the language server protocol and Textmate grammars. Together, these APIs provide for developers to create tools for developing in novel languages. Cloudify is perfect for such an application.
Let’s dive in.
Improved Blueprint Writing
Cloudify is an environment management and configuration product. Users describe infrastructure and application configurations in files called blueprints.
Blueprints are expressed in YAML, a configuration language that relies heavily on indentation for syntax. Cloudify’s DSL (domain specific language) determines what parameters and values are valid in Cloudify Blueprint files.
The Cloudify extension for VS Code offers some valuable features to help Cloudify developers write and validate their blueprints, such as word completion and syntax and style linting.
Cloudify’s DSL defines certain syntax conditions. Such conditions may be indentation or data types.
These primordial building blocks help us identify contexts such as top-level sections. If we are in an indented section, then the closest non-indented section above us is our top-level section. Examples of top-level sections are “inputs” and “node_templates”.
These sections can provide us with context, giving us hints about the meaning and possible values for a given term.
For example, the term“type”. This is a special word in any programming language and Cloudify is no different.
In Cloudify, the term “type” has a different meaning, depending on if we are in a “inputs” context, or a “node templates” context.
For example, if we are in an “inputs” context, and our level of indentation indicates that we are the first indented level inside of another indented level, then we know that the term “type” indicates the type of an input.
There are other conditions to consider, for example the DSL version. Cloudify has advanced past various DSL versions. So for example, some values for “type” in DSL version 1.5 are not valid in DSL version 1.3.
The elementary values that are supported in v1.3 are “string”, “integer”, and “boolean”. In v1.5, we already have “dict”, “list”, and several more advanced types.
On the other hand, if we are in a “node_templates” context, and our level of indentation indicates that we are the first indented level inside of another indented level, then we know that the term “type” indicates the type of the node template.
A node template is always an advanced type. The available types are only indirectly related to the Cloudify DSL version. Rather, the plugins which are imported (in the “imports” section) determine the possible values for “type” in a node template context.
Cloudify has many node types, so it’s nice to have helpful hints to remind us what is the correct type name that we need to use.
For example, let’s say I’m writing a blueprint. I know that I want to use an Azure resource group. I remember the term is “group something”, but not the exact namespaces.
With the Cloudify VS Code language extension, I can type “group” and the word completion will tell me what type names match “group”.
Another useful feature of word completion are matches for documentation.
Let’s say that I’ve selected an Azure virtual network. I want to know what other possible sections there are for determining my node template. So, when I hover over the suggestions, the VS code extension also provides me with some documentation.
- If you don’t know what you want to type next, you can run CTRL-SPACE and you’ll get a list of up-to-date suggestions.
- If suggestions look out-dated, run CTRL-S and then run CTRL-SPACE again.
Another feature available in the VS Code extension is diagnostics. In the above screenshots, you might have noticed that some of the words have squiggly red underlines.
This is the result of diagnostics provided by “cfy-lint”. CFY Lint is a stand-alone command-line tool developed by Cloudify.
CFY Lint is able to read our YAML files and provide us with everything from syntactical errors to style suggestions. You can get pointers on deprecated nodes and relationship types. You can also get warnings when there is superfluous code or unprovided dependencies.
Diagnostics such as these are only available when CFY Lint is installed in current Python PATH configured in VS Code preferences.
While I am editing my Cloudify blueprint, CFY Lint is running in the background sending diagnostic information to VS Code.
So, for example, my “group” input from above. There’s a red squiggly line underneath “group”. If I hover over “group”, then I learn that the input is unused. I can either delete the input or find the place where I intended to use this input.
Some CFY-lint diagnostics are simple enough to offer an automatic fix. This feature is also available from within VS Code.
For example, I have a diagnostic that indicates that there are “trailing spaces”. This means after a certain string, there are some spaces that provide no meaning in YAML or the Cloudify DSL.
When I hover over the red line, I have an option for a quick fix. Selecting “Fix with Cfy-Lint” will fix the issue, if that type of issue is supported by CFY Lint.
The release of Cloudify’s VS Code extension is exciting for our user’s experience. It will allow an Integrated Development Environment (IDE) for just about any language. It helps write and validate blueprints. It will provide more context for users along with helpful hints to remind users what is the correct type name that we need to use and other quick fixes.
We even have plans for how this fits into future releases of Cloudify, so stay tuned.
In order to install the Cloudify extension in VS Code, navigate to “View” and select “Extensions”. In the search bar on the left panel, search for “Cloudify”. And install the “Cloudify” extension.
CFY Lint Installation
Cloudify distributes a CFY Lint RPM. You can also install CFY Lint with Pip. You can easily install CFY Lint with this command:
curl -sfL https://cloudify.co/get-lint | sh –
Then, ensure that VS Code is able to use CFY Lint. To do that, you need to configure the Python environment used by VS Code. For more information on that, see this link: https://code.visualstudio.com/docs/python/environments.
You can find the full list of Cloudify 7 features in the release notes.