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

Workspace id migration #106

Merged
merged 29 commits into from
Mar 25, 2020
Merged

Workspace id migration #106

merged 29 commits into from
Mar 25, 2020

Conversation

beekus
Copy link
Member

@beekus beekus commented Nov 20, 2019

This PR migrates the schema of workspaces to use the workspace's immutable external_id as the id, instead of the mutable organization/workspace identifier.

The variables and team_access resources also have a workspace_id field, which is migrated to the new workspace.id as well. Additionally, the team_access and workspace data source have been updated accordingly, though those don't require a state migration.

Background comment from @apparentlymart

That sort of transition between id types is tricky, particularly in attributes marked as ForceNew where changes can be very disruptive, but I think it should be possible here in principle because our id strings follow a particular syntax that should not (I think?) be ambiguous with an "organization/workspace" string.

The high-level idea here is to implement a StateUpgradeFunc on the affected resource types which inspects the strings already in the state to see if they seem to be in the "organization/workspace" form, and if so make an API call to find the corresponding id and write that out in its place. The upgrade function will then establish a new schema version number (recorded in the state) so the SDK can see that the upgrade has completed and not keep trying to repeat it on future operations.

The key to avoid issues for users would be to ensure that we apply this upgrade to all of the affected attributes at the same time -- at minimum, we must update both the id of the workspace object itself and the reference to it in the variables at the same time, so that they will keep matching. At the same time I think we'd want to add a validation rule in all of the places where workspace ids are expected to produce a helpful error message if we detect the user is trying to hard-code the "organization/workspace" syntax, to guide them towards referencing the workspace unique id instead.

There may still be churn for users if these id attributes are referenced anywhere else in configuration (outside of the TFE provider), so I think we'd still want to make it a major release and document it as a breaking change to be sure, though I expect most users will not be passing TFE workspace ids on to other providers and so the upgrade codepath will do all the work for them. For anyone that does need it, we can expose the "organization/name" string as a separate attribute (if we aren't already) and show in the upgrade instructions how to replace existing references to use that new attribute instead.

This is not a trivial amount of work though, especially if we allow for the requisite thorough downgrade/upgrade testing, so I think the "time" constraint still applies.

Todo:

  • Fix the variable and team_access (and maybe workspace) importers
  • Figure out how to unit test the variable and team access migrations, since they have to reach out to the API.
  • Adjust the state upgraders to not upgrade if the workspace_id is already the external_id. Also not going to do this as it seems extremely corner casey.
  • Add a validation rule in all of the places where workspace ids are expected to produce a helpful error message if we detect the user is trying to hard-code the "organization/workspace" syntax
  • Some additional tests probably need to be updated, as well as the acceptance tests.
  • Update the docs
  • Update the CHANGELOG.

Notes

  • Requires at least TFE v201904-1

@ghost ghost added the size/XL label Nov 20, 2019
@ghost ghost added the documentation label Nov 21, 2019
@beekus beekus marked this pull request as ready for review November 21, 2019 19:13
Copy link
Contributor

@lafentres lafentres left a comment

Choose a reason for hiding this comment

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

I'm not sure if it makes sense to do this now or to plan to do it later but this does introduce some inconsistencies with workspace_id vs workspace_external_id.
Policy sets and notification configurations both use workspace_external_id. It would be nice if everything could use workspace_external_id or if policy sets and notification configurations could be switched to just use workspace_id.
I think I lean more toward workspace_id for everything since go-tfe and the API both seem to use workspace id to refer to the external id. Is this something that would be reasonable to change with this release (if we are already introducing breaking changes)? Or something you'd prefer to wait to do?
I don't think we can remove workspace.external_id until we sort this out.

@svanharmelen
Copy link
Contributor

How do we release this as a breaking change? What about TF Enterprise installs that may not have updated API which is required for the workspace actions by ID?

I think this is a perfect use case for the service discovery logic I've build into the remote backend, this provider and TFC/TFE. Currently this provider supports the TFE services v2 and v2.1 (https://github.com/terraform-providers/terraform-provider-tfe/blob/master/tfe/provider.go#L27). So if you would update the service version in TFC/TFE (and of course configure the needed things in CheckPoint) you should be able to use the supported version to decide if you want to migrate the state or not.

I believe that you can support multiple versions in TFC/TFE concurrently and the remote backend and this provider will try to use the latest commonly supported version. But not sure anymore how this looks in Altas 😉

Either way I would strongly suggest to use the service version logic as it's specifically added for things like this. Hope this helps!

@svanharmelen
Copy link
Contributor

I think I lean more toward workspace_id for everything since go-tfe and the API both seem to use workspace id to refer to the external id.

Fully agree on that @lafentres! The only reason workspace_external_id exists, is because the API previously didn't support using the "external" ID as the resource ID in all cases. Now that has been updated/fixed it would be very nice to just call it workspace_id consistently (as is done with all other resources).

@beekus
Copy link
Member Author

beekus commented Nov 25, 2019

Thanks y'all. Yeah, I agree that we should update everything to use workspace.id and possibly get rid of the workspace_ids data source as part of this release, but not necessarily part of this PR.

Will give updating the testing a bit a try based on y'all's comments, and see if I can figure out how to get the service discovery endpoint used.

@ghost ghost added size/XXL and removed size/XL labels Nov 26, 2019
Copy link
Contributor

@lafentres lafentres left a comment

Choose a reason for hiding this comment

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

The updates look good to me! I tested the state migration with a simple config and it everything looks like it worked.

Copy link
Contributor

@svanharmelen svanharmelen left a comment

Choose a reason for hiding this comment

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

Didn't test things myself, but had a quick look through the PR...

tfe/data_source_workspace_ids_test.go Outdated Show resolved Hide resolved
website/docs/r/workspace.html.markdown Outdated Show resolved Hide resolved
website/docs/r/workspace.html.markdown Outdated Show resolved Hide resolved
* `id` - The workspace's human-readable ID, which looks like
`<ORGANIZATION>/<WORKSPACE>`.
* `id` - The workspace's opaque external ID, which looks like
`ws-<RANDOM STRING>`.
* `external_id` - The workspace's opaque external ID, which looks like
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should now remove this field right?

website/docs/r/variable.html.markdown Outdated Show resolved Hide resolved
website/docs/d/workspace.html.markdown Outdated Show resolved Hide resolved
website/docs/d/workspace.html.markdown Outdated Show resolved Hide resolved
* `id` - The workspace's human-readable ID, which looks like
`<ORGANIZATION>/<WORKSPACE>`.
* `id` - The workspace's opaque external ID, which looks like
`ws-<RANDOM STRING>`.
* `external_id` - The workspace's opaque external ID, which looks like
Copy link
Contributor

Choose a reason for hiding this comment

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

This one should be removed right? No point in exporting the same ID twice with a different name.

tfe/resource_tfe_workspace.go Outdated Show resolved Hide resolved

log.Printf("[DEBUG] Read configuration of workspace: %s", name)
workspace, err := tfeClient.Workspaces.Read(ctx, organization, name)
id := d.Id()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is perfectly valid, but it's also very common and fine to just call d.Id() everywhere the ID is needed.

@beekus
Copy link
Member Author

beekus commented Dec 9, 2019

Thanks for the feedback y'all.

TLDR; I'm not planning on merging this until late January.

We had to update the version of the API in the Atlas discovery doc and make that the only allowed version for this version of the provider. That will likely not make it into PTFE until late January. Therefore, we should hold off on merging this until it is supported by PTFE.

@beekus beekus mentioned this pull request Jan 13, 2020
2 tasks
@beekus
Copy link
Member Author

beekus commented Feb 10, 2020

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v  -timeout 15m
?   	github.com/terraform-providers/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFESSHKeyDataSource_basic
--- PASS: TestAccTFESSHKeyDataSource_basic (9.94s)
=== RUN   TestAccTFETeamAccessDataSource_basic
--- PASS: TestAccTFETeamAccessDataSource_basic (15.10s)
=== RUN   TestAccTFETeamDataSource_basic
--- PASS: TestAccTFETeamDataSource_basic (9.29s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_basic
--- PASS: TestAccTFEWorkspaceIDsDataSource_basic (13.15s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_wildcard
--- PASS: TestAccTFEWorkspaceIDsDataSource_wildcard (14.43s)
=== RUN   TestAccTFEWorkspaceDataSource_basic
--- PASS: TestAccTFEWorkspaceDataSource_basic (12.15s)
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestProvider_versionConstraints
--- PASS: TestProvider_versionConstraints (0.00s)
=== RUN   TestAccTFENotificationConfiguration_basic
--- PASS: TestAccTFENotificationConfiguration_basic (9.28s)
=== RUN   TestAccTFENotificationConfiguration_update
--- PASS: TestAccTFENotificationConfiguration_update (15.62s)
=== RUN   TestAccTFENotificationConfiguration_slackWithToken
--- PASS: TestAccTFENotificationConfiguration_slackWithToken (5.21s)
=== RUN   TestAccTFENotificationConfiguration_duplicateTriggers
--- PASS: TestAccTFENotificationConfiguration_duplicateTriggers (8.89s)
=== RUN   TestAccTFENotificationConfigurationImport
--- PASS: TestAccTFENotificationConfigurationImport (10.26s)
=== RUN   TestAccTFEOAuthClient_basic
--- SKIP: TestAccTFEOAuthClient_basic (0.45s)
    resource_tfe_oauth_client_test.go:19: Please set GITHUB_TOKEN to run this test
=== RUN   TestAccTFEOrganization_basic
--- PASS: TestAccTFEOrganization_basic (5.68s)
=== RUN   TestAccTFEOrganization_update
--- PASS: TestAccTFEOrganization_update (9.33s)
=== RUN   TestAccTFEOrganization_import
--- PASS: TestAccTFEOrganization_import (6.30s)
=== RUN   TestAccTFEOrganizationToken_basic
--- PASS: TestAccTFEOrganizationToken_basic (8.96s)
=== RUN   TestAccTFEOrganizationToken_existsWithoutForce
--- PASS: TestAccTFEOrganizationToken_existsWithoutForce (10.56s)
=== RUN   TestAccTFEOrganizationToken_existsWithForce
--- PASS: TestAccTFEOrganizationToken_existsWithForce (14.87s)
=== RUN   TestAccTFEOrganizationToken_import
--- PASS: TestAccTFEOrganizationToken_import (9.48s)
=== RUN   TestAccTFEPolicySet_basic
--- PASS: TestAccTFEPolicySet_basic (13.51s)
=== RUN   TestAccTFEPolicySet_update
--- PASS: TestAccTFEPolicySet_update (23.10s)
=== RUN   TestAccTFEPolicySet_updateEmpty
--- PASS: TestAccTFEPolicySet_updateEmpty (18.05s)
=== RUN   TestAccTFEPolicySet_updatePopulated
--- PASS: TestAccTFEPolicySet_updatePopulated (27.93s)
=== RUN   TestAccTFEPolicySet_updateToGlobal
--- FAIL: TestAccTFEPolicySet_updateToGlobal (19.89s)
    testing.go:568: Step 1 error: Check failed: Check 2/5 error: Wrong number of workspaces: 0
=== RUN   TestAccTFEPolicySet_updateToWorkspace
--- FAIL: TestAccTFEPolicySet_updateToWorkspace (10.70s)
    testing.go:568: Step 0 error: Check failed: Check 2/5 error: Wrong number of workspaces: 0
=== RUN   TestAccTFEPolicySet_vcs
--- SKIP: TestAccTFEPolicySet_vcs (0.39s)
    resource_tfe_policy_set_test.go:255: Please set GITHUB_TOKEN to run this test
=== RUN   TestAccTFEPolicySetImport
--- PASS: TestAccTFEPolicySetImport (14.31s)
=== RUN   TestAccTFESentinelPolicy_basic
--- PASS: TestAccTFESentinelPolicy_basic (10.77s)
=== RUN   TestAccTFESentinelPolicy_update
--- PASS: TestAccTFESentinelPolicy_update (24.07s)
=== RUN   TestAccTFESentinelPolicy_import
--- PASS: TestAccTFESentinelPolicy_import (19.06s)
=== RUN   TestAccTFESSHKey_basic
--- PASS: TestAccTFESSHKey_basic (9.02s)
=== RUN   TestAccTFESSHKey_update
--- PASS: TestAccTFESSHKey_update (12.54s)
=== RUN   TestResourceTfeTeamAccessStateUpgradeV0
--- PASS: TestResourceTfeTeamAccessStateUpgradeV0 (0.18s)
=== RUN   TestAccTFETeamAccess_basic
--- PASS: TestAccTFETeamAccess_basic (12.18s)
=== RUN   TestAccTFETeamAccess_import
--- PASS: TestAccTFETeamAccess_import (12.68s)
=== RUN   TestPackTeamMemberID
--- PASS: TestPackTeamMemberID (0.00s)
=== RUN   TestUnpackTeamMemberID
--- PASS: TestUnpackTeamMemberID (0.00s)
=== RUN   TestAccTFETeamMember_basic
--- FAIL: TestAccTFETeamMember_basic (5.47s)
    testing.go:568: Step 0 error: errors during apply:

        Error: Error adding user "admin" to team team-NEhhs3ZHueXwRask: bad request

        admin is not a member of the organization

          on /var/folders/8v/6rlnz0t15tl16zy2yqzgvdqh0000gn/T/tf-test436626285/main.tf line 12:
          (source code not available)


=== RUN   TestAccTFETeamMember_import
--- FAIL: TestAccTFETeamMember_import (5.36s)
    testing.go:568: Step 0 error: errors during apply:

        Error: Error adding user "admin" to team team-Hd3w9hP47Cpta7PV: bad request

        admin is not a member of the organization

          on /var/folders/8v/6rlnz0t15tl16zy2yqzgvdqh0000gn/T/tf-test379627559/main.tf line 12:
          (source code not available)


=== RUN   TestAccTFETeamMembers_basic
--- SKIP: TestAccTFETeamMembers_basic (0.50s)
    resource_tfe_team_members_test.go:22: Please set TFE_USER1 to run this test
=== RUN   TestAccTFETeamMembers_update
--- SKIP: TestAccTFETeamMembers_update (0.46s)
    resource_tfe_team_members_test.go:55: Please set TFE_USER1 to run this test
=== RUN   TestAccTFETeamMembers_import
--- SKIP: TestAccTFETeamMembers_import (0.42s)
    resource_tfe_team_members_test.go:102: Please set TFE_USER1 to run this test
=== RUN   TestAccTFETeam_basic
--- PASS: TestAccTFETeam_basic (7.98s)
=== RUN   TestAccTFETeam_import
--- PASS: TestAccTFETeam_import (8.27s)
=== RUN   TestAccTFETeamToken_basic
--- PASS: TestAccTFETeamToken_basic (10.31s)
=== RUN   TestAccTFETeamToken_existsWithoutForce
--- PASS: TestAccTFETeamToken_existsWithoutForce (13.56s)
=== RUN   TestAccTFETeamToken_existsWithForce
--- PASS: TestAccTFETeamToken_existsWithForce (18.12s)
=== RUN   TestAccTFETeamToken_import
--- PASS: TestAccTFETeamToken_import (11.18s)
=== RUN   TestResourceTfeVariableStateUpgradeV0
--- PASS: TestResourceTfeVariableStateUpgradeV0 (0.16s)
=== RUN   TestAccTFEVariable_basic
--- PASS: TestAccTFEVariable_basic (12.59s)
=== RUN   TestAccTFEVariable_update
--- PASS: TestAccTFEVariable_update (17.66s)
=== RUN   TestAccTFEVariable_import
--- PASS: TestAccTFEVariable_import (11.11s)
=== RUN   TestResourceTfeWorkspaceStateUpgradeV0
--- PASS: TestResourceTfeWorkspaceStateUpgradeV0 (0.00s)
=== RUN   TestAccTFEWorkspace_basic
--- PASS: TestAccTFEWorkspace_basic (8.15s)
=== RUN   TestAccTFEWorkspace_monorepo
--- PASS: TestAccTFEWorkspace_monorepo (8.49s)
=== RUN   TestAccTFEWorkspace_renamed
--- PASS: TestAccTFEWorkspace_renamed (11.34s)
=== RUN   TestAccTFEWorkspace_update
--- FAIL: TestAccTFEWorkspace_update (11.01s)
    testing.go:568: Step 1 error: Check failed: Check 2/12 error: Bad operations: true
=== RUN   TestAccTFEWorkspace_updateFileTriggers
--- PASS: TestAccTFEWorkspace_updateFileTriggers (14.72s)
=== RUN   TestAccTFEWorkspace_sshKey
--- PASS: TestAccTFEWorkspace_sshKey (22.84s)
=== RUN   TestAccTFEWorkspace_import
--- PASS: TestAccTFEWorkspace_import (9.56s)
=== RUN   TestFetchWorkspaceExternalID
=== RUN   TestFetchWorkspaceExternalID/non_exisiting_organization
=== RUN   TestFetchWorkspaceExternalID/non_exisiting_workspace
=== RUN   TestFetchWorkspaceExternalID/found_workspace
--- PASS: TestFetchWorkspaceExternalID (1.41s)
    --- PASS: TestFetchWorkspaceExternalID/non_exisiting_organization (0.00s)
    --- PASS: TestFetchWorkspaceExternalID/non_exisiting_workspace (0.00s)
    --- PASS: TestFetchWorkspaceExternalID/found_workspace (0.00s)
=== RUN   TestFetchWorkspaceHumanID
=== RUN   TestFetchWorkspaceHumanID/non_exisiting_workspace
=== RUN   TestFetchWorkspaceHumanID/found_workspace
--- PASS: TestFetchWorkspaceHumanID (0.00s)
    --- PASS: TestFetchWorkspaceHumanID/non_exisiting_workspace (0.00s)
    --- PASS: TestFetchWorkspaceHumanID/found_workspace (0.00s)
=== RUN   TestPackWorkspaceID
--- PASS: TestPackWorkspaceID (0.00s)
=== RUN   TestUnpackWorkspaceID
--- PASS: TestUnpackWorkspaceID (0.00s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-tfe/tfe	628.556s
?   	github.com/terraform-providers/terraform-provider-tfe/version	[no test files]
make: *** [testacc] Error 1

@sean-nixon
Copy link

We are very much interested in this and looking forward to it being released. Is this still planned to be merged sometime soon?

@beekus
Copy link
Member Author

beekus commented Mar 25, 2020

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v  -timeout 15m
?   	github.com/terraform-providers/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFESSHKeyDataSource_basic
--- PASS: TestAccTFESSHKeyDataSource_basic (12.42s)
=== RUN   TestAccTFETeamAccessDataSource_basic
--- PASS: TestAccTFETeamAccessDataSource_basic (19.80s)
=== RUN   TestAccTFETeamDataSource_basic
--- PASS: TestAccTFETeamDataSource_basic (11.46s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_basic
--- PASS: TestAccTFEWorkspaceIDsDataSource_basic (15.34s)
=== RUN   TestAccTFEWorkspaceIDsDataSource_wildcard
--- PASS: TestAccTFEWorkspaceIDsDataSource_wildcard (15.41s)
=== RUN   TestAccTFEWorkspaceDataSource_basic
--- PASS: TestAccTFEWorkspaceDataSource_basic (11.10s)
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN   TestProvider_versionConstraints
--- PASS: TestProvider_versionConstraints (0.00s)
=== RUN   TestAccTFENotificationConfiguration_basic
--- PASS: TestAccTFENotificationConfiguration_basic (12.69s)
=== RUN   TestAccTFENotificationConfiguration_update
--- PASS: TestAccTFENotificationConfiguration_update (19.46s)
=== RUN   TestAccTFENotificationConfiguration_slackWithToken
--- PASS: TestAccTFENotificationConfiguration_slackWithToken (7.44s)
=== RUN   TestAccTFENotificationConfiguration_duplicateTriggers
--- PASS: TestAccTFENotificationConfiguration_duplicateTriggers (15.45s)
=== RUN   TestAccTFENotificationConfigurationImport
--- PASS: TestAccTFENotificationConfigurationImport (11.68s)
=== RUN   TestAccTFEOAuthClient_basic
--- SKIP: TestAccTFEOAuthClient_basic (0.60s)
    resource_tfe_oauth_client_test.go:19: Please set GITHUB_TOKEN to run this test
=== RUN   TestAccTFEOrganization_basic
--- PASS: TestAccTFEOrganization_basic (7.18s)
=== RUN   TestAccTFEOrganization_update
--- PASS: TestAccTFEOrganization_update (13.16s)
=== RUN   TestAccTFEOrganization_import
--- PASS: TestAccTFEOrganization_import (8.58s)
=== RUN   TestAccTFEOrganizationToken_basic
--- PASS: TestAccTFEOrganizationToken_basic (10.25s)
=== RUN   TestAccTFEOrganizationToken_existsWithoutForce
--- PASS: TestAccTFEOrganizationToken_existsWithoutForce (12.71s)
=== RUN   TestAccTFEOrganizationToken_existsWithForce
--- PASS: TestAccTFEOrganizationToken_existsWithForce (17.09s)
=== RUN   TestAccTFEOrganizationToken_import
--- PASS: TestAccTFEOrganizationToken_import (11.86s)
=== RUN   TestAccTFEPolicySetParameter_basic
--- PASS: TestAccTFEPolicySetParameter_basic (14.44s)
=== RUN   TestAccTFEPolicySetParameter_update
--- PASS: TestAccTFEPolicySetParameter_update (22.87s)
=== RUN   TestAccTFEPolicySetParameter_import
--- PASS: TestAccTFEPolicySetParameter_import (14.03s)
=== RUN   TestAccTFEPolicySet_basic
--- PASS: TestAccTFEPolicySet_basic (17.34s)
=== RUN   TestAccTFEPolicySet_update
--- PASS: TestAccTFEPolicySet_update (26.15s)
=== RUN   TestAccTFEPolicySet_updateEmpty
--- PASS: TestAccTFEPolicySet_updateEmpty (20.32s)
=== RUN   TestAccTFEPolicySet_updatePopulated
--- PASS: TestAccTFEPolicySet_updatePopulated (31.69s)
=== RUN   TestAccTFEPolicySet_updateToGlobal
--- PASS: TestAccTFEPolicySet_updateToGlobal (26.98s)
=== RUN   TestAccTFEPolicySet_updateToWorkspace
--- PASS: TestAccTFEPolicySet_updateToWorkspace (26.71s)
=== RUN   TestAccTFEPolicySet_vcs
--- SKIP: TestAccTFEPolicySet_vcs (0.59s)
    resource_tfe_policy_set_test.go:255: Please set GITHUB_TOKEN to run this test
=== RUN   TestAccTFEPolicySetImport
--- PASS: TestAccTFEPolicySetImport (18.73s)
=== RUN   TestAccTFERunTrigger_basic
--- PASS: TestAccTFERunTrigger_basic (12.99s)
=== RUN   TestAccTFERunTriggerImport
--- PASS: TestAccTFERunTriggerImport (13.66s)
=== RUN   TestAccTFESentinelPolicy_basic
--- PASS: TestAccTFESentinelPolicy_basic (13.13s)
=== RUN   TestAccTFESentinelPolicy_update
--- PASS: TestAccTFESentinelPolicy_update (22.88s)
=== RUN   TestAccTFESentinelPolicy_import
--- PASS: TestAccTFESentinelPolicy_import (13.96s)
=== RUN   TestAccTFESSHKey_basic
--- PASS: TestAccTFESSHKey_basic (9.52s)
=== RUN   TestAccTFESSHKey_update
--- PASS: TestAccTFESSHKey_update (15.82s)
=== RUN   TestResourceTfeTeamAccessStateUpgradeV0
--- PASS: TestResourceTfeTeamAccessStateUpgradeV0 (0.35s)
=== RUN   TestAccTFETeamAccess_basic
--- PASS: TestAccTFETeamAccess_basic (12.90s)
=== RUN   TestAccTFETeamAccess_import
--- PASS: TestAccTFETeamAccess_import (13.98s)
=== RUN   TestPackTeamMemberID
--- PASS: TestPackTeamMemberID (0.00s)
=== RUN   TestUnpackTeamMemberID
--- PASS: TestUnpackTeamMemberID (0.00s)
=== RUN   TestAccTFETeamMember_basic
--- FAIL: TestAccTFETeamMember_basic (6.04s)
    testing.go:569: Step 0 error: errors during apply:
        
        Error: Error adding user "admin" to team team-3nx16FocLysXvD7t: bad request
        
        admin is not a member of the organization
        
          on /var/folders/yt/66g8c6q95yd580n_6rsg38l80000gp/T/tf-test383473848/main.tf line 12:
          (source code not available)
        
        
=== RUN   TestAccTFETeamMember_import
--- FAIL: TestAccTFETeamMember_import (7.56s)
    testing.go:569: Step 0 error: errors during apply:
        
        Error: Error adding user "admin" to team team-T1Z2mapcRQ6Nz739: bad request
        
        admin is not a member of the organization
        
          on /var/folders/yt/66g8c6q95yd580n_6rsg38l80000gp/T/tf-test677401770/main.tf line 12:
          (source code not available)
        
        
=== RUN   TestAccTFETeamMembers_basic
--- SKIP: TestAccTFETeamMembers_basic (0.52s)
    resource_tfe_team_members_test.go:22: Please set TFE_USER1 to run this test
=== RUN   TestAccTFETeamMembers_update
--- SKIP: TestAccTFETeamMembers_update (0.49s)
    resource_tfe_team_members_test.go:55: Please set TFE_USER1 to run this test
=== RUN   TestAccTFETeamMembers_import
--- SKIP: TestAccTFETeamMembers_import (0.51s)
    resource_tfe_team_members_test.go:102: Please set TFE_USER1 to run this test
=== RUN   TestAccTFETeam_basic
--- PASS: TestAccTFETeam_basic (10.75s)
=== RUN   TestAccTFETeam_import
--- PASS: TestAccTFETeam_import (10.77s)
=== RUN   TestAccTFETeamToken_basic
--- PASS: TestAccTFETeamToken_basic (12.02s)
=== RUN   TestAccTFETeamToken_existsWithoutForce
--- PASS: TestAccTFETeamToken_existsWithoutForce (15.45s)
=== RUN   TestAccTFETeamToken_existsWithForce
--- PASS: TestAccTFETeamToken_existsWithForce (20.85s)
=== RUN   TestAccTFETeamToken_import
--- PASS: TestAccTFETeamToken_import (13.08s)
=== RUN   TestResourceTfeVariableStateUpgradeV0
--- PASS: TestResourceTfeVariableStateUpgradeV0 (0.22s)
=== RUN   TestAccTFEVariable_basic
--- PASS: TestAccTFEVariable_basic (15.12s)
=== RUN   TestAccTFEVariable_update
--- PASS: TestAccTFEVariable_update (24.08s)
=== RUN   TestAccTFEVariable_import
--- PASS: TestAccTFEVariable_import (15.05s)
=== RUN   TestResourceTfeWorkspaceStateUpgradeV0
--- PASS: TestResourceTfeWorkspaceStateUpgradeV0 (0.00s)
=== RUN   TestAccTFEWorkspace_basic
--- PASS: TestAccTFEWorkspace_basic (11.64s)
=== RUN   TestAccTFEWorkspace_monorepo
--- PASS: TestAccTFEWorkspace_monorepo (9.89s)
=== RUN   TestAccTFEWorkspace_renamed
--- PASS: TestAccTFEWorkspace_renamed (14.62s)
=== RUN   TestAccTFEWorkspace_update
--- PASS: TestAccTFEWorkspace_update (15.77s)
=== RUN   TestAccTFEWorkspace_updateWorkingDirectory
--- PASS: TestAccTFEWorkspace_updateWorkingDirectory (22.39s)
=== RUN   TestAccTFEWorkspace_updateFileTriggers
--- PASS: TestAccTFEWorkspace_updateFileTriggers (14.99s)
=== RUN   TestAccTFEWorkspace_updateTriggerPrefixes
--- PASS: TestAccTFEWorkspace_updateTriggerPrefixes (15.94s)
=== RUN   TestAccTFEWorkspace_sshKey
--- PASS: TestAccTFEWorkspace_sshKey (24.28s)
=== RUN   TestAccTFEWorkspace_import
--- PASS: TestAccTFEWorkspace_import (10.55s)
=== RUN   TestFetchWorkspaceExternalID
=== RUN   TestFetchWorkspaceExternalID/non_exisiting_organization
=== RUN   TestFetchWorkspaceExternalID/non_exisiting_workspace
=== RUN   TestFetchWorkspaceExternalID/found_workspace
--- PASS: TestFetchWorkspaceExternalID (0.39s)
    --- PASS: TestFetchWorkspaceExternalID/non_exisiting_organization (0.00s)
    --- PASS: TestFetchWorkspaceExternalID/non_exisiting_workspace (0.00s)
    --- PASS: TestFetchWorkspaceExternalID/found_workspace (0.00s)
=== RUN   TestFetchWorkspaceHumanID
=== RUN   TestFetchWorkspaceHumanID/non_exisiting_workspace
=== RUN   TestFetchWorkspaceHumanID/found_workspace
--- PASS: TestFetchWorkspaceHumanID (0.00s)
    --- PASS: TestFetchWorkspaceHumanID/non_exisiting_workspace (0.00s)
    --- PASS: TestFetchWorkspaceHumanID/found_workspace (0.00s)
=== RUN   TestPackWorkspaceID
--- PASS: TestPackWorkspaceID (0.00s)
=== RUN   TestUnpackWorkspaceID
--- PASS: TestUnpackWorkspaceID (0.00s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-tfe/tfe	876.262s
?   	github.com/terraform-providers/terraform-provider-tfe/version	[no test files]

@beekus beekus merged commit 773842d into master Mar 25, 2020
@beekus beekus deleted the f-workspace-id-migration branch March 25, 2020 19:02
@glentakahashi
Copy link

Even porting to the new workspace_id format, I still receive this error on new variables
invalid value for workspace_id (must be the workspace's external_id)

@bjmask
Copy link

bjmask commented Mar 26, 2020

This just broke all of our bindings

@beekus
Copy link
Member Author

beekus commented Mar 27, 2020

Howdy folks. First, I'm sorry for pushing out this change without better communication. We are working to improve our process on this provider so we can avoid such situations in the future.

The underlying reason for this change was that the workspace's ID in the <organization>/<workspace> format is mutable. When, say, the workspace name is changed, variable and team access updates within the same apply do not work correctly, and things break. We cannot support both ways for this reason.

You can fetch the workspace's external id and use it in the variable resource by using the tfe_workspace data source:

data "tfe_workspace" "ws" {
  name = "my-workspace"
  organization = "my-org"
}

resource "tfe_variable" "var" {
  key = "a-key"
  value = "a-val"
  category = "terraform"
  workspace_id = data.tfe_workspace.ws.id
}

When this provider was originally created, the API did not support the using the workspace's external_id to update these resources, and it does now. This provider is still pre-1.0, but we still strive to not make any disruptive changes between releases - this one just needed to be done, and hopefully the validation describing that you now need to use the workspace ID makes the path forward clear.

Sorry for the disruption, and thanks!

@glentakahashi
Copy link

Also as a reminder, you can always pin your provider versions. e.g.

provider "tfe" {
  version = "= 0.14.1"
  token   = var.terraform_token
}

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

Successfully merging this pull request may close these issues.

8 participants