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
New Terraform Workspace select flag: -or-create
#31633
New Terraform Workspace select flag: -or-create
#31633
Conversation
Although I cannot commit to having this PR reviewed at this time, we acknowledge your contribution and appreciate it! |
@crw Does this comment mean that this PR will not be reviewed, or that there will be a delay in the review? This feature will be a huge help to those running terraform using docker. |
Hi @brittandeyoung, thanks for the bump. First off thanks for the great initial write-up for the PR - that is always a huge help. The initial feedback is that per #16191 (comment), a flag would be more appropriate than a new subcommand. Implementing this feature as a flag would make it more likely to get reviewed. Thanks for this submission, and apologies for the late response on this. |
8abd500
to
5932540
Compare
-or-create
-or-create
-or-create
@crw Pull request has been update to follow the strategy suggested. It is ready for review when you have time. Here is a screen shot running the binary local with both the select a valid state, select a missing state, and select a missing state with new |
Friendly bump @crw. Do we have an idea as to when or if this pull request will be able to be reviewed? The pull request is much smaller now using the flag. |
Hi @brittandeyoung, thanks for the bump! I admit I lost track of this due to the long Labor Day weekend. We are working on finishing up the 1.3 release so apologize if this process is going a bit slowly. There is a bit of functionality coming that may overlap with this feature -- I'm looking into whether it makes sense to review this or wait for the new functionality. I'll keep you updated. Thanks for your patience. |
@crw Thank you for the update. I will wait to hear back on what you find in terms of functionality overlap. |
c.Ui.Error(fmt.Sprintf(envDoesNotExist, name)) | ||
return 1 | ||
if orCreate { | ||
_, err = b.StateMgr(name) |
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.
This is a "Time of Check Time of Use" race condition, but the workspace select
command doesn't have the ability to take a lock. I think this may need to incorporate the new
command. I'll have to look into the other code path to see what that entails.
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.
OK, double checked and the StateMgr
implementations are expected to handle the check race again internally, so that's not an issue here. The missing options are then only to exclude the lock, but I think for the sake of keeping this simple, we can leave that to using the new
subcommand directly,
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.
@jbardin are there any changes needed? From reading your comments we are good to leave state locking for the new
command?
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.
@jbardin Are changes actually needed here? or am I able to resolve this 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.
sorry, no changes needed here
@crw Looks like 1.3.0 release is out. I did not see any potential overlap in the release notes. Any update on that end? |
@brittandeyoung Yes, apologies - @jbardin moving forward with the review is the acknowledgement that we are reviewing this for inclusion. I'll check with @jbardin on what we need to do to press "merge." Thanks again for the contribution! |
Hi @brittandeyoung, this is still on @jbardin's radar. He's just been busy closing issues in the 1.3 release of Terraform. This and one other community PR are in the pipe to be reviewed once 1.3 is stable. Thanks for checking in, apologies for the stop-and-start here. |
@crw thank you for the response. I will patiently wait for y'all to get caught up. I just wanted to make sure I wasn't missing something. |
Quick update that I have not forgotten this, we are still working on bugs from 1.3. This is still in the queue to be reviewed. |
@crw thank you for the update 👍 |
This would be a great feature for us, as our action feels needlessly complicated just to deal with the potential creation of a workspace :) |
1.3 seems to have settled out - I'll get this back in the queue. Thanks! |
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.
just a quick typo
Co-authored-by: James Bardin <j.bardin@gmail.com>
@brittandeyoung is attempting to deploy a commit to the HashiCorp Team on Vercel. A member of the Team first needs to authorize it. |
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
1.4, which is the next non-bugfix release. I believe it should start showing up in the alpha builds when we do the next one of those, which will likely be in January. |
Cheers :) |
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 contributions. |
This adds the new terraform workspace select flag
-or-create
. This flag is intended to make managing workspaces easier in CI environments where auto creating or selecting a workspace is useful (especially when using remote backend). This flag will first attempt to select the provided workspace name. If this workspace is not found, it will then create and select it.Traditionally this functionality has been achieved through some sort of scripting. We currently get this behavior using the following script:
terraform workspace select test || terraform workspace new test
; however, this does not work well when attempting to use the official terraform docker image as it does not handle shell scripts by design. Having this functionality in the terraform cli itself would be very useful. We want to be able to provide the same functionally locally to our developers as exists in our CI environment. Using the terraform official docker image helps provide this, but missing this functionality is making it difficult to auto provision workspaces for new projects. Calling theworkspace new
command will error if it already exists, and calling theworkspace select
command will error if it does not exist.This will especially help when using
terraform
with https://dagger.io or any other docker based CI as it relies on docker for running pipelines where bash scripting my not be an option.Closes: #16191