Skip to content
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

Add workspace show command #15157

Merged
merged 5 commits into from
Jul 5, 2017

Conversation

michaelhelmick
Copy link
Contributor

I didn't see an easy way to display the current env (except for env list and the * next to the current env)

This pull request adds terraform env show which looks something like this:

mikehelmick@local [dev-env-show] ✅  bin/terraform env show
default

@apparentlymart
Copy link
Contributor

Thanks for this, @michaelhelmick!

This does seem like a reasonable way to get the name in a way that's useful in wrapper scripts, etc.

In 0.10 we're actually going to rename the env subcommand to workspace, due to feedback about the confusing overlap of the term "environment" with other concepts in and around Terraform, so I'd like to hold off on merging this for the moment until we're able to land #14952, which will then unfortunately cause some merge conflicts for your PR here but I think it shouldn't be too hard to resolve.

Thanks again for working on this, and sorry for the friction as we get through the integration phase for the 0.10 release.

@michaelhelmick
Copy link
Contributor Author

No worries, I'll keep an eye out for 0.10 and come back to this pull request and fix any conflicts!

@nanoz
Copy link

nanoz commented Jun 7, 2017

Until then, maybe you could use 'cat .terraform/environment' :)

@apparentlymart
Copy link
Contributor

Heh... that will indeed work for now, and we're not planning to rename that file to workspace yet in 0.10 for reasons of risk/time, but note that we don't consider that file to a stable interface, so we reserve the right to rename it to workspace (or indeed to anything else!) in future without notice, since it's considered an implementation detail.

@apparentlymart
Copy link
Contributor

Hi again @michaelhelmick!

With the switch to terraform workspace ... merged I've rebased your changes here to apply to that. Since this command didn't exist before we don't need the compatibility shim, so I just wired it up as terraform workspace show without the associated terraform env show.

If you have the time it'd be good to have a simple test for this in the workspace_command_test.go file... since this is a pretty simple command I think we don't need anything too complex here. If you're not able to do it then no worries... I can have a whack at it myself when I get a chance.

@michaelhelmick
Copy link
Contributor Author

michaelhelmick commented Jun 28, 2017

@apparentlymart Thanks! I attempted to add a test, but am see this:

mikehelmick@local [dev-env-show] ⚡️  make test TEST=./command
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/06/28 13:04:40 Generated command/internal_plugin_list.go
go test -i ./command || exit 1
echo ./command | \
		xargs -t -n4 go test  -timeout=60s -parallel=4
go test -timeout=60s -parallel=4 ./command
--- FAIL: TestWorkspace_createAndShow (0.00s)
	workspace_command_test.go:130: bad: 1

FAIL
FAIL	github.com/hashicorp/terraform/command	13.442s

Any idea where I'm going wrong?

make dev
bin/terraform workspace show

Still works...

not sure if something other than nil should be passed to

if code := showCmd.Run(nil); code != 0 {
    t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
}

workspace := c.Workspace()
c.Ui.Output(workspace)

return 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh... I didn't catch this on the first pass. We need to return 0 here to indicate that the command has completed without error. Numbers greater than zero indicate errors, as we can see with the flag parse error above.

@michaelhelmick
Copy link
Contributor Author

@apparentlymart fixed the return code but looks like the first show succeeds but the second show doesn't.

--- FAIL: TestWorkspace_createAndShow (0.00s)
	workspace_command_test.go:166:
		expcted: "test_a"
		actual:  "<nil>"
FAIL

@michaelhelmick
Copy link
Contributor Author

@apparentlymart Found it! Was referencing the wrong ui

@michaelhelmick michaelhelmick changed the title Add env show command Add workspace show command Jun 30, 2017
@apparentlymart apparentlymart merged commit 9d7fce2 into hashicorp:master Jul 5, 2017
@apparentlymart
Copy link
Contributor

Awesome. Thanks, @michaelhelmick!

@michaelhelmick michaelhelmick deleted the dev-env-show branch July 6, 2017 14:14
@ghost
Copy link

ghost commented Apr 8, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants