|
| 1 | +# ThothCTL Check Command |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `thothctl check` command group provides tools for validating various aspects of your infrastructure code, project structure, and environment. These commands help ensure that your projects follow best practices, adhere to defined structures, and meet security requirements. |
| 6 | + |
| 7 | +## Available Check Commands |
| 8 | + |
| 9 | +### check iac |
| 10 | + |
| 11 | +Validates Infrastructure as Code (IaC) artifacts against predefined rules and best practices. |
| 12 | + |
| 13 | +```bash |
| 14 | +thothctl check iac [OPTIONS] |
| 15 | +``` |
| 16 | + |
| 17 | +Options: |
| 18 | +- `--mode [soft|hard]`: Validation mode (default: soft) |
| 19 | +- `-deps, --dependencies TEXT`: View a dependency graph in ASCII pretty shell output |
| 20 | +- `--recursive [local|recursive]`: Validate your terraform plan recursively or in one directory |
| 21 | +- `--outmd`: Output markdown file path |
| 22 | +- `-type, --check_type [tfplan|module|project]`: Check module or project structure format, or check tfplan (default: project) |
| 23 | + |
| 24 | +This command can validate: |
| 25 | +- Project structure against defined rules |
| 26 | +- Module structure against best practices |
| 27 | +- Terraform plans for security and compliance |
| 28 | + |
| 29 | +[Detailed documentation for check iac](commands/check/check_iac.md) |
| 30 | + |
| 31 | +### check project |
| 32 | + |
| 33 | +Validates project configuration and structure. |
| 34 | + |
| 35 | +```bash |
| 36 | +thothctl check project [OPTIONS] |
| 37 | +``` |
| 38 | + |
| 39 | +This command is currently under development. |
| 40 | + |
| 41 | +### check environment |
| 42 | + |
| 43 | +Validates the development environment and required tools. |
| 44 | + |
| 45 | +```bash |
| 46 | +thothctl check environment [OPTIONS] |
| 47 | +``` |
| 48 | + |
| 49 | +This command is currently under development. |
| 50 | + |
| 51 | +## Project Structure Validation |
| 52 | + |
| 53 | +The `check iac` command validates your project structure against rules defined in the `.thothcf.toml` file. The validation includes: |
| 54 | + |
| 55 | +1. **Required Folders**: Checks if all mandatory folders exist |
| 56 | +2. **Required Files**: Checks if all required files exist in the project root |
| 57 | +3. **Folder Content**: Checks if folders contain required files |
| 58 | +4. **Folder Hierarchy**: Validates the parent-child relationship between folders |
| 59 | + |
| 60 | +### Example Project Structure Rules |
| 61 | + |
| 62 | +```toml |
| 63 | +[project_structure] |
| 64 | +root_files = [ |
| 65 | + ".gitignore", |
| 66 | + ".pre-commit-config.yaml", |
| 67 | + "README.md" |
| 68 | +] |
| 69 | +ignore_folders = [ |
| 70 | + ".git", |
| 71 | + ".terraform", |
| 72 | + "Reports" |
| 73 | +] |
| 74 | + |
| 75 | +[[project_structure.folders]] |
| 76 | +name = "modules" |
| 77 | +mandatory = true |
| 78 | +content = [ |
| 79 | + "variables.tf", |
| 80 | + "main.tf", |
| 81 | + "outputs.tf", |
| 82 | + "README.md" |
| 83 | +] |
| 84 | +type = "root" |
| 85 | + |
| 86 | +[[project_structure.folders]] |
| 87 | +name = "environments" |
| 88 | +mandatory = true |
| 89 | +type = "root" |
| 90 | +``` |
| 91 | + |
| 92 | +## Validation Modes |
| 93 | + |
| 94 | +The check commands support two validation modes: |
| 95 | + |
| 96 | +- **soft**: Reports issues but doesn't fail the command (exit code 0) |
| 97 | +- **hard**: Reports issues and fails the command with a non-zero exit code if any issues are found |
| 98 | + |
| 99 | +```bash |
| 100 | +thothctl check iac --mode hard |
| 101 | +``` |
| 102 | + |
| 103 | +## Use Cases |
| 104 | + |
| 105 | +### Continuous Integration |
| 106 | + |
| 107 | +Add check commands to your CI/CD pipeline to validate infrastructure code before deployment: |
| 108 | + |
| 109 | +```yaml |
| 110 | +# Example GitHub Actions workflow |
| 111 | +jobs: |
| 112 | + validate: |
| 113 | + runs-on: ubuntu-latest |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v2 |
| 116 | + - name: Install ThothCTL |
| 117 | + run: pip install thothctl |
| 118 | + - name: Validate IaC |
| 119 | + run: thothctl check iac --mode hard |
| 120 | +``` |
| 121 | +
|
| 122 | +### Pre-commit Hooks |
| 123 | +
|
| 124 | +Use check commands in pre-commit hooks to validate changes before committing: |
| 125 | +
|
| 126 | +```yaml |
| 127 | +# .pre-commit-config.yaml |
| 128 | +repos: |
| 129 | + - repo: local |
| 130 | + hooks: |
| 131 | + - id: thothctl-check-iac |
| 132 | + name: ThothCTL Check IaC |
| 133 | + entry: thothctl check iac |
| 134 | + language: system |
| 135 | + pass_filenames: false |
| 136 | +``` |
| 137 | +
|
| 138 | +### Development Workflow |
| 139 | +
|
| 140 | +Run check commands during development to ensure your code meets requirements: |
| 141 | +
|
| 142 | +```bash |
| 143 | +# Before submitting a pull request |
| 144 | +thothctl check iac --check_type project |
| 145 | +``` |
| 146 | + |
| 147 | +## Examples |
| 148 | + |
| 149 | +### Basic Project Structure Check |
| 150 | + |
| 151 | +```bash |
| 152 | +thothctl check iac |
| 153 | +``` |
| 154 | + |
| 155 | +### Strict Module Validation |
| 156 | + |
| 157 | +```bash |
| 158 | +thothctl check iac --check_type module --mode hard |
| 159 | +``` |
| 160 | + |
| 161 | +### Recursive Terraform Plan Check with Markdown Output |
| 162 | + |
| 163 | +```bash |
| 164 | +thothctl check iac --check_type tfplan --recursive recursive --outmd |
| 165 | +``` |
| 166 | + |
| 167 | +### Check Project Structure with Dependencies |
| 168 | + |
| 169 | +```bash |
| 170 | +thothctl check iac --dependencies |
| 171 | +``` |
| 172 | + |
| 173 | +## Best Practices |
| 174 | + |
| 175 | +1. **Define Clear Rules**: Create detailed structure rules in your `.thothcf.toml` file |
| 176 | +2. **Version Control Rules**: Include your validation rules in version control |
| 177 | +3. **Consistent Validation**: Use the same validation rules across all environments |
| 178 | +4. **Automated Checks**: Integrate validation into your CI/CD pipeline |
| 179 | +5. **Documentation**: Document your project structure requirements |
| 180 | + |
| 181 | +## Troubleshooting |
| 182 | + |
| 183 | +### Common Issues |
| 184 | + |
| 185 | +#### Missing Configuration |
| 186 | + |
| 187 | +``` |
| 188 | +Using default options |
| 189 | +``` |
| 190 | + |
| 191 | +**Solution**: Create a `.thothcf.toml` file with your project structure rules. |
| 192 | + |
| 193 | +#### Validation Failures |
| 194 | + |
| 195 | +``` |
| 196 | +❌ - Required file main.tf missing in modules/network |
| 197 | +Project structure is invalid |
| 198 | +``` |
| 199 | + |
| 200 | +**Solution**: Add the missing file or update your structure rules if the file is not actually required. |
| 201 | + |
| 202 | +#### Permission Issues |
| 203 | + |
| 204 | +``` |
| 205 | +Error: [Errno 13] Permission denied: '/path/to/directory' |
| 206 | +``` |
| 207 | + |
| 208 | +**Solution**: Ensure you have read permissions for all directories being validated. |
| 209 | + |
| 210 | +### Debugging |
| 211 | + |
| 212 | +For more detailed logs, run ThothCTL with the `--debug` flag: |
| 213 | + |
| 214 | +```bash |
| 215 | +thothctl --debug check iac |
| 216 | +``` |
| 217 | + |
| 218 | +## Related Commands |
| 219 | + |
| 220 | +- [thothctl init project](commands/init/init_project.md): Initialize a new project with the correct structure |
| 221 | +- [thothctl scan](commands/scan/scan.md): Scan infrastructure code for security issues |
0 commit comments