This package is available on pypi, you can for example use on of these commands (pipx is recommended)
pipx install cfn-drift-remediation
pip install cfn-drift-remediation
- Run drift detection on a stack, and verify that you want to remediate it by changing the provisioned resource (using the stack as the source of truth).
- run one of the commands below
- Run drift detection again to verify that everything is in sync again.
# Default usage
cfn-drift-remediation stack_name
# Using a different profile
AWS_DEFAULT_PROFILE=profile-name cfn-drift-remediation stack_name
# Using a third party tool like aws-vault
aws-vault exec profile-name -- cfn-drift-remediation stack_name
This tool will read the existing drift of a stack, iterate through the drifted resources and construct a patch document to change the actual (detected) property values to the expected (stack) values.
- Changes are done with CloudControl API. This does mean that if the drifted resources do not support Cloud Control API, they will be skipped.
- For some resources the order in a list does not matter, this might lead to a failure to apply changes, because Cloud Control API will assume the resource is not in the drifted state it expects.
- We do not support creating resources that were completely deleted from the stack. The drift detection api does not return enough information to construct the replacement resource.
We use poetry to manage this project
- Clone this repository
- Run
poetry install
- Activate the virtualenvironment with
poetry shell
(you can also usepoetry run $command
)
- Edit pyproject.toml to update the version number
- Edit cfn_drift_remediation/_init.py to update the version number
- Commit the version number bump
- Run tests
poetry run pytest
(you might have to install dependencies withpoetry install --dev
) - Tag the commit with the version number
git tag x.y.z
- Push to GitHub with
git push --tags
, this will create a new release in pypi and GitHub
If you want to use poetry in Visual Studio Code, it works best if the virtual environment is created inside the project folder. Once the virtual environment is created, you can run the "Python: Select interpreter" command in Visual Studio Code, and point to the .venv
folder.
poetry config virtualenvs.in-project true
If you already created the virtual environment, you have to recreate it
# from within the project folder
poetry env remove $(poetry env list)
poetry install