Deploy infrastructure as code via polling
Project description
PyIAACSync
Introduction
infrastructure-as-code tools such as Terraform and Palumi are gaining popularity and increasingly becoming neceessary to support the principles of Site Reliability Engineering (SRE).
However, there are a couple of disadvantages in existing tools in the market:
- Terraform requires knowledge of golang to be able to sync assets
- Both Terraform and Palumi plugins can be quite complex for beginners to manage and maintain - As in 2023, Terraform plugins require modules to be built in golang
- In a shared environment, where some assets are being built manually while others are being built using automation, tools like Terraform Automation can fail if assets managed by automation are deleted
PyIAACSync provides a framework which allows software engineering teams getting into infrastructure-as-code to easily create and sync assets which they have defined in YAML spec files, in a polled manner (non-event driven). The infrastructue components can be anything (AWS asset, GCP asset, any SIEM detection rule) that can be:
a. described in YAML files, and
b. can be read, created or deleted via API calls
Software engineers need to create the following to leverage pyiaacsync:
- A folder (
iaac_sync_folder) that contains the specs/configs for the infrastructure to create - A simple asset python file that contains a class describing the asset with the following
staticfunctions:validate: to validate whether the spec/config that has been supplied in thecreate: to create the asset via the supplied spec/configdelete: to delete that has been supplied via the spec/configcheck: to check whether the asset that has been deployed matches the spec/config akaintegrity check. If not, the asset will be re-createdupdate(Optional): to be called to update an existing asset, eg when the configuration gets changed. If not defined for the assets , then thedelete/creategets called.
Please see Usage section that describes the example in more detail
Install
via PyPI
python3 -m pip install pyiaacsync
Manually
Install all necessary dependencies as follows:
python3 -m pip install -r requirements.txt
Usage
Structure
We will be using the example example-fileasset described in the examples folder of this repository. Users of this repo can use the files in the examples folder (especially fileasset.py) to build their own assets with pyiaacsync.py.
In this folder, we have the following objects:
exampleconf: a folder which contains 3 spec/config files (1 file is in a subfolder) that describe what kind of file to createfileasset.py: A python file that contains the fileasset which defines how tovalidatethe spec config file,createasset from the spec / config file,deletethe existing asset created from the config file and alsocheckif the the created asset is different from the config fileexample.py: the main script which will invoke the creation of assets using pyiaacsync conf file
Note that pyiaacsync also has an args option available in __init__ which can be used to provide any additional optional
parameters as a dict that can be used by the asset class. Uncomment the random_args set line in example.py to see how it can be used:
...
random_args = {}
## uncomment line below to demonstrate how the random arguments can work
#random_args = {'message': 'hello world'}
Actions
init
The first steps is to execute init which will create a new state file out-teststate.yaml:
python3 example.py -a init
To force re-creation of the state file even if it exists (NOTE: Beware this will delete the existing state file!):
python3 example.py -a init -if
We can also specify an existing state file to use:
python3 example.py -a init -if -f /tmp/out-teststatefile.yaml
validate_configs
To validate the configs in the spec folder for all existing assets using the validate function defined in fileasset.py class:
python3 example.py -a validate_configs
sync
To sync the assets based on the spec/configs folder continuously - this will create the files as per the configs in the folder. Any changes made to the files the next time will be reset.
python3 example.py -a sync
To sync the assets once only:
python3 example.py -a sync_once
delete_assets
To delete all existing assets (in this case, all files) and remove the assets from the state file:
python3 example.py -a delete_assets
TODO
- Add unit testing
- Fix the comments for create asset
- Fix the bug in deleteasset
- Add an assumption: Assuming that the API works ok - every action performed once (no retry)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyiaacsync-0.6.tar.gz.
File metadata
- Download URL: pyiaacsync-0.6.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9143270dd898027a5ec851ee1917a08e71945e4a1b51fae2b15c2238677f120
|
|
| MD5 |
f6b39ec1dc5269fd9918fd1c902bba1f
|
|
| BLAKE2b-256 |
397ee2969855f65c23cf911b4eeee828a54c4e1747c8eacad72355ffcf98c7ae
|
File details
Details for the file pyiaacsync-0.6-py3-none-any.whl.
File metadata
- Download URL: pyiaacsync-0.6-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21f35d4d21808af7ed55b1c223b0bff08e50f1d17165c8973353b70304b7dfcd
|
|
| MD5 |
b5753752535399a68a06570d79e8a511
|
|
| BLAKE2b-256 |
493ed44421aa8162b0d36ae7727e036a409471ea23780603e58a687f1067f848
|