Skip to main content

Flows

In Mantis, flows are used to orchestrate tasks and define the execution logic for infrastructure and application deployments. Flows provide a powerful way to structure and manage complex operations in a declarative manner.

note

Mantis currently uses hofstadter to parse and execute flows. hof is a wrapper around cuelang tools/flow package.

Flow Syntax and Structure

Flows in Mantis are defined using CUE (Configure Unify Execute) language and are typically stored in files with a .tf.cue extension. Here's an overview of the key components and syntax of a flow:

Flow Annotation

Flows are identified using the @flow annotation. This annotation is placed at the top level of a CUE structure to designate it as a flow:

deploy_flask_dynamodb: {
// Flow annotation is required for mantis to identify flows in
// the configuration files. These are entry points for mantis to
// start the execution

@flow(deploy_flask_dynamodb)
task1: {...}
task2: {...}
task3: {...}
// Tasks and other flow components go here
}

Task Dependencies

Tasks within a flow can be executed independently or in a specific order. To define explicit ordering, use the dep field in a task definition:

deploy_flask_app: {
@task(mantis.core.K8s) // Task type
dep: [create_dynamodb_table] // Task dependencies go here
config: {...} // Task configuration goes here
}

Flow Execution Modes

Flows in Mantis represent the scripting logic of Terraform and can be executed in different modes, similar to Terraform's workflow. The common execution modes are:

  1. Init: Initialize the working directory containing the flow configuration.
  2. Plan: Create an execution plan to preview the changes that will be made.
  3. Apply: Execute the planned changes to reach the desired state.
  4. Destroy: Destroy the resources created by the flow.
warning

Currently, destroy mode doesnt reverse the order of execution. It destroys the resources in the same order as they were created. We plan to address this issue before Mantis GA release. Deleting resources out of order could lead unpredictable results.

These modes allow for a controlled and predictable deployment process.

Example Flow

Here's a simplified example of a flow that deploys a Flask application with a DynamoDB backend:

deploy_flask_dynamodb: {
@flow(deploy_flask_dynamodb)

setup_tf_providers: {
@task(mantis.core.TF)
config: {...} // Provider configuration
}

create_dynamodb_table: {
@task(mantis.core.TF)
dep: [setup_tf_providers]
config: {...} // DynamoDB table configuration
}

deploy_flask_app: {
@task(mantis.core.K8s)
dep: [create_dynamodb_table]
config: {...}// Flask app deployment configuration
}

deploy_flask_service: {
@task(mantis.core.K8s)
dep: [deploy_flask_app]
config: {...}// Flask service configuration
}
}

This flow demonstrates the key concepts of flow definition, task ordering, and the use of different task types (TF for Terraform and K8s for Kubernetes) within a single flow.

By using flows, Mantis enables you to create complex, multi-step deployment processes that are easy to understand, maintain, and execute.