starhawking / python-terrascript

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

Feature/multiple providers #27

Closed vfoucault closed 6 years ago

vfoucault commented 6 years ago
mjuenema commented 6 years ago

Thanks very much for that pull request. I am currently updating .travis.yml to accomodate the 0.11.4 release of Terraform and to test your pull request on Travis-CI.

mjuenema commented 6 years ago

Terraform's JSON syntax is really badly documented. Anyway, after a lot of trial-and-error I worked out that the correct syntax for multiple providers is this.

{
  "provider":
    {
      "aws": 
      {
        "NAME1": "",
        "NAME2": ""
      },
      "google": 
      {
        "NAME3": "",
        "NAME4": ""
      }
    }
}

Another big problem I currently have that I made a bad design decision when I started this project. The terraform/__init__.py module has a "hidden" variable config which gets populated behind the scenes whenever you initialise a new resource, provider, backend, etc. For a start that's bad practice but I also realised today that it absolutely sabotages my (nose)tests. So I am now in the process of rewriting everything so that one has to explicitly create an instance of a new terrascript.Terrascript class to which one can then add resources, etc. Example

t = terrascript.Terrascript()
t += provider('aws', region='us-east-1')     # The + operator is overloaded
t.validate()                                 # This now also runs 'terraform init' to download plugins!
t.dump()

This will also solve issue #26. Once that is stable I am going to merge your pull request :-)

mjuenema commented 6 years ago

I manually merged your feature branch into my feature branch and added tests. See tests/test_issues.py for details. Release 0.5.0 introduces the terrascript.Terrascript class which makes it backwards-incomaptible with earlier releases.

mjuenema commented 6 years ago

I am going to "reject" this pull request as I manually merged your change already. Thanks a lot for your work.