-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompt for custom tfcloud host #1678
Prompt for custom tfcloud host #1678
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Convez, thanks for the updated PR. I appreciate your patience with the delays in reviewing your original PR and this one. I'm grateful for your continued contributions. The delay is not a reflection of the importance of your contributions, it's a result of new priorities and the need to manage shifting timelines.
For now, with your permission, I can do a couple of things to get some forward movement here. I would like to extract the bug fix for the Terraform credential path on Windows myself into a separate PR and attribute you for it. Then I'll rebase this PR so there is not so many merge commits in it and get it in a ready to review state. My team will be discussing TFE support in our quarterly planning in 2 weeks, after that I will let you know the results of that meeting and how that applies to this PR.
I again thank you for your patience.
Bump. |
9d8a9fb
to
51dd4a7
Compare
Hey @Convez, thanks for your patience. There are/have been several things in the air that either needed to land or be started before I could come back to this. The good news is I am picking this back up now. I've rebased and made a small commit updating some HCP Terraform renaming, which is minor. Then I have tested it against a test TFE instance that has over 10,000 workspaces, and the good news is it works which was a concern of ours since we didn't load test this extension with TFE workloads in mind. The bad news is I've hit two bugs, but only one is related to this PR. The one related to this PR is it not remembering the hostname after closing out VS Code. This seems to hit mostly with the temp profile, but did happen with my personal install. I think I found the resolution by storing the hostname along with the token in the secret store. This way it is present when the extension starts again. I still have to test it with expired tokens to make sure all the auth related scenarios still work, but I think that resolves it. The bug not related to your PR is refreshing the workspace view after loading a significant number of workspaces seems to fail with a duplicate key. I'll resolve that separately. The next steps is to finish out the testing auth scenarios, then we can go through the review process and get this merged. |
51dd4a7
to
273a5ab
Compare
Hello @jpogran , I see, please let me know if there is anything I can do to help from my side 😄 |
9abab90
to
0137d57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey 👋
I just test drove this PR a little and noticed a small inconsistency (which seems to have existed before) when opting to use an existing token from the Terraform CLI.
Steps to reproduce:
- Have an existing
~/.terraform.d/credentials.tfrc.json
file with e.g. credentials forapp.terraform.io
(doesn't really matter) - Login to HCP Terraform
- Select "New Instance"
- Put in some endpoint for which we don't have credentials in the TF CLI file
- Select "Stored user token"
- There's no error message but we also are not logged in
(this also happens for the "Default HCP Terraform Instance" login option if there are no credentials forapp.terraform.io
in thecredentials.tfrc.json
file)
A similar thing I noticed (that may be related) is that when selecting "Existing user token – Enter a token manually" and then entering an empty string the same behavior seems to happen (i.e. nothing happens, we are not logged in and no message is displayed). However, in this case I could see entering an empty string as a way of aborting (But the input also states "Press Esc to cancel" so there's that 😄)
Other than that, I could successfully log into a different instance 🎉 (I used it to log into the HCP Terraform staging instance for testing as I don't have a TFE instance ready).
Also: Do we need to add some note somewhere that it's only possible to log into one endpoint at a time? When I logged into the staging instance, another VS Code window of mine popped up from the background and told me that I was logged out of HCP Terraform and prompted me to login again 😅 Is this something we need to handle better? Is it already known, @jpogran?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With an existing session/login present, I'm getting this error on this branch
Steps to reproduce
- checkout
main
- start the extension
- login with your HCP Terraform credentials
- close the extension
- switch to this branch
- start the extension again
We might need something like a default fallback to HCP Terraform?
4a7a40c
to
501ceaa
Compare
This was a failure of the token check inside This should be fixed now.
This should be fixed by the above fix, which handles this similar scenario where there isn't a token returned.
Previously we only supported one endpoint, so there was only one login/token allowed and we would trigger a session refresh in all windows if one window changed. Now that we are accepting custom endpoints, it is a possibility but would require more work than this PR intends to cover. I can ticket this request |
This is because on load, we only checked if there was a persisted session and not if it had all of the properties we expected. This is fixed by checking to see if the stored session has a hostname, and if not adding the default HCP Terraform hostname then calling the session handler store method. This is a safe assumption because we know all prior sessions were only for HCP Terraform and we can update the stored session accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the hostname issue. It now works fine when starting from an existing login (main
).
I added a suggestion to reduce duplication in client creation, but feel free to ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that I have to select approve because I previously requested changes. Oops
This commit renames all instances of "Terraform Cloud" to "HCP Terraform" in the authentication provider in accordance with the branding changes.
This commit stores the hostname in the secret store when the user logs in. This ensures that the hostname is available when the user logs in again. This is necessary because the hostname is used to construct the API URL and the Web URL for a given TFE or HCP Terraform instance.
This changes the order of hostname options in the quick pick by moving the new hostname option to the bottom of the list and presenting existing host names first. This makes it easier for users to select an existing hostname if they have one, as that is most likely the more common workflow.
This change adds the ability to identify TFE instances by making a call to the `/ping` endpoint. This will allow the user to see the name of the instance they are connecting to in the quickpick menu. There is still some hardcoding of 'HCP Terraform' in the code that needs to be updated to be more generic, but that can be handled in a separate set of work.
This handles sessions created before this version without a hostname to connect to. This will set the hostname to the default Terraform Cloud API URL if it is undefined.
Instead of rebuilding the entire apiClient, we use the `pluginBaseURL` plugin to override the previous `baseURL`. This allows us to keep the endpoint setup in one place.
f2bf20c
to
f1f80d1
Compare
@Convez this is now merged to main, and will go out with the next release. Thank you for your patience, we really appreciate the contribution! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
This is a simplified version of PR #1673 , as requested


This closes #1671 and closes #1505
Allow TFC host selection during login. Hosts already in TFC credentials file are displayed. Options for insertion of new hosts added:
N.B. Logging to a new hostname does not update the TFC credentials file (Maybe to be implemented in the future?)