Package: pyiaacsync
PyIAACSyncIntroductioninfrastructure-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 assetsBoth 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 golangIn 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 deletedPyIAACSync 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 beanything(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 callsSoftware engineers need to create the following to leveragepyiaacsync:A folder (iaac_sync_folder) that contains the specs/configs for the infrastructure to createA simple asset python file that contains a class describing the asset with the followingstaticfunctions: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 seeUsagesection that describes the example in more detailInstallvia PyPIpython3 -m pip install pyiaacsyncManuallyInstall all necessary dependencies as follows:python3 -m pip install -r requirements.txtUsageStructureWe will be using the exampleexample-fileassetdescribed in theexamplesfolder of this repository. Users of this repo can use the files in theexamplesfolder (especiallyfileasset.py) to build their own assets withpyiaacsync.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 fileNote thatpyiaacsyncalso has anargsoption 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 therandom_argsset line inexample.pyto see how it can be used:...
    random_args = {}
    ## uncomment line below to demonstrate how the random arguments can work
    #random_args = {'message': 'hello world'}Note: An additional example has been added in folder calledexample-fileasset-with-updatewhere thefileassetwupd.pyis a python file which additionally includes theupdatemethod in theFileAssetWithUpdateclass. The commands listed below also apply to files in this folder.ActionsinitThe first steps is to executeinitwhich will create a new state fileout-teststate.yaml:python3 example.py -a initTo 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 -ifWe can also specify an existing state file to use:python3 example.py -a init -if -f /tmp/out-teststatefile.yamlvalidate_configsTo validate the configs in the spec folder for all existing assets using thevalidatefunction defined infileasset.pyclass:python3 example.py -a validate_configssyncTo 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 syncTo sync the assets once only:python3 example.py -a sync_oncedelete_assetsTo delete all existing assets (in this case, all files) and remove the assets from the state file:python3 example.py -a delete_assetsTODOAdd unit testingFix the comments for create assetFix the bug in deleteassetAdd an assumption: Assuming that the API works ok - every action performed once (no retry)