# Block Management

Blocks are the building components of Spacelift Flows. Each block performs one function and communicates with other blocks through inputs and outputs.

## Adding Blocks
[Section titled “Adding Blocks”](#adding-blocks)
 1. Choose Built-in blocks or App blocks from left sidebar
 1. Click the block type you want
 1. Click specific block variant

![Adding blocks to the canvas](/images/adding-blocks-to-canvas.png)

## Connecting Blocks
[Section titled “Connecting Blocks”](#connecting-blocks)
Connect blocks by linking sockets:

 - Drag from **output socket** (bottom of source block)
 - Drop onto **input socket** (top of destination block)
 - One output can connect to multiple inputs (parallel processing)
 - Multiple outputs can connect to one input (data merging)

### Inputs and Outputs
[Section titled “Inputs and Outputs”](#inputs-and-outputs)
Every block has defined input and output sockets:

 - **Input sockets** (top of blocks): Configure input settings or manually send debug events
 - **Output sockets** (bottom of blocks): View outgoing events or customize output data

#### Input Socket
[Section titled “Input Socket”](#input-socket)
![Input socket](/images/input-socket.png)

#### Output Socket
[Section titled “Output Socket”](#output-socket)
![Output socket](/images/output-socket.png)

**Best Practice**: Name blocks before connecting them. Block names become the keys you use to access their outputs in subsequent blocks.

## Configuring Blocks
[Section titled “Configuring Blocks”](#configuring-blocks)
Blocks may have two configuration types:

### Static Configuration:
[Section titled “Static Configuration:”](#static-configuration)
 - Set at block level
 - Evaluated right away, not per-event
 - Usually const, but can also reference “signals” from other blocks using `ref()`

### Dynamic Configuration:
[Section titled “Dynamic Configuration:”](#dynamic-configuration)
 - Set at input level
 - Accesses outputs of previous blocks through `outputs` variable
 - Evaluated for each incoming event

When you connect blocks, Spacelift shows you the available input schema so you know what data you can access. You also have full auto-complete in the config editors.

## Block Types
[Section titled “Block Types”](#block-types)
### Core Blocks
[Section titled “Core Blocks”](#core-blocks)
Built-in functionality: HTTP requests, scheduling, data transformation, business logic.

### App Integration Blocks
[Section titled “App Integration Blocks”](#app-integration-blocks)
From installed apps: complex integrations with external services, authentication, API interactions, low-level protocols.

## Block Lifecycles
[Section titled “Block Lifecycles”](#block-lifecycles)
Some blocks have lifecycles that manage external resources or configurations. Blocks with lifecycles handle:

 - Creation of external resources or configurations
 - Updates to those resources when block settings change
 - Deletion and cleanup when the block is removed (draining)
 - Exposing static outputs via signals that other blocks can reference

Examples of lifecycle blocks:

 - AWS S3 Bucket (creates and manages S3 bucket)
 - PagerDuty Incident Subscription (manages PagerDuty-side webhook configuration)

### Lifecycle Statuses:
[Section titled “Lifecycle Statuses:”](#lifecycle-statuses)
 - `DRAFT`: Being configured by the user, no resource created yet
 - `IN_PROGRESS`: Being created or updated
 - `READY`: Successfully created or updated
 - `FAILED`: Creation or update failed
 - `DRAINING`: Being deleted, cleaning up resources