Skip to content

Commit baa8e39

Browse files
committed
fix: Add links attribute to effective tags
1 parent fd1a115 commit baa8e39

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

tag.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
package tfe
55

6-
import "fmt"
6+
import (
7+
"fmt"
8+
)
79

810
type TagList struct {
911
*Pagination
@@ -26,6 +28,8 @@ type EffectiveTagBinding struct {
2628
ID string `jsonapi:"primary,effective-tag-bindings"`
2729
Key string `jsonapi:"attr,key"`
2830
Value string `jsonapi:"attr,value,omitempty"`
31+
32+
Links map[string]interface{} `jsonapi:"links,omitempty"`
2933
}
3034

3135
func encodeTagFiltersAsParams(filters []*TagBinding) map[string][]string {

workspace_integration_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,3 +3089,69 @@ func TestWorkspacesAutoDestroyDuration(t *testing.T) {
30893089
require.Equal(t, wTest.InheritsProjectAutoDestroy, false)
30903090
})
30913091
}
3092+
3093+
func TestWorkspaces_effectiveTagBindingsInheritedFrom(t *testing.T) {
3094+
skipUnlessBeta(t)
3095+
3096+
client := testClient(t)
3097+
ctx := context.Background()
3098+
3099+
orgTest, orgTestCleanup := createOrganization(t, client)
3100+
t.Cleanup(orgTestCleanup)
3101+
3102+
projTest, projTestCleanup := createProject(t, client, orgTest)
3103+
t.Cleanup(projTestCleanup)
3104+
3105+
ws, wsCleanup := createWorkspaceWithOptions(t, client, orgTest, WorkspaceCreateOptions{
3106+
Name: String("mycoolworkspace"),
3107+
Project: projTest,
3108+
})
3109+
t.Cleanup(wsCleanup)
3110+
3111+
_, err := client.Workspaces.AddTagBindings(ctx, ws.ID, WorkspaceAddTagBindingsOptions{
3112+
TagBindings: []*TagBinding{
3113+
{
3114+
Key: "a",
3115+
Value: "1",
3116+
},
3117+
{
3118+
Key: "b",
3119+
Value: "2",
3120+
},
3121+
},
3122+
})
3123+
require.NoError(t, err)
3124+
3125+
t.Run("when no tags are inherited from the project", func(t *testing.T) {
3126+
effectiveBindings, err := client.Workspaces.ListEffectiveTagBindings(ctx, ws.ID)
3127+
require.NoError(t, err)
3128+
3129+
for _, binding := range effectiveBindings {
3130+
require.Nil(t, binding.Links)
3131+
}
3132+
})
3133+
3134+
t.Run("when tags are inherited from the project", func(t *testing.T) {
3135+
_, err := client.Projects.AddTagBindings(ctx, projTest.ID, ProjectAddTagBindingsOptions{
3136+
TagBindings: []*TagBinding{
3137+
{
3138+
Key: "inherited",
3139+
Value: "foo",
3140+
},
3141+
},
3142+
})
3143+
require.NoError(t, err)
3144+
3145+
effectiveBindings, err := client.Workspaces.ListEffectiveTagBindings(ctx, ws.ID)
3146+
require.NoError(t, err)
3147+
3148+
for _, binding := range effectiveBindings {
3149+
if binding.Key == "inherited" {
3150+
require.NotNil(t, binding.Links)
3151+
require.NotNil(t, binding.Links["inherited-from"])
3152+
} else {
3153+
require.Nil(t, binding.Links)
3154+
}
3155+
}
3156+
})
3157+
}

0 commit comments

Comments
 (0)