title: Edit Terraform configuration files programmatically with Python
body: <p>I am trying to edit Terraform configuration files with Python. I am parsing Terraform files (.tf) using python <a href="https://pypi.org/project/python-hcl2/" rel="noreferrer">hcl2</a> library which returns a python dictionary. I want to add new key/value pairs or change some values in the dictionary. Directly writing to the file is not a good practice since the returned python dictionary is not in Hashicorp Configuration Language format. Also there can be multiple configuration files like variables.tf etc. which are linked together. Should I implement my own serializer which converts python dictionary to terraform configuration file or is there an easier way to do it?</p>