---
name: filter
description: Filter configurations using a flexible query language
type: list(string)
---

import {Aside} from '@astrojs/starlight/components';

<Aside type="note" title="Filter Behavior for Stack Generate">
The `--filter` flag works differently for `stack generate` compared to other commands. It requires that you explicitly target stacks using the `type=stack` attribute.

Examples:

```bash
# Filter by name
terragrunt stack generate --filter 'name=prod | type=stack'
```

</Aside>

### Attribute-Based Filtering
Match stacks by their configuration attributes:

```bash
# Filter by name
terragrunt stack generate --filter 'prod | type=stack'

# Filter by type
terragrunt stack generate --filter 'type=stack'

# Filter by path
terragrunt stack generate --filter './envs/prod/** | type=stack'
```

### Negation
Exclude paths using the `!` prefix:

```bash
# Exclude by path
terragrunt stack generate --filter '!./prod/** | type=stack'
```

### Union (Multiple Filters)
Specify multiple `--filter` flags to combine results using OR logic:

```bash
# Generate the dev and prod stacks
terragrunt stack generate --filter 'dev | type=stack' --filter 'prod | type=stack'
```
