solarboat 0.8.2

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
# Solarboat Configuration Guide

Solarboat supports configuration files to customize workspace management and variable file handling across your Terraform modules. This guide covers all configuration options and their usage.

## Quick Start

1. Create a configuration file in your project root:

   - `solarboat.json` (JSON format)

2. Configure your settings and run solarboat commands as usual.

## Configuration File Structure

### Basic Configuration

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

## Configuration Sections

### Global Configuration

The `global` section applies to all modules unless overridden by module-specific settings.

#### `ignore_workspaces`

- **Type**: Array of strings
- **Description**: Workspace names to skip during plan and apply operations
- **Example**: `["dev", "test"]`

#### `var_files`

- **Type**: Array of strings
- **Description**: Variable files to use for all workspaces
- **Example**: `["global.tfvars", "environment.tfvars"]`

#### `workspace_var_files`

- **Type**: Object mapping workspace names to arrays of variable files
- **Description**: Workspace-specific variable files
- **Example**:
  ```json
  {
    "dev": ["dev.tfvars", "dev-secrets.tfvars"],
    "prod": ["prod.tfvars", "prod-secrets.tfvars"]
  }
  ```

### Module-Specific Configuration

The `modules` section allows you to override global settings for specific modules.

#### Module Path

- **Type**: String (key in the modules object)
- **Description**: Path to the Terraform module. Can be relative to the configuration file location or absolute path. Solarboat automatically normalizes paths for lookup.
- **Examples**:
  - `"infrastructure/networking"` (relative path)
  - `"terraform/projects/webapp"` (relative path)
  - `"/absolute/path/to/module"` (absolute path - normalized to relative internally)

**Note**: Module paths are automatically normalized to be relative to the configuration file location for consistent lookup, regardless of whether you specify them as absolute or relative paths.

#### Module Settings

Each module can have the same settings as the global configuration:

- `ignore_workspaces`: Override global ignore settings for this module
- `var_files`: Override global var files for this module
- `workspace_var_files`: Override global workspace var files for this module

## Environment-Specific Configuration

Solarboat supports environment-specific configuration files using the `SOLARBOAT_ENV` environment variable.

### Usage

```bash
# Use development configuration
SOLARBOAT_ENV=dev solarboat plan

# Use production configuration
SOLARBOAT_ENV=prod solarboat apply

# Use staging configuration
SOLARBOAT_ENV=staging solarboat scan
```

### File Naming Convention

When `SOLARBOAT_ENV` is set, solarboat looks for these files in order:

1. `solarboat.<env>.json`
2. `solarboat.json` (fallback)

### Example Environment Files

**solarboat.dev.json:**

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

**solarboat.prod.json:**

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

## Configuration Precedence

Settings are resolved in the following order (highest to lowest priority):

1. **CLI Arguments**: `--ignore-workspaces`, `--var-files`
2. **Module-Specific Configuration**: Settings from `modules.<module_path>`
3. **Global Configuration**: Settings from the `global` section
4. **Defaults**: Built-in default values

### Example Precedence

Given this configuration:

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

For module `infrastructure/networking`:

- **Ignore workspaces**: `["dev"]` (module-specific overrides global)
- **Var files**: `["networking.tfvars"]` (module-specific overrides global)

If you run: `solarboat plan --ignore-workspaces prod,staging`

- **Ignore workspaces**: `["prod", "staging"]` (CLI overrides all config)

## Variable File Resolution

### General Variable Files

Variable files specified in `var_files` are applied to all workspaces.

### Workspace-Specific Variable Files

Variable files specified in `workspace_var_files.<workspace_name>` are applied only to that specific workspace.

### Final Variable File List

For each workspace, the final variable file list is:

1. General var files (module-specific → global fallback)
2. Workspace-specific var files (module-specific → global fallback)

### Example Resolution

For module `infrastructure/networking` and workspace `prod`:

- **General var files**: `["networking.tfvars", "vpc.tfvars"]` (from module config)
- **Workspace-specific var files**: `["networking-prod.tfvars", "networking-prod-secrets.tfvars"]` (from module config)
- **Final var files**: `["networking.tfvars", "vpc.tfvars", "networking-prod.tfvars", "networking-prod-secrets.tfvars"]`

## Path Resolution

### Module Paths

Module paths (keys in the `modules` object) are automatically normalized to be relative to the configuration file location. This ensures consistent lookup regardless of how you specify the path:

- **Relative paths**: Used as-is (e.g., `"terraform/projects/webapp"`)
- **Absolute paths**: Automatically converted to relative paths (e.g., `/full/path/to/terraform/projects/webapp``terraform/projects/webapp`)

This normalization happens internally and is transparent to users.

**Example**: If your configuration file is at `/home/user/project/solarboat.json` and you have a module at `/home/user/project/terraform/projects/webapp`, you can specify it in your configuration as:

```json
{
  "modules": {
    "terraform/projects/webapp": {
      "ignore_workspaces": ["dev"]
    }
  }
}
```

Solarboat will automatically match this configuration to the discovered module path, regardless of whether the module was found using its absolute or relative path.

### Variable File Paths

Variable file paths are resolved relative to the configuration file location.

### Relative Paths

Variable file paths are resolved relative to the configuration file location.

### Absolute Paths

Absolute paths are used as-is.

### Examples

```json
{
  "global": {
    "var_files": [
      "vars/global.tfvars", // Relative to config file
      "/absolute/path/secrets.tfvars" // Absolute path
    ]
  }
}
```

## CLI Integration

### Configuration File Options

```bash
# Use specific configuration file
solarboat --config /path/to/solarboat.json plan

# Disable configuration file loading
solarboat --no-config plan

# Auto-discover configuration file
solarboat plan
```

### Backward Compatibility

All existing CLI options continue to work:

- `--ignore-workspaces` overrides configuration file settings
- `--var-files` overrides configuration file settings
- Configuration files are optional

## Validation and Error Handling

### Configuration Validation

Solarboat validates your configuration and provides helpful warnings for:

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

### Example Validation Output

```
⚠️  Configuration validation warnings:
   • Module path 'infrastructure/networking' does not exist (checked: /path/to/infrastructure/networking)
   • Var file 'dev.tfvars' for global does not exist (checked: /path/to/dev.tfvars)
   • Workspace name 'default' is reserved and may cause issues
```

### Error Handling

- Invalid JSON syntax results in immediate error
- Missing required fields use sensible defaults
- Configuration validation warnings don't prevent execution

## Best Practices

### 1. Use Environment-Specific Configurations

```bash
# Development
SOLARBOAT_ENV=dev solarboat plan

# Production
SOLARBOAT_ENV=prod solarboat apply
```

### 2. Organize Variable Files

```
project/
├── solarboat.json
├── vars/
│   ├── global.tfvars
│   ├── dev.tfvars
│   ├── dev-secrets.tfvars
│   ├── prod.tfvars
│   └── prod-secrets.tfvars
└── infrastructure/
    └── networking/
        ├── main.tf
        └── networking.tfvars
```

### 3. Use Module-Specific Overrides Sparingly

Only override global settings when necessary to avoid configuration duplication.

### 4. Validate Your Configuration

Run `solarboat scan` to validate your configuration before using plan/apply commands.

### 5. Keep Secrets Separate

Use workspace-specific variable files for sensitive information:

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

## Migration from CLI-Only Usage

### Before (CLI-only)

```bash
solarboat plan --ignore-workspaces dev,test --var-files global.tfvars,env.tfvars
solarboat apply --ignore-workspaces dev,test --var-files global.tfvars,env.tfvars
```

### After (Configuration-based)

```json
{
  "global": {
    "ignore_workspaces": ["dev", "test"],
    "var_files": ["global.tfvars", "env.tfvars"]
  }
}
```

```bash
solarboat plan
solarboat apply
```

## Troubleshooting

### Configuration Not Loading

- Check file permissions
- Verify file path is correct
- Ensure JSON syntax is valid

### Module Configuration Not Applied

If your module-specific settings (like `ignore_workspaces` or `workspace_var_files`) are not being applied:

- Ensure you're using `"modules"` as the top-level key (not `"projects"`)
- Verify the module path matches your directory structure relative to the config file
- Use relative paths like `"terraform/projects/webapp"` rather than absolute paths in your configuration
- Check that the module exists and contains `.tf` files

**Note**: As of version 0.8.2+, path normalization automatically handles absolute vs relative path mismatches.

### Unexpected Variable Files

- Check configuration precedence
- Verify workspace-specific settings
- Review CLI argument overrides

### Validation Warnings

- Create missing variable files
- Fix module paths
- Review workspace names

### Environment-Specific Config Not Found

- Verify `SOLARBOAT_ENV` is set correctly
- Check file naming convention
- Ensure files exist in the expected location