Multiple tokens for different accounts in

Hi all,
I searched in the discussions but couldn’t find the answer.

I need to access 2 complete different accounts from (2 companies that have nothing to do between them) and I’m need also sometimes to use the Terraform CLI.

I couldn’t find a way to configure both tokens on my laptop: is there any way to do it using the .terraformc or ~/.terraform.d/credentials.tfrc.json CLI configuration files?


Hi @cloudmaniac,

The credentials model for Terraform is one set of credentials per hostname, so there’s no built in way to select different credentials per account. Indeed, the credentials used dictate which accounts you have access to, rather than the other way around.

What you could do, though, is to set the TF_CLI_CONFIG_FILE environment variable to point to some other file, which Terraform will then use instead of ~/.terraformrc as the initial configuration file.

(Terraform will still read and use the files in ~/.terraform.d, so to use this approach you’ll need to make sure there are no credentials "" { ... } blocks in those files that would otherwise conflict with your new separate file.)

I see, that’s what I was afraid of. :expressionless:
I’ll see how I can handle that long term.

Thx for the answer!

@cloudmaniac I ran into the same problem. Did you go with TF_CLI_CONFIG_FILE or did you figure out another solution?

I used the TF_CLI_CONFIG_FILE as I had to move on.