Skip to content

Upgrade go-tfe from 1.51.0 to 1.58.0#35495

Merged
liamcervante merged 2 commits intohashicorp:mainfrom
jbonhag:jbonhag/go-tfe-upgrade
Aug 8, 2024
Merged

Upgrade go-tfe from 1.51.0 to 1.58.0#35495
liamcervante merged 2 commits intohashicorp:mainfrom
jbonhag:jbonhag/go-tfe-upgrade

Conversation

@jbonhag
Copy link
Copy Markdown
Contributor

@jbonhag jbonhag commented Jul 23, 2024

This PR bumps the go-tfe dependency in Terraform to v1.58.0, which allows the Terraform cloud block to interact with workspaces that have HCP IDs.

This requires changing the mock dependency from golang/mock to go.uber.org/mock to maintain compatibility with go-tfe v1.53.0: hashicorp/go-tfe#897

Why?

For Unified HCP Terraform, we create organizations, projects, and workspaces using HCP-generated external IDs (e.g. terraform.workspace:qjRw3Pbjttz9D73mR7Rz for a workspace) rather than a prefixed ID format (ws-DEB5Hz2oJM2fXnBs). This allows for greater interoperability between HCP and TFC, and also required relaxing client-side ID validation in the go-tfe library.

The go-tfe changes were made here: hashicorp/go-tfe#924 and included in the go-tfe 1.58.0 release.

Because the Terraform cloud block uses go-tfe 1.51.0, Terraform is currently unable to read the current state of those workspaces. In the following example, jbonhag-demo-1 is a unified organization, and default-project is a unified project synced from HCP.

main.tf:

terraform {
  cloud {
    organization = "jbonhag-demo-1"

    workspaces {
      project = "default-project"
      name    = "unified"
    }
  }
}

With Terraform 1.9.2:

❯ terraform init 
Initializing HCP Terraform...
╷
│ Error: Error refreshing state: error retrieving state: invalid value for workspace ID
│ 
│ 
╵

With proposed change:

❯ go build
❯ ./terraform init
Initializing HCP Terraform...
Initializing provider plugins...

HCP Terraform has been successfully initialized!

You may now begin working with HCP Terraform. Try running "terraform plan" to
see any changes that are required for your infrastructure.

If you ever set or change modules or Terraform Settings, run "terraform init"
again to reinitialize your working directory.

Here is where Terraform fetches the state:

sv, err := s.tfeClient.StateVersions.ReadCurrent(ctx, s.workspace.ID)

And here is where go-tfe performs the subsequent workspace ID validation:

https://github.com/hashicorp/go-tfe/blob/dee5a9cfda19483a7cdf7f6728b70d0e2340168b/state_version.go#L346-L348

Target Release

1.9.3

Draft CHANGELOG entry

ENHANCEMENTS

  • The cloud block can now interact with workspaces that have HCP resource IDs.
  • Mocks are now generated using the go.uber.org/mock package.

@jbonhag jbonhag force-pushed the jbonhag/go-tfe-upgrade branch 2 times, most recently from 9ea5f9a to a805e6d Compare July 23, 2024 20:45
@jbonhag jbonhag requested review from a team as code owners July 23, 2024 20:47
@jbonhag jbonhag self-assigned this Jul 23, 2024
@jbonhag jbonhag added the go-tfe label Jul 23, 2024
@jbonhag jbonhag changed the title Upgrade go-tfe to 1.58.0 Upgrade go-tfe from 1.51.0 to 1.58.0 Jul 23, 2024
@jbonhag jbonhag requested a review from a team July 23, 2024 21:10
@jbonhag
Copy link
Copy Markdown
Contributor Author

jbonhag commented Jul 23, 2024

go-tfe 1.53.0 includes a change to the mocking framework, so these unit test failures will need to be resolved before merging.

@jbonhag jbonhag force-pushed the jbonhag/go-tfe-upgrade branch from f5d16b4 to e8973c7 Compare July 23, 2024 21:39
@jbonhag jbonhag force-pushed the jbonhag/go-tfe-upgrade branch from 835464a to 16af0fa Compare July 24, 2024 14:09
Copy link
Copy Markdown
Member

@jbardin jbardin left a comment

Choose a reason for hiding this comment

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

This changes the mocks for packages unrelated to go-tfe too, but since github.com/golang/mock is now deprecated in favor of go.uber.org/mock I don't see any reason to not change them all at once anyway.

Copy link
Copy Markdown
Member

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

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

Approving on behalf of the gcs backend - the acceptance tests pass when I use this branch

Copy link
Copy Markdown
Member

@jar-b jar-b left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

% TF_ACC=1 go test -count=1 ./...
ok      github.com/hashicorp/terraform/internal/backend/remote-state/s3 207.382s

@liamcervante liamcervante added the 1.9-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Aug 7, 2024
Copy link
Copy Markdown
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@liamcervante liamcervante merged commit 8b29414 into hashicorp:main Aug 8, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 8, 2024

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

liamcervante pushed a commit that referenced this pull request Aug 8, 2024
* go get github.com/hashicorp/go-tfe@v1.58.0

* Switch to go.uber.org/mock for mocks
liamcervante pushed a commit that referenced this pull request Aug 9, 2024
* go get github.com/hashicorp/go-tfe@v1.58.0

* Switch to go.uber.org/mock for mocks

Co-authored-by: Jeff Bonhag <jbonhag@hashicorp.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 8, 2024

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 github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

1.9-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged go-tfe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants