terraform icon indicating copy to clipboard operation
terraform copied to clipboard

New Terraform Workspace select flag: `-or-create`

Open brittandeyoung opened this issue 2 years ago • 15 comments

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 the workspace new command will error if it already exists, and calling the workspace 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

brittandeyoung avatar Aug 12 '22 13:08 brittandeyoung

CLA assistant check
All committers have signed the CLA.

hashicorp-cla avatar Aug 12 '22 13:08 hashicorp-cla

Although I cannot commit to having this PR reviewed at this time, we acknowledge your contribution and appreciate it!

crw avatar Aug 12 '22 18:08 crw

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

brittandeyoung avatar Aug 31 '22 14:08 brittandeyoung

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 https://github.com/hashicorp/terraform/issues/16191#issuecomment-332340691, 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.

crw avatar Aug 31 '22 16:08 crw

@crw Thank you for the direction. I will modify this PR to match what is requested in #16191 and update.

brittandeyoung avatar Aug 31 '22 16:08 brittandeyoung

@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 -or-create flag.

image

brittandeyoung avatar Aug 31 '22 17:08 brittandeyoung

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.

brittandeyoung avatar Sep 09 '22 14:09 brittandeyoung

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 avatar Sep 09 '22 22:09 crw

@crw Thank you for the update. I will wait to hear back on what you find in terms of functionality overlap.

brittandeyoung avatar Sep 13 '22 16:09 brittandeyoung

@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 avatar Sep 21 '22 17:09 brittandeyoung

@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!

crw avatar Sep 22 '22 01:09 crw

@crw and @jbardin Any update on this PR?

brittandeyoung avatar Sep 29 '22 18:09 brittandeyoung

@crw ans @jbardin any update on this pr? Am I missing a required change?

brittandeyoung avatar Oct 16 '22 23:10 brittandeyoung

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 avatar Oct 17 '22 21:10 crw

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

brittandeyoung avatar Oct 17 '22 22:10 brittandeyoung

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 avatar Nov 11 '22 22:11 crw

@crw thank you for the update 👍

brittandeyoung avatar Nov 12 '22 12:11 brittandeyoung

@crw and @jbardin . Friendly bump to make sure this didn't fall of the radar.

brittandeyoung avatar Dec 13 '22 14:12 brittandeyoung

This would be a great feature for us, as our action feels needlessly complicated just to deal with the potential creation of a workspace :)

anderssonw avatar Dec 13 '22 15:12 anderssonw

1.3 seems to have settled out - I'll get this back in the queue. Thanks!

crw avatar Dec 13 '22 20:12 crw

@brittandeyoung is attempting to deploy a commit to the HashiCorp Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 16 '22 20:12 vercel[bot]

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

github-actions[bot] avatar Dec 16 '22 20:12 github-actions[bot]

@jbardin @crw Any plans for which release this flag will be available?

anderssonw avatar Dec 19 '22 10:12 anderssonw

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.

crw avatar Dec 20 '22 01:12 crw

Cheers :)

anderssonw avatar Dec 20 '22 08:12 anderssonw

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. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Jan 21 '23 02:01 github-actions[bot]