-
Notifications
You must be signed in to change notification settings - Fork 98
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 agent token support #169
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.
Thanks for doing this, this looks great!
Some fixes are necessary and then this should be good to go.
Unfortunately, I cannot run the tests since I don't have a valid TFC plan to privately create agent pools.
Indeed, we've not yet been able to support a testing mechanism to allow trusted forks to run against our CI, sorry about that.
Here's the full output when I tried just now:
» go test -v ./... -timeout=30m -run TestAgentToken
=== RUN TestAgentTokensList
=== RUN TestAgentTokensList/with_no_list_options
agent_token_test.go:26:
Error Trace: agent_token_test.go:26
Error: "[%!s(*tfe.AgentToken=&{at-miXBXJQyjgjs3gWs {710000000 63746670870 <nil>} 3e4a4a34-1043-0bed-504d-ec1429735f60 {0 0 <nil>} }) %!s(*tfe.AgentToken=&{at-fhF7K7zbkhp1qH5Z {882000000 63746670870 <nil>} a0636446-0636-396b-dd17-2fcc05f8bef4 {0 0 <nil>} })]" does not contain "&{at-miXBXJQyjgjs3gWs 2021-01-19 16:34:30.71 +0000 UTC 3e4a4a34-1043-0bed-504d-ec1429735f60 0001-01-01 00:00:00 +0000 UTC YXwyw9WDvYauUg.atlasv1.zyjDMkK41HqhekztZHfJ1Un6rp18Th2kcWz2beXGB4IIzGxyZG2q3yyuhbpUmO6zLWQ}"
Test: TestAgentTokensList/with_no_list_options
agent_token_test.go:27:
Error Trace: agent_token_test.go:27
Error: "[%!s(*tfe.AgentToken=&{at-miXBXJQyjgjs3gWs {710000000 63746670870 <nil>} 3e4a4a34-1043-0bed-504d-ec1429735f60 {0 0 <nil>} }) %!s(*tfe.AgentToken=&{at-fhF7K7zbkhp1qH5Z {882000000 63746670870 <nil>} a0636446-0636-396b-dd17-2fcc05f8bef4 {0 0 <nil>} })]" does not contain "&{at-fhF7K7zbkhp1qH5Z 2021-01-19 16:34:30.882 +0000 UTC a0636446-0636-396b-dd17-2fcc05f8bef4 0001-01-01 00:00:00 +0000 UTC RGrapiJic5VyzA.atlasv1.omd4soBhyQ0AM4yNbDKVgNL9modFlQnTVDI5vl1yPQHyT74vZ0S6oBR9P8F3lcNGK9E}"
Test: TestAgentTokensList/with_no_list_options
agent_token_test.go:29: paging not supported yet in API
=== RUN TestAgentTokensList/without_a_valid_agent_pool_ID
=== CONT TestAgentTokensList
helper_test.go:82: Error destroying agent token! WARNING: Dangling resources
may exist! The full error is shown below.
AgentToken: apool-XcSs6woTqgac3StZ
Error: resource not found
helper_test.go:82: Error destroying agent token! WARNING: Dangling resources
may exist! The full error is shown below.
AgentToken: apool-XcSs6woTqgac3StZ
Error: resource not found
--- FAIL: TestAgentTokensList (2.26s)
--- FAIL: TestAgentTokensList/with_no_list_options (0.17s)
--- PASS: TestAgentTokensList/without_a_valid_agent_pool_ID (0.00s)
=== RUN TestAgentTokensGenerate
=== RUN TestAgentTokensGenerate/with_valid_description
=== RUN TestAgentTokensGenerate/without_valid_description
=== RUN TestAgentTokensGenerate/without_valid_agent_pool_ID
--- PASS: TestAgentTokensGenerate (1.30s)
--- PASS: TestAgentTokensGenerate/with_valid_description (0.17s)
--- PASS: TestAgentTokensGenerate/without_valid_description (0.00s)
--- PASS: TestAgentTokensGenerate/without_valid_agent_pool_ID (0.00s)
=== RUN TestAgentTokensRead
=== RUN TestAgentTokensRead/read_token_with_valid_token_ID
agent_token_test.go:83:
Error Trace: agent_token_test.go:83
Error: Not equal:
expected: "QT0xc6w4V3ErcA.atlasv1.0ltjbvSwYHxRnyiLaPGtROKgzyQLcMYz2704XVwnsCLLQB6bJmTyh0lJFIM64M0P4EA"
actual : ""
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-QT0xc6w4V3ErcA.atlasv1.0ltjbvSwYHxRnyiLaPGtROKgzyQLcMYz2704XVwnsCLLQB6bJmTyh0lJFIM64M0P4EA
+
Test: TestAgentTokensRead/read_token_with_valid_token_ID
=== RUN TestAgentTokensRead/read_token_without_valid_token_ID
=== CONT TestAgentTokensRead
helper_test.go:82: Error destroying agent token! WARNING: Dangling resources
may exist! The full error is shown below.
AgentToken: apool-DzLWRw9iJc83LXau
Error: resource not found
--- FAIL: TestAgentTokensRead (1.61s)
--- FAIL: TestAgentTokensRead/read_token_with_valid_token_ID (0.18s)
--- PASS: TestAgentTokensRead/read_token_without_valid_token_ID (0.00s)
=== RUN TestAgentTokensDelete
=== RUN TestAgentTokensDelete/with_valid_token_ID
=== RUN TestAgentTokensDelete/without_valid_token_ID
=== CONT TestAgentTokensDelete
helper_test.go:82: Error destroying agent token! WARNING: Dangling resources
may exist! The full error is shown below.
AgentToken: apool-bu3aZDkhKZSq7cLz
Error: resource not found
--- FAIL: TestAgentTokensDelete (1.59s)
--- PASS: TestAgentTokensDelete/with_valid_token_ID (0.14s)
--- PASS: TestAgentTokensDelete/without_valid_token_ID (0.00s)
FAIL
FAIL github.com/hashicorp/go-tfe 6.921s
? github.com/hashicorp/go-tfe/examples/organizations [no test files]
? github.com/hashicorp/go-tfe/examples/workspaces [no test files]
FAIL
agent_token_test.go
Outdated
tokenlist, err := client.AgentTokens.List(ctx, apTest.ID) | ||
require.NoError(t, err) | ||
assert.Contains(t, tokenlist.Items, agentToken1) | ||
assert.Contains(t, tokenlist.Items, agentToken2) |
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.
These fail; based on the test output it looks like some bits are mismatched so they aren't treated equal(?) Looks like the synonymous test for user tokens might be helpful here.
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.
First, it's about the token itself: it's returned at generating only and not if you read the token afterward.
And second, I think the list is returning correct IDs, and there seem to be differences in the timestamp representation.
Anyway, what I didn't get (while copy/pasting and search/replace most of the code 😉 ) is if I really need the AgentTokenList function? While implementing the tfe_agent_token resource, I didn't need it anywhere.
Should I remove it or is there any other need for 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.
Ah right, forgot about the token value being omitted on the read afterward.
You don't need the list function for your purposes in the provider resource but for the client in general but it's a perfectly valid and supported endpoint otherwise for the client, might as well keep it.
A few more tweaks needed to get tests to pass, and I figured you'd much rather have me just push them than have you continuing to try and make things pass that you can't actually run yourself! 😅 Pushed! |
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.
Looks good, thanks for your contribution!
@chrisarcand |
Description
This PR adds support to manage agent tokens.
I need it as a basis to implement agent token support into terraform-provider-tfe afterward.
External links
tfe_agent_pool_token
resource terraform-provider-tfe#250 Issue requesting support for agent token in terraform-provider-tfeOutput from tests
Unfortunately, I cannot run the tests since I don't have a valid TFC plan to privately create agent pools. But I did tests to manage agent tokens with our company TFC organization.