Skip to content

[IPL-7725] Updating Calls to the Remote HCP Terraform API to Retrieve All Workspace Variables #37241

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

debrin-hc
Copy link

@debrin-hc debrin-hc commented Jun 16, 2025

Description

Original Problem

While doing a terraform import, it was observed that variables inherited from variable sets in HCP Terraform were not
getting resolved, which caused the No value for required variable error. Usually, in such cases, terraform would make
an API call to HCP Terraform (via go-tfe client) to retrieve the list of variables accessible to the workspace. However,
the HCP Terraform API failed to include inherited variables that were not overwritten by workspace variables, which led
to the error.

Proposed Solution

We updated the HCP Terraform API to include the following variables for a workspace:

  • variables declared in the workspace and not overwritten by organization / project variable set
  • variables inherited from organization / project variable sets and not overwritten by workspace variables

The updated API was included in the latest version (v1.83.0) of the go-tfe client, and this PR updates the go-tfe client
version and updates the API calls in the terraform import command to use the new API.

Note - the terraform import block does not face this issue since it is executed during a plan / apply run, and
importing variables from variable sets works as expected.

Testing

  1. Verified that the issue is fixed by running terraform import on a workspace with inherited variables from variable
    sets. Evidence attached below.

Documentation and External References

  1. Fixes JIRA: IPL-7725
  2. ADR Documentation: TF-033
  3. go-tfe PR: #1105

Target Release

1.13.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

NO

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

Testing Evidence

evidence__ipl_7725__hcp_workspace_variables evidence__ipl_7725__terraform_config evidence__ipl_7725__terraform_import_result

@debrin-hc debrin-hc requested review from a team as code owners June 16, 2025 11:08
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: Retrieve all workspace variables while doing a `terraform import`, include variables inhertied from variable sets but not overwritten by the worskapce.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
body: Retrieve all workspace variables while doing a `terraform import`, include variables inhertied from variable sets but not overwritten by the worskapce.
body: Retrieve all workspace variables while doing a `terraform import`, include variables inherited from variable sets but not overwritten by the workspace.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@radeksimko radeksimko requested a review from a team June 16, 2025 14:28
go get github.com/hashicorp/jsonapi@v1.5.0
… all variables

 accessible to a workspace. This should include:
 - variables declared in the workspace and not overwritten by organization / project varset variables
 - variables inherited from organization / project varsets and not overwritten by workspace variables

Other changes: Adding mocks for new functions in go-tfe after version upgrade
@debrin-hc debrin-hc requested review from a team as code owners June 18, 2025 05:21
@debrin-hc debrin-hc requested a review from radeksimko June 18, 2025 10:06
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