Skip to content

Commit

Permalink
✨ 🎨 Add file operations and improve existing functions
Browse files Browse the repository at this point in the history
Improvements:
* Running `terragrunt render-json` to read module's config dynamically.
* Better class inheritance.
* Removed repetitive code.
* Various small fixes.
* Added docstrings.
* Added general exception handling.
* Updated documentation.
* Updated project structure.
  • Loading branch information
ChristophShyper committed Feb 22, 2025
1 parent 84bd56a commit 883f9c7
Show file tree
Hide file tree
Showing 11 changed files with 923 additions and 464 deletions.
102 changes: 65 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Velez

Python framework for interacting with Terragrunt configurations and performing various cloud operations.

![Velez](velez.jpg)
DevOps/CloudOps CLI framework for making work with Terragrunt and performing various cloud operations much easier.

<a href="https://gitmoji.dev">
<img
Expand All @@ -11,8 +9,43 @@ Python framework for interacting with Terragrunt configurations and performing v
/>
</a>


![Velez](img/velez.jpg)


## Features

- Supporting following services/tools and operations on them:
- Terragrunt:
- Walk directory structure containing Terragrunt modules.
- Run Plan on a selected module or a specific target.
- Run Apply on a selected module or a specific target.
- Import a resource to the state.
- Run Destroy on a selected module or a specific target.
- Run Output on a selected module or a specific target.
- Run Validate on a selected module.
- Run Refresh on a selected module.
- Run State operations like:
- List resources.
- Move a resource.
- Remove a resource.
- Show resource.
- Pull and push state.
- Run Module operations on source modules:
- Move a module to a new directory, including moving remote state.
- Destroy resources and backend of the module.
- Destroy backend of the module.
- Taint and Untaint a resource.
- Unlock module and show lock information.
- File operations:
- Formatting all HCL files in the project.
- Cleaning up temporary files in the project or a selected module.


## Installation

Framework is written in Python and can be installed as a package.

1. Clone the repository:
```sh
git clone https://github.com/devops-infra/velez.git
Expand All @@ -21,7 +54,18 @@ Python framework for interacting with Terragrunt configurations and performing v
```sh
cd velez
```
3. Install the package:
3. Install other dependencies:
* Install Python if not installed yet - required.
* Install `hcledit` - required for updating `.hcl` files.
* Install `direnv` if not installed yet - highly suggested for managing environments.

It can be installed, e.g. by running:
```sh
brew install python
brew install direnv
brew install minamijoyo/hcledit/hcledit
```
4. Install the package:
```sh
pip install .
```
Expand Down Expand Up @@ -58,9 +102,11 @@ velez --terragrunt <operation> <module> <other-arguments>
```

Where:
* `<operation>` is a Terraform/Terragrunt operation to perform, e.g. `plan`.
* `<module>` is a relative path to a Terragrunt module to operate on, e.g. `aws/dev-account`.
* `<other-arguments>` are additional arguments for the operation, e.g. `--target=module.resource`.

* `<operation>` is a Terraform/Terragrunt operation to perform, e.g. `plan`.
* `<module>` is a relative path to a Terragrunt module to operate on, e.g. `aws/dev-account`.
* `<other-arguments>` are additional arguments for the Terraform and Terragrunt operations, e.g.
`--target=module.resource`.

For example for the following directory structure:

Expand All @@ -79,50 +125,32 @@ For example for the following directory structure:
Run the following command to plan the `aws/dev-account` module:

```sh
velez --terragrunt plan aws/dev-account
velez -tg plan aws/dev-account
```


## Configuration

Velez expects following environment variables to be set:
* `VELEZ_USE_S3_BACKEND` - set to `true` if you use AWS S3 backend for storing Terraform state. Acts as set to `true` by default.
* `VELEZ_USE_DYNAMODB_LOCKS` - set to `true` if you use AWS DynamoDB for locking Terraform state. Acts as set to `true` by default.
Velez expects following environment variables to be set if corresponding values are not hardcoded in the root Terragrunt
configuration file:

For your convenience, you can set these variables in a `.env` file in the project directory and use the `dotenv` to load them.
* `VELEZ_ROOT_HCL` - relative path to the Terragrunt configuration file, e.g. `root.hcl`.
* `VELEZ_TEMP_CONFIG` - absolute path to a temporary file created to render Terragrunt configuration, e.g.
`/tmp/terragrunt.hcl`.

For the convenience, these variables can be set in a `.env` file in the project directory and use the `direnv` (mentioned above) to load
them automatically for every project separately.

## Features
Veles will read Terragrunt configuration and expand any dynamic config available statically.
For example for each selected Terragrunt module backed configuration will be read to determine exact values of the S3 bucket and DynamoDB table and key used for locking the state.

- Supporting following services/tools and operations on them:
- Terragrunt:
- Walk directory structure containing Terragrunt modules.
- Run Plan on a selected module or a specific target.
- Run Apply on a selected module or a specific target.
- Import a resource to the state.
- Run Destroy on a selected module or a specific target.
- Run State operations like:
- List resources.
- Move a resource.
- Remove a resource.
- Show resource.
- Pull and push state.
- Run Module operations on source modules:
- Move a module to a new directory, including backend references.
- Destroy resources and backend of the module.
- Destroy backend of the module.
- Taint and Untaint a resource.
- Unlock module.
- Run Output on a selected module or a specific target.
- Run Validate on a selected module.
- Run Refresh on a selected module.


## License

This project is licensed under the MIT License.


## Velez

Name of the project is a misspelled name of the slavic god of the underworld - [Veles](https://en.wikipedia.org/wiki/Veles_(god)).
Name of the project is a misspelled name of the slavic god of the
underworld - [Veles](https://en.wikipedia.org/wiki/Veles_(god)).
File renamed without changes
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pick==2.4.0
setuptools==75.8.0
boto3==1.36.25
python-hcl2==6.1.1
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

setup(
name='velez',
version='0.1.0',
py_modules=['velez', 'terragrunt_ops'],
version='0.2.0',
packages=find_packages(),
install_requires=[
'pick',
'boto3',
'python-hcl2'
],
entry_points={
'console_scripts': [
'velez=velez:main',
'velez=velez.velez:main',
],
},
)
)
Loading

0 comments on commit 883f9c7

Please sign in to comment.