Skip to content

Commit 876de2d

Browse files
authored
Merge pull request #1043 from hashicorp/sebasslash/allow-effective-tag-binding-include
Add effective tag binding include relation to projects and workspaces
2 parents 31f7d18 + 7190298 commit 876de2d

File tree

5 files changed

+83
-13
lines changed

5 files changed

+83
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
## Enhancements
4+
5+
* Adds `EffectiveTagBindings` relation to projects and workspaces, allowing the relation to be included when listing projects or workspaces by @sebasslash [#1043](https://github.com/hashicorp/go-tfe/pull/1043)
6+
37
# v1.74.1
48

59
## Enhancements

project.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,16 @@ type Project struct {
7171
AutoDestroyActivityDuration jsonapi.NullableAttr[string] `jsonapi:"attr,auto-destroy-activity-duration,omitempty"`
7272

7373
// Relations
74-
Organization *Organization `jsonapi:"relation,organization"`
74+
Organization *Organization `jsonapi:"relation,organization"`
75+
EffectiveTagBindings []*EffectiveTagBinding `jsonapi:"relation,effective-tag-bindings"`
7576
}
7677

78+
type ProjectIncludeOpt string
79+
80+
const (
81+
ProjectEffectiveTagBindings ProjectIncludeOpt = "effective_tag_bindings"
82+
)
83+
7784
// ProjectListOptions represents the options for listing projects
7885
type ProjectListOptions struct {
7986
ListOptions
@@ -89,6 +96,9 @@ type ProjectListOptions struct {
8996
// Optional: A filter string to list projects filtered by key/value tags.
9097
// These are not annotated and therefore not encoded by go-querystring
9198
TagBindings []*TagBinding
99+
100+
// Optional: A list of relations to include
101+
Include []ProjectIncludeOpt `url:"include,omitempty"`
92102
}
93103

94104
// ProjectCreateOptions represents the options for creating a project

projects_integration_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,33 @@ func TestProjectsList(t *testing.T) {
113113
assert.Len(t, pl3.Items, 1)
114114
assert.Contains(t, pl3.Items, p2)
115115
})
116+
117+
t.Run("when including effective tags relationship", func(t *testing.T) {
118+
skipUnlessBeta(t)
119+
120+
orgTest2, orgTest2Cleanup := createOrganization(t, client)
121+
t.Cleanup(orgTest2Cleanup)
122+
123+
_, pTestCleanup1 := createProjectWithOptions(t, client, orgTest2, ProjectCreateOptions{
124+
Name: randomStringWithoutSpecialChar(t),
125+
TagBindings: []*TagBinding{
126+
{Key: "key1", Value: "value1"},
127+
{Key: "key2", Value: "value2a"},
128+
},
129+
})
130+
t.Cleanup(pTestCleanup1)
131+
132+
pl, err := client.Projects.List(ctx, orgTest2.Name, &ProjectListOptions{
133+
Include: []ProjectIncludeOpt{ProjectEffectiveTagBindings},
134+
})
135+
require.NoError(t, err)
136+
require.Len(t, pl.Items, 2)
137+
require.Len(t, pl.Items[0].EffectiveTagBindings, 2)
138+
assert.NotEmpty(t, pl.Items[0].EffectiveTagBindings[0].Key)
139+
assert.NotEmpty(t, pl.Items[0].EffectiveTagBindings[0].Value)
140+
assert.NotEmpty(t, pl.Items[0].EffectiveTagBindings[1].Key)
141+
assert.NotEmpty(t, pl.Items[0].EffectiveTagBindings[1].Value)
142+
})
116143
}
117144

118145
func TestProjectsRead(t *testing.T) {

workspace.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,19 @@ type Workspace struct {
217217
SettingOverwrites *WorkspaceSettingOverwrites `jsonapi:"attr,setting-overwrites"`
218218

219219
// Relations
220-
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
221-
CurrentRun *Run `jsonapi:"relation,current-run"`
222-
CurrentStateVersion *StateVersion `jsonapi:"relation,current-state-version"`
223-
Organization *Organization `jsonapi:"relation,organization"`
224-
SSHKey *SSHKey `jsonapi:"relation,ssh-key"`
225-
Outputs []*WorkspaceOutputs `jsonapi:"relation,outputs"`
226-
Project *Project `jsonapi:"relation,project"`
227-
Tags []*Tag `jsonapi:"relation,tags"`
228-
CurrentConfigurationVersion *ConfigurationVersion `jsonapi:"relation,current-configuration-version,omitempty"`
229-
LockedBy *LockedByChoice `jsonapi:"polyrelation,locked-by"`
230-
Variables []*Variable `jsonapi:"relation,vars"`
231-
TagBindings []*TagBinding `jsonapi:"relation,tag-bindings"`
220+
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
221+
CurrentRun *Run `jsonapi:"relation,current-run"`
222+
CurrentStateVersion *StateVersion `jsonapi:"relation,current-state-version"`
223+
Organization *Organization `jsonapi:"relation,organization"`
224+
SSHKey *SSHKey `jsonapi:"relation,ssh-key"`
225+
Outputs []*WorkspaceOutputs `jsonapi:"relation,outputs"`
226+
Project *Project `jsonapi:"relation,project"`
227+
Tags []*Tag `jsonapi:"relation,tags"`
228+
CurrentConfigurationVersion *ConfigurationVersion `jsonapi:"relation,current-configuration-version,omitempty"`
229+
LockedBy *LockedByChoice `jsonapi:"polyrelation,locked-by"`
230+
Variables []*Variable `jsonapi:"relation,vars"`
231+
TagBindings []*TagBinding `jsonapi:"relation,tag-bindings"`
232+
EffectiveTagBindings []*EffectiveTagBinding `jsonapi:"relation,effective-tag-bindings"`
232233

233234
// Deprecated: Use DataRetentionPolicyChoice instead.
234235
DataRetentionPolicy *DataRetentionPolicy
@@ -314,6 +315,7 @@ const (
314315
WSCurrentRunPlan WSIncludeOpt = "current_run.plan"
315316
WSCurrentRunConfigVer WSIncludeOpt = "current_run.configuration_version"
316317
WSCurrentrunConfigVerIngress WSIncludeOpt = "current_run.configuration_version.ingress_attributes"
318+
WSEffectiveTagBindings WSIncludeOpt = "effective_tag_bindings"
317319
WSLockedBy WSIncludeOpt = "locked_by"
318320
WSReadme WSIncludeOpt = "readme"
319321
WSOutputs WSIncludeOpt = "outputs"

workspace_integration_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,33 @@ func TestWorkspacesList(t *testing.T) {
299299
assert.Contains(t, wl3.Items, w2)
300300
})
301301

302+
t.Run("when including effective tag bindings", func(t *testing.T) {
303+
skipUnlessBeta(t)
304+
305+
orgTest2, orgTest2Cleanup := createOrganization(t, client)
306+
t.Cleanup(orgTest2Cleanup)
307+
308+
_, wTestCleanup1 := createWorkspaceWithOptions(t, client, orgTest2, WorkspaceCreateOptions{
309+
Name: String(randomString(t)),
310+
TagBindings: []*TagBinding{
311+
{Key: "key1", Value: "value1"},
312+
{Key: "key2", Value: "value2a"},
313+
},
314+
})
315+
t.Cleanup(wTestCleanup1)
316+
317+
wl, err := client.Workspaces.List(ctx, orgTest2.Name, &WorkspaceListOptions{
318+
Include: []WSIncludeOpt{WSEffectiveTagBindings},
319+
})
320+
require.NoError(t, err)
321+
require.Len(t, wl.Items, 1)
322+
require.Len(t, wl.Items[0].EffectiveTagBindings, 2)
323+
assert.NotEmpty(t, wl.Items[0].EffectiveTagBindings[0].Key)
324+
assert.NotEmpty(t, wl.Items[0].EffectiveTagBindings[0].Value)
325+
assert.NotEmpty(t, wl.Items[0].EffectiveTagBindings[1].Key)
326+
assert.NotEmpty(t, wl.Items[0].EffectiveTagBindings[1].Value)
327+
})
328+
302329
t.Run("when using project id filter and project contains workspaces", func(t *testing.T) {
303330
// create a project in the orgTest
304331
p, pTestCleanup := createProject(t, client, orgTest)

0 commit comments

Comments
 (0)