v1

Infrastructure as Code /

Create a template

You can create a new template from the templates page in your team dashboard, or from the templates page in a project.

Click here to create a new template.

You can create the template using the visual or code editor, and configure the template's settings on the template edit page.

The Northflank editor includes code hints, autocompletion, and error checking to help you include required properties in the correct format.

Create a template

You can create and edit a template using either the visual editor to drag and drop nodes, or by editing the template code directly. You can switch between these views at any point when editing a template.

Create a template using the visual editor

The visual editor allows you to drag and drop nodes in the order you want them to run.

Creating a template in the Northflank application using the visual editor

Nodes must be nested in workflows, which define whether nodes contained run in sequence (sequential), or at the same time (parallel). Workflow nodes can be nested within other workflow nodes. You can click the button in the workflow node to switch between parallel and sequential workflows.

To add a node, find the relevant node from the list, or use the search box, and drag the node into your workflow. If a node is inserted into a sequential workflow, it will be placed before, between, or after other nodes depending on where it is dropped, with arrows showing the sequence the template will run in. Nodes dropped into a parallel workflow will be added without any sequence, as they will be executed simultaneously. You can drag and drop nodes to re-order them, or move them into and out of workflows.

Click on an individual node to edit that specific node. You can configure a node using the form, or switch to code to directly edit the JSON for the individual node. Editing the code directly is particularly useful to paste in resource specifications from your existing projects, or other sources.

Click save node to finish editing an individual node, cancel to discard your changes, or delete node to remove it.

Editing a template node in the Northflank application using the visual editor

Click create template or save template to save your template.

Create a template using the code editor

Template code consists of JSON defining resources and actions to be performed in workflows.

You can enter the content of your template using the Northflank code editor by selecting code. The editor includes code hints, autocompletion, and error checking to help you include required properties in the correct format.

Creating a template in the Northflank application using the code editor

Configure template settings

You can set the name and description for your template, and configure how your template will behave in the settings view.

Configuring template settings in the Northflank application

Set project context

Every node for a project-level resource must have a project context. You can either set the project context directly in the resource node, or the node can inherit the project context from a parent workflow. You can create and update resources across multiple projects by setting different contexts for workflows or nodes.

Setting the project context for a workflow in the Northflank application

Learn more about setting project contexts.

Run your template automatically

You can enable the template to run automatically whenever it is updated - whether it's updated in the Northflank UI, via the API, or changed in the Git repository (if GitOps is enabled).

This is convenient if you want to manage your resources via templates, as triggering a run automatically will mean your resources will be updated to reflect the template specifications on change.

Enable GitOps for your template

You can enable GitOps to sync the template with a Git repository. You can make changes to your template by committing changes to it in the repository or by editing it on Northflank, and the changes will be propagated to the other platform automatically. This allows you to maintain your templates alongside your codebase, or in a separate infrastructure repository.

Enable GitOps and select the repository and branch that contains, or will contain, the template code. Enter the path to the template relative to the repository root. For example /template.json will look for a file called template.json in the repository root, while /platform/backend.json will look for a file called backend.json in the directory platform.

If a template file already exists at the path, it will be loaded into the editor. If no file exists, one will be created with the template specification defined in the editor.

It is not necessary, but it is recommended, to save the template file with the format json so it can be recognised by IDEs and text editors.

Learn more about GitOps on Northflank.

Configure template run concurrency

You can choose how a template will behave if it receives more than one request to run at the same time, or receives a request to run while a run is still in progress.

  • Allow (default): multiple template runs can be executed in parallel, with no restrictions
  • Queue: each time a template run is triggered it will be added to a queue, and runs will be executed sequentially in order of creation
  • Forbid: if a template is currently pending or running any run requests will be ignored

You may want to queue or forbid simultaneous runs to ensure that resources are not updated with conflicting configurations.

Provide secrets securely to a template

You should not include any secrets, such as API keys, passwords, or other sensitive data in your template. Instead, you should define argument keys in your template and provide the values in argument overrides, which are stored securely on the Northflank platform, encrypted at rest.

You can configure argument overrides for a template which will override any arguments with the same key. If the key specified in the overrides object does not exist in the arguments object, it will be inserted.

Get template specifications

The simplest way to start writing a template is to get the template specification for your existing resources or entire projects.

Once you have your resource or project correctly configured and running you can copy the specification, paste it into a new template, and modify and add nodes.

View project template

Click the project template button in the project header to get the template for an entire project. You can switch between viewing the template code and the visual representation of the project, and view the specification for individual resources by clicking on a node in the visual editor.

An example of a project template specification in the Northflank application

View resource specification

To view the specification for individual resources, such as services, addons, jobs you can click the options button in the resource's header.

Select view specification and ensure the view is on template code. Toggle between node only to copy the specification into an existing template, or full template which will give you a full template specification including the resource.

An example of a resource template specification in the Northflank application

Access your templates

There are two ways to access your templates in the Northflank UI, either from your team dashboard, or from within a project.

Your team templates page will display all templates created within your team, regardless of any projects they may be related to. The template page within a project will only show templates that create or reference that project.

These separate views are only to make it easier to navigate to relevant templates as all templates are stored on the team.

© 2024 Northflank Ltd. All rights reserved.