solarboat 0.6.0

A CLI tool for intelligent Terraform operations management with automatic dependency detection
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# Solar Boat CLI 🚀

[![Release](https://github.com/devqik/solarboat/actions/workflows/release.yml/badge.svg)](https://github.com/devqik/solarboat/actions/workflows/release.yml)
[![Crates.io](https://img.shields.io/crates/v/solarboat)](https://crates.io/crates/solarboat)
[![Website](https://img.shields.io/website?url=https://solarboat.io)](https://solarboat.io)

> Built with love for Rust and infrastructure automation by [devqik]https://devqik.com

Solar Boat is a command-line interface tool designed for Infrastructure as Code (IaC) and GitOps workflows. It provides intelligent Terraform operations management with automatic dependency detection and stateful/stateless module handling.

<table>
<tr>
<td width="50%">

## Why "Solar Boat"?

Inspired by the Ancient Egyptian Solar Boats that carried Pharaohs through their celestial journey, this CLI tool serves
as a modern vessel that carries developers through the complexities of operations and infrastructure management. Just as
the ancient boats handled the journey through the afterlife so the Pharaoh didn't have to worry about it, Solar Boat CLI
handles the operational journey so developers can focus on what they do best - writing code.

</td>
<td width="50%">
<img src="./icon.jpg" alt="Solar Boat Logo" width="100%">
</td>
</tr>
</table>

## Features ✨

### Current Features

- **Intelligent Terraform Operations**
  - Automatic detection of changed modules
  - Smart handling of stateful and stateless modules
  - Automatic dependency propagation
  - Parallel execution of independent modules
  - Detailed operation reporting
  - Path-based filtering for targeted operations

### Coming Soon

- Self-service ephemeral environments on Kubernetes
- Infrastructure management and deployment
- Custom workflow automation

## Installation 📦

### Using Cargo (Recommended)

```bash
# Install the latest version
cargo install solarboat

# Install a specific version
cargo install solarboat --version 0.6.0
```

### Building from Source

```bash
git clone https://github.com/devqik/solarboat.git
cd solarboat
cargo build
```

## Usage 🛠️

### Basic Commands

```bash
# Scan for changed Terraform modules
solarboat scan

# Scan modules in a specific directory
solarboat scan --path ./terraform-modules

# Plan Terraform changes
solarboat plan

# Plan and save outputs to a specific directory
solarboat plan --output-dir ./terraform-plans

# Plan changes while ignoring specific workspaces
solarboat plan --ignore-workspaces dev,staging

# Process all stateful modules regardless of changes
solarboat plan --all

# Apply Terraform changes (dry-run mode by default)
solarboat apply

# Apply actual Terraform changes
solarboat apply --dry-run=false

# Apply changes while ignoring specific workspaces
solarboat apply --ignore-workspaces prod,staging

# Process all stateful modules regardless of changes
solarboat apply --all
```

### Command Details

#### Scan

The scan command analyzes your repository for changed Terraform modules and their dependencies. It:

- Detects modified `.tf` files
- Builds a dependency graph
- Identifies affected modules
- Filters modules based on the specified path
- Does not generate any plans or make changes
- Can process all stateful modules with `--all` flag

#### Plan

The plan command generates Terraform plans for changed modules. It:

- Runs `terraform init` for each module
- Detects and handles multiple workspaces
- Generates detailed plans for each workspace
- Optionally skips specified workspaces
- Optionally saves plans to a specified directory
- Shows what changes would be made
- Filters modules based on the specified path
- Can process all stateful modules with `--all` flag
- Saves plans as Markdown files for better readability

#### Apply

The apply command implements the changes to your infrastructure. It:

- Runs `terraform init` for each module
- Detects and handles multiple workspaces
- Supports dry-run mode for safety
- Optionally skips specified workspaces
- Automatically approves changes in CI/CD
- Shows real-time progress
- Filters modules based on the specified path
- Can process all stateful modules with `--all` flag

### Module Types

Solar Boat CLI recognizes two types of Terraform modules:

- **Stateful Modules**: Modules that manage actual infrastructure state (contain backend configuration)
- **Stateless Modules**: Reusable modules without state (no backend configuration)

When changes are detected in stateless modules, the CLI automatically identifies and processes any stateful modules that depend on them.

### Workspace Handling

Solar Boat CLI provides intelligent workspace management for Terraform modules:

- **Automatic Detection**: Automatically detects if a module has multiple workspaces
- **Individual Processing**: Processes each workspace separately for both plan and apply operations
- **Workspace Filtering**: Allows skipping specific workspaces using the `--ignore-workspaces` flag
- **Default Workspace**: Handles modules with only the default workspace appropriately

### Path-based Filtering

Solar Boat CLI supports path-based filtering for all commands:

- **Targeted Operations**: Use `--path` to target specific modules or directories
- **Recursive Scanning**: Automatically discovers all modules within the specified path
- **Dependency Awareness**: Maintains dependency relationships even when filtering by path
- **Combined with --all**: Can be used together with `--all` to process all modules in a specific path

### Configuration Files

Solar Boat CLI supports configuration files to manage global and module-specific settings for Terraform workspaces and variable files.

#### Quick Start

1. Create a `solarboat.json` in your project root:

```json
{
  "global": {
    "ignore_workspaces": ["dev", "test"],
    "var_files": ["global.tfvars"],
    "workspace_var_files": {
      "prod": ["prod.tfvars"]
    }
  },
  "modules": {
    "infrastructure/networking": {
      "ignore_workspaces": ["test"],
      "var_files": ["networking.tfvars"],
      "workspace_var_files": {
        "prod": ["networking-prod.tfvars"]
      }
    }
  }
}
```

2. Run Solar Boat as usual - it will automatically load your configuration:

```bash
solarboat plan
solarboat apply
```

#### Environment-Specific Configuration

Use different config files for different environments by setting the `SOLARBOAT_ENV` environment variable:

```bash
SOLARBOAT_ENV=dev solarboat plan
SOLARBOAT_ENV=prod solarboat apply
```

Solar Boat will look for files like `solarboat.dev.json`, etc. If the environment-specific file is not found, it falls back to the default config file.

#### Configuration Options

- **Use a specific config file**:

  ```bash
  solarboat --config /path/to/solarboat.json plan
  ```

- **Disable config file loading**:

  ```bash
  solarboat --no-config plan
  ```

- **Override config file settings with CLI options**:
  ```bash
  solarboat plan --ignore-workspaces dev,test --var-files custom.tfvars
  ```

#### Configuration Precedence

1. CLI arguments (highest priority)
2. Module-specific config
3. Global config
4. Defaults (lowest priority)

#### Example: Workspace-Specific Variable Files

```json
{
  "global": {
    "workspace_var_files": {
      "dev": ["dev-secrets.tfvars"],
      "prod": ["prod-secrets.tfvars"]
    }
  }
}
```

#### Validation

Solar Boat validates your configuration and warns about:

- Missing module paths
- Missing variable files
- Reserved workspace names (`default`, `terraform`)

Run `solarboat scan` to check your configuration before running plan/apply.

> **Note**: For complete configuration documentation, see [CONFIGURATION.md]./CONFIGURATION.md.

### GitHub Actions Integration

Solar Boat provides a GitHub Action for seamless integration with your CI/CD pipeline. The action can scan for changes, generate Terraform plans, and automatically comment on pull requests with the results.

#### Basic Usage

```yaml
name: Infrastructure Management

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  infrastructure:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Important for detecting changes

      - name: Scan for Changes
        if: github.event_name == 'pull_request'
        uses: devqik/solarboat-action@latest
        with:
          command: scan
          github_token: ${{ secrets.GITHUB_TOKEN }}

      - name: Plan Infrastructure Changes
        if: github.event_name == 'pull_request'
        uses: devqik/solarboat-action@latest
        with:
          command: plan
          output_dir: terraform-plans
          github_token: ${{ secrets.GITHUB_TOKEN }}

      - name: Apply Infrastructure Changes
        if: github.ref == 'refs/heads/main'
        uses: devqik/solarboat-action@latest
        with:
          command: apply
          apply_dry_run: false # Set to true for dry-run mode
          github_token: ${{ secrets.GITHUB_TOKEN }}
```

This workflow will:

1. Scan for changes
2. Plan infrastructure changes
3. Comment on the PR with results
4. Apply changes when merged to main

#### Action Inputs

| Input               | Description                                        | Required | Default           |
| ------------------- | -------------------------------------------------- | -------- | ----------------- |
| `command`           | Command to run (`scan`, `plan`, or `apply`)        | Yes      | -                 |
| `plan_output_dir`   | Directory to save Terraform plan files             | No       | `terraform-plans` |
| `apply_dry_run`     | Run apply in dry-run mode                          | No       | `true`            |
| `ignore_workspaces` | Comma-separated list of workspaces to ignore       | No       | `''`              |
| `path`              | Root directory to scan for Terraform modules       | No       | `'.'`             |
| `all`               | Process all stateful modules regardless of changes | No       | `false`           |

#### Workflow Examples

**Basic Scan and Plan:**

```yaml
- name: Scan Changes
  uses: devqik/solarboat@v0.6.0
  with:
    command: scan

- name: Plan Changes
  uses: devqik/solarboat@v0.6.0
  with:
    command: plan
    plan_output_dir: my-plans
```

**Apply with Workspace Filtering:**

```yaml
- name: Apply Changes
  uses: devqik/solarboat@v0.6.0
  with:
    command: apply
    ignore_workspaces: dev,staging,test
    apply_dry_run: true
```

**Targeted Operations with Path Filtering:**

```yaml
- name: Plan Specific Modules
  uses: devqik/solarboat@v0.6.0
  with:
    command: plan
    path: ./terraform-modules/production
    plan_output_dir: prod-plans
```

**Complete Workflow with Conditions:**

```yaml
jobs:
  terraform:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      # Run on all branches
      - name: Plan Changes
        uses: devqik/solarboat@v0.6.0
        with:
          command: plan
          plan_output_dir: terraform-plans
          ignore_workspaces: dev,staging

      # Run only on main branch
      - name: Apply Changes
        if: github.ref == 'refs/heads/main'
        uses: devqik/solarboat@v0.6.0
        with:
          command: apply
          apply_dry_run: false
```

## Contributing 🤝

Contributions are welcome! Please feel free to submit a Pull Request.

## License 📄

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support 💬

- Issues: [GitHub Issues]https://github.com/devqik/solarboat/issues
- Discussions: [GitHub Discussions]https://github.com/devqik/solarboat/discussions
- Documentation: [Wiki]https://github.com/devqik/solarboat/wiki

## Acknowledgments 🙏

This project needs your support! If you find Solar Boat CLI useful, please consider:

- ⭐ Starring the project on GitHub
- 🛠️ Contributing with code, documentation, or bug reports
- 💡 Suggesting new features or improvements
- 🌟 Sharing it with other developers

Your support will help make this project better and encourage its continued development.

~ [@devqik](https://github.com/devqik) (Creator)