Skip to content

Commit 6221c0b

Browse files
committed
[IPL-7725] Updating calls to the remote HCP Terraform API to retrieve 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
1 parent c44489d commit 6221c0b

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: Retrieve all workspace variables while doing a `terraform import`, include variables inherited from variable sets but not overwritten by the workspace.
3+
time: 2025-06-18T10:14:56.994302+05:30
4+
custom:
5+
Issue: "37241"

internal/backend/remote/backend_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (b *Remote) LocalRun(op *backendrun.Operation) (*backendrun.LocalRun, state
113113
log.Printf("[TRACE] skipping retrieving variables from workspace %s/%s (%s), workspace is in Local Execution mode", remoteWorkspaceName, b.organization, remoteWorkspaceID)
114114
} else {
115115
log.Printf("[TRACE] backend/remote: retrieving variables from workspace %s/%s (%s)", remoteWorkspaceName, b.organization, remoteWorkspaceID)
116-
tfeVariables, err := b.client.Variables.List(context.Background(), remoteWorkspaceID, nil)
116+
tfeVariables, err := b.client.Variables.ListAll(context.Background(), remoteWorkspaceID, nil)
117117
if err != nil && err != tfe.ErrResourceNotFound {
118118
diags = diags.Append(fmt.Errorf("error loading variables: %w", err))
119119
return nil, nil, diags

internal/cloud/backend_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (b *Cloud) LocalRun(op *backendrun.Operation) (*backendrun.LocalRun, statem
111111
log.Printf("[TRACE] skipping retrieving variables from workspace %s/%s (%s), workspace is in Local Execution mode", remoteWorkspaceName, b.Organization, remoteWorkspaceID)
112112
} else {
113113
log.Printf("[TRACE] cloud: retrieving variables from workspace %s/%s (%s)", remoteWorkspaceName, b.Organization, remoteWorkspaceID)
114-
tfeVariables, err := b.client.Variables.List(context.Background(), remoteWorkspaceID, nil)
114+
tfeVariables, err := b.client.Variables.ListAll(context.Background(), remoteWorkspaceID, nil)
115115
if err != nil && err != tfe.ErrResourceNotFound {
116116
diags = diags.Append(fmt.Errorf("error loading variables: %w", err))
117117
return nil, nil, diags

internal/cloud/tfe_client_mock.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,11 @@ func newMockRegistryModules(client *MockClient) *MockRegistryModules {
11121112
}
11131113
}
11141114

1115+
func (m *MockRegistryModules) ReadTerraformRegistryModule(ctx context.Context, moduleID tfe.RegistryModuleID, version string) (*tfe.TerraformRegistryModule, error) {
1116+
// TODO implement me
1117+
panic("implement me")
1118+
}
1119+
11151120
func (m *MockRegistryModules) List(ctx context.Context, organization string, options *tfe.RegistryModuleListOptions) (*tfe.RegistryModuleList, error) {
11161121
//TODO implement me
11171122
panic("implement me")
@@ -1235,6 +1240,11 @@ func newMockRuns(client *MockClient) *MockRuns {
12351240
}
12361241
}
12371242

1243+
func (m *MockRuns) ListForOrganization(ctx context.Context, organization string, options *tfe.RunListForOrganizationOptions) (*tfe.OrganizationRunList, error) {
1244+
// TODO implement me
1245+
panic("implement me")
1246+
}
1247+
12381248
func (m *MockRuns) List(ctx context.Context, workspaceID string, options *tfe.RunListOptions) (*tfe.RunList, error) {
12391249
m.Lock()
12401250
defer m.Unlock()
@@ -1887,6 +1897,10 @@ func (m *MockVariables) List(ctx context.Context, workspaceID string, options *t
18871897
return vl, nil
18881898
}
18891899

1900+
func (m *MockVariables) ListAll(ctx context.Context, workspaceID string, options *tfe.VariableListOptions) (*tfe.VariableList, error) {
1901+
return m.List(ctx, workspaceID, options)
1902+
}
1903+
18901904
func (m *MockVariables) Create(ctx context.Context, workspaceID string, options tfe.VariableCreateOptions) (*tfe.Variable, error) {
18911905
v := &tfe.Variable{
18921906
ID: GenerateID("var-"),

0 commit comments

Comments
 (0)