python-terrascript icon indicating copy to clipboard operation
python-terrascript copied to clipboard

Add support for `required_providers`

Open jbscare opened this issue 4 years ago • 5 comments

Terraform added the required_providers block a while ago, and as of Terraform 0.14, it gives a warning at plan time if you don't have one. It'd be great if Terrascript supported this! See https://www.terraform.io/docs/configuration/provider-requirements.html#requiring-providers for details.

jbscare avatar Dec 04 '20 15:12 jbscare

Came here to ask if this is supported and, if not, if it could be added!

Need to add the equivalent to this HCL:

terraform {
  required_providers {
    datadog = {
      source = "datadog/datadog"
    }
  }
}

robinbowes avatar Jan 05 '21 10:01 robinbowes

As of today, this is easy to add to ones generated configuration like this:

Python 3.8.6 (default, Sep 25 2020, 00:00:00) 
[GCC 10.2.1 20200723 (Red Hat 10.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import terrascript
>>> terrascript.Terrascript(terrascript.terraform(required_providers={"aws": {"source": "hashicorp/aws", "version": "~> 3.0"}}))
{'terraform': {'required_providers': {'aws': {'source': 'hashicorp/aws', 'version': '~> 3.0'}}}}

What is the requested feature? That any provider that gets added to the config are automatically added as a required_provider as well? This would be possible to do for the providers where a version have been specified, but would otherwise be hard.

ilons avatar Jan 22 '21 14:01 ilons

I agree that automatically adding providers to required_providers would be hard -- we're planning to use Terrascript to write code that does that, and we'll require versions in our configs, but I don't think Terrascript itself should be enforcing that.

I hadn't put together that you could do it like in your example, but looking at our code now, I see that this is how we do backends too, so the same thing should work here! Let me try it out, and if it works as expected for us, I'll close this out. Stay tuned!

jbscare avatar Jan 22 '21 15:01 jbscare

@jbscare I realized there is some limitations for the terraform property (namely, you can not update it by providing it multiple times). I prepared a fix for that: https://github.com/mjuenema/python-terrascript/pull/142 which I intent do get into develop ASAP.

ilons avatar Jan 25 '21 07:01 ilons

The solution @ilons suggested above will be documented in release 0.10.0.

mjuenema avatar May 23 '21 03:05 mjuenema