Skip to main content

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

  1. Open any .yaml or .yml file in your project.

  2. Type infrahubobject and select the snippet from the suggestion list.

  3. The following template will be inserted:

    ---
    apiVersion: infrahub.app/v1
    kind: Object
    spec:
    kind: ${1:kind}
    data:
    - name: "${2:name}"
  4. Replace the placeholder values (kind, name) with your desired values.

2. Insert a Infrahub Python Snippet

  1. Open a .py file in your workspace.
  2. Type one of the following snippet prefixes and select it from the suggestion list:
    • infrahubtransform for a transform
    • infrahubscript for a script
    • infrahubgenerator for a generator
    • infrahubcheck for a check
  3. Fill in the placeholders as needed to scaffold your automation script.