starhawking / python-terrascript

Create Terraform files using Python scripts.
BSD 2-Clause "Simplified" License
515 stars 76 forks source link

Unable to update terraform block when added #120

Open ilons opened 4 years ago

ilons commented 4 years ago

I'm trying to define my terraform resource to the configuration in multiple steps, first adding backend, and later add required_version.

I'm not certain if this is a bug or feature request, but I would expect to be able to add the resource multiple times, and have the properties merged, similar to how I can add multiple resources of other types.

My idea of how it would work is something like:

import terrascript
config = terrascript.Terrascript()
config += terrascript.terraform(backend=terrascript.backend("azurerm"))
config.add(terrascript.terraform(required_version="0.13.1"))
{'backend': {'azurerm': {}}, 'required_version': '0.13.1'}

While currently you only get the latest added resource:

import terrascript
config = terrascript.Terrascript()
config += terrascript.terraform(backend=terrascript.backend("azurerm"))
config.add(terrascript.terraform(required_version="0.13.1"))
{'terraform': {'required_version': '0.13.1'}}

What differs here is that the terraform block is a simple dict, while for example provider contains a list for each type.