terranix icon indicating copy to clipboard operation
terranix copied to clipboard

multiple aws provider clash with already defined attributes

Open Westixy opened this issue 2 years ago • 2 comments

Hi, I'm trying to port a configuration from an terraform project to terranix and I think I'll not be able to do it (maybe I'm wrong)

so for a bit of context this is my config.nix

{lib, config}:
let
  region = "eu-west-1";
  profile = "\${}"; 
  # ...
in {
  # ...
  provider.aws = {
    inherit profile region;
  };
  provider.aws = {
    alias = "central";
    region = "eu-central-1";
    inherit profile;
  };
}

and then I get this error (which make sense to me)

error: attribute 'region' already defined at .../config.nix:37:7
       at .../config.nix:33:14:

           32|     provider.aws = {
           33|       inherit profile region;
             |              ^
           34|     };

So is there already a way to do that ?

Thanks in advance

Westixy avatar Jun 28 '22 14:06 Westixy

Found the solution, I'll put it here if needed by other. just need to read a bit the documentation of terraform json: https://www.terraform.io/language/syntax/json#provider-blocks

so you can do that with

{
  provider.aws = [{
    inherit region profile;
  } {
    alias = "central";
    region = "eu-central-1";
    inherit profile;
  }];
}

Westixy avatar Jun 28 '22 14:06 Westixy

Good point, and the solution is correct. I reopened the ticket to document this approach. But it will take a wile till I find the time for it.

Thx @Westixy

mrVanDalo avatar Jun 28 '22 15:06 mrVanDalo

Added documentation issue - https://github.com/terranix/terranix-website/issues/15

mdarocha avatar Jun 23 '23 11:06 mdarocha