hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.88k stars 456 forks source link

Method chaining with addProvider() #900

Open bondsb opened 3 years ago

bondsb commented 3 years ago

Community Note

Description

The return type for addProvider() within TerraformModule is void: https://github.com/hashicorp/terraform-cdk/blob/2baf75f53b99e68cf53061a73ad6bd5aa69f02be/packages/cdktf/lib/terraform-module.ts#L62

This request is to return this, with type this:

  public addProvider(provider: TerraformProvider | TerraformModuleProvider) : this {
    if (!this._providers) {
      this._providers = [];
    }
    this._providers.push(provider);
    return this;
  }

in order to allow for convenient method chaining:

var myModule = new MyModule(this, "my_module", {
   someValue: "abcd",
}).addProvider(myProvider);
jsteinich commented 3 years ago

I think the team would be happy to accept a PR to add this.