# Terraform login

**URL:** <https://discuss.hashicorp.com/t/terraform-login/44209>\
**Category:** HCP Terraform\
**Tags:** hcp-terraform\
**Created:** [September 12, 2022, 9:23pm UTC](https://discuss.hashicorp.com/t/terraform-login/44209 "2022-09-12T21:23:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![futtidu](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/futtidu/32/26922_2.png) [@futtidu](https://discuss.hashicorp.com/u/futtidu)\
**Post date:** [September 12, 2022, 9:23pm UTC](https://discuss.hashicorp.com/t/terraform-login/44209/1 "2022-09-12T21:23:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [September 13, 2022, 3:47pm UTC](https://discuss.hashicorp.com/t/terraform-login/44209/2 "2022-09-13T15:47:24Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![futtidu](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/futtidu/32/26922_2.png) [@futtidu](https://discuss.hashicorp.com/u/futtidu)\
**Post date:** [September 13, 2022, 7:52pm UTC](https://discuss.hashicorp.com/t/terraform-login/44209/3 "2022-09-13T19:52:17Z")

</div>

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😉

I hope it make sense to you 👍
