Terraform login

Hello,

I would like to use terraform login command together with an existing team API token. I don’t want to generate a new one and if it is possible automate it, like wrap it in a shell line. What I am trying to achieve, login and save my state file in the workspace.
If not terraform login, what would be the best way to do it with your pipeline?

I am new to terraform, any help much appreciated.

Thanks,
Futtidu

Hi @futtidu,

The purpose of the login command is to issue a new token, so this command won’t be useful to you if you already have a token to use.

After issuing a token the command will write it to a file in your home directory and announce what it wrote. You can write your own script that generates a similar file with the token you wish to use. The file is in JSON format, so should be possible to generate it using any language with a JSON library.

Terraform searches the whole directory where the login command creates its file for any files ending in .tfrc.json so you can use a different filename named after your script as long as it is in the same directory and has the same suffix. If you use a different filename then your script won’t interfere with any existing tokens previously issued by terraform login.

Ok, thank you for your answer. I believe I will take another approach. I will save the token in my Jenkins as config. Then I will issue a command to pass it while pipeline run populating the .terraformrc file, so I won’t need to use the actual login command. Thank you for clarifying it @apparentlymart :wink:

I hope it make sense to you :+1: