How to Use Infrahub Snippets in VSCode
This guide shows you how to quickly insert and customize Infrahub YAML objects and automation scripts using built-in snippets in Visual Studio Code. By following these steps, you’ll save time and reduce errors when authoring Infrahub resources.
Prerequisites
- Infrahub VSCode extension installed
- Workspace containing YAML or Python files
- Basic familiarity with editing files in VSCode
Steps
1. Insert a Infrahub Object Snippet
-
Open any
.yaml
or.yml
file in your project. -
Type
infrahubobject
and select the snippet from the suggestion list. -
The following template will be inserted:
---
apiVersion: infrahub.app/v1
kind: Object
spec:
kind: ${1:kind}
data:
- name: "${2:name}" -
Replace the placeholder values (
kind
,name
) with your desired values.
2. Insert a Infrahub Python Snippet
- Open a
.py
file in your workspace. - Type one of the following snippet prefixes and select it from the suggestion list:
infrahubtransform
for a transforminfrahubscript
for a scriptinfrahubgenerator
for a generatorinfrahubcheck
for a check
- Fill in the placeholders as needed to scaffold your automation script.