Skip to content

Add UserTokensEnabled field for Organizations#1225

Merged
emlanctot merged 6 commits intomainfrom
jspiker/user-token-enablement
Dec 12, 2025
Merged

Add UserTokensEnabled field for Organizations#1225
emlanctot merged 6 commits intomainfrom
jspiker/user-token-enablement

Conversation

@JarrettSpiker
Copy link
Copy Markdown
Contributor

@JarrettSpiker JarrettSpiker commented Sep 23, 2025

Description

Adds UserTokensEnabled for Organizations.

This new HCP Terraform setting defaults to true. When disabled by an organization owner, user tokens will no longer be permitted to access the organization's resources through the API.

Testing plan

  1. Validate that the setting can be read from existing orgs
  2. Test creating orgs with the setting enabled/disabled
  3. Test updating an org to enable/disable the setting
  4. Validate that the setting is not included in update request serialization if not specified

External links

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

/usr/local/bin/go test -timeout 3000s -run ^TestOrganizationsUpdate$ github.com/hashicorp/go-tfe

=== RUN   TestOrganizationsUpdate
=== RUN   TestOrganizationsUpdate/with_HCP_Terraform-only_options
--- PASS: TestOrganizationsUpdate/with_HCP_Terraform-only_options (2.83s)
=== RUN   TestOrganizationsUpdate/with_new_AggregatedCommitStatusEnabled_option
--- PASS: TestOrganizationsUpdate/with_new_AggregatedCommitStatusEnabled_option (5.25s)
=== RUN   TestOrganizationsUpdate/with_new_SpeculativePlanManagementEnabled_option
--- PASS: TestOrganizationsUpdate/with_new_SpeculativePlanManagementEnabled_option (3.65s)
=== RUN   TestOrganizationsUpdate/with_new_UserTokensEnabled_option
--- PASS: TestOrganizationsUpdate/with_new_UserTokensEnabled_option (5.66s)
=== RUN   TestOrganizationsUpdate/with_valid_options
--- PASS: TestOrganizationsUpdate/with_valid_options (3.72s)
=== RUN   TestOrganizationsUpdate/with_invalid_name
--- PASS: TestOrganizationsUpdate/with_invalid_name (0.00s)
=== RUN   TestOrganizationsUpdate/with_agent_pool_provided,_but_remote_execution_mode
--- PASS: TestOrganizationsUpdate/with_agent_pool_provided,_but_remote_execution_mode (3.75s)
=== RUN   TestOrganizationsUpdate/when_only_updating_a_subset_of_fields
--- PASS: TestOrganizationsUpdate/when_only_updating_a_subset_of_fields (2.16s)
=== RUN   TestOrganizationsUpdate/with_different_default_execution_modes
--- PASS: TestOrganizationsUpdate/with_different_default_execution_modes (3.93s)
--- PASS: TestOrganizationsUpdate (31.59s)
PASS
ok      github.com/hashicorp/go-tfe
...

Rollback Plan

If we need to revert this change before a go-tfe release, we will.

Changes to Security Controls

no

@JarrettSpiker JarrettSpiker requested a review from a team as a code owner September 23, 2025 21:33
@JarrettSpiker JarrettSpiker marked this pull request as draft September 23, 2025 21:33
@JarrettSpiker JarrettSpiker force-pushed the jspiker/user-token-enablement branch from bf749f0 to 62ba5e8 Compare September 24, 2025 15:53
@JarrettSpiker JarrettSpiker force-pushed the jspiker/user-token-enablement branch from 62ba5e8 to 7eb9144 Compare November 25, 2025 19:11
@JarrettSpiker JarrettSpiker marked this pull request as ready for review November 25, 2025 19:13
@JarrettSpiker JarrettSpiker changed the title [DRAFT] Add UserTokensEnabled field for Organizations Add UserTokensEnabled field for Organizations Nov 25, 2025
@datadog-terraform-cloud-hashicorp
Copy link
Copy Markdown

datadog-terraform-cloud-hashicorp bot commented Nov 25, 2025

⚠️ Tests

⚠️ Warnings

❄️ 4 New flaky tests detected

TestCostEstimatesRead_RunDependent from cost_estimate_integration_test.go (Datadog)
Run "run-GYjzvycVgEgxeJW1" unexpectedly errored
TestRunsListQueryParams_RunDependent from run_integration_test.go (Datadog)
Run "run-YRbCUCqTgzy3Prbj" unexpectedly errored
TestWorkspaces_AddTags from workspace_integration_test.go (Datadog)
failed test
TestWorkspaces_AddTags/successfully_adds_tags_by_id_and_name from workspace_integration_test.go (Datadog)

	Error Trace:	/home/runner/work/go-tfe/go-tfe/workspace_integration_test.go:2919
	            				/home/runner/go/pkg/mod/github.com/!data!dog/dd-trace-go/v2@v2.4.0/internal/civisibility/integrations/gotesting/instrumentation_orchestrion.go:242
	Error:      	Not equal: 
	            	expected: "tag-NPxJdPpBesdMtg4E"
	            	actual  : "tag-JGWep3M9JNY44naa"
	            	
	            	Diff:
	            	--- Expected
	            	+++ Actual
...
View all

ℹ️ Info

🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 44f2192 | Docs | Was this helpful? Give us feedback!

@ctrombley ctrombley force-pushed the jspiker/user-token-enablement branch from 09dc30b to e7cf4aa Compare November 27, 2025 00:12
RemainingTestableCount int `jsonapi:"attr,remaining-testable-count"`
SpeculativePlanManagementEnabled bool `jsonapi:"attr,speculative-plan-management-enabled"`
EnforceHYOK bool `jsonapi:"attr,enforce-hyok"`
UserTokensEnabled *bool `jsonapi:"attr,user-tokens-enabled"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we use a bool pointer type? false and nil are both logically equivalent, correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question: it is because this setting defaults to true. Making this a bool pointer allows us to distinguish between "this is unspecified on the organization" (ie, because it is an older version of TFE) and "this is explicitly false" (ie, because this is an up-to-date TFE and the user has disabled the setting)

That is important because in the provider when we read an organization from an old TFE version, we dont want the the value to appear as false. That could lead to the provider always showing drift for the org and/or be misleading since the behaviour of the old org is that user tokens are enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A similar example would be like OrganizationScoped for agent pools

org, err := ownerClient.Organizations.Update(ctx, orgTest.Name, options)
require.NoError(t, err)
assert.False(t, *org.UserTokensEnabled, "user tokens disabled")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider including assertions that validate the change had the intended effect, i.e. try and look up some resources and expect an error here. (& the inverse when the setting is off)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for the suggestion, I have added some more assertions!

Copy link
Copy Markdown
Collaborator

@ctrombley ctrombley left a comment

Choose a reason for hiding this comment

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

Thanks @JarrettSpiker !

@emlanctot emlanctot merged commit a4aeb60 into main Dec 12, 2025
55 of 64 checks passed
@emlanctot emlanctot deleted the jspiker/user-token-enablement branch December 12, 2025 18:24
@github-actions
Copy link
Copy Markdown

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants