Skip to content

Commit 588526b

Browse files
authored
[BETA] Create a project-owned varset (#992)
* Create a project-owned varset * Add test for reading parent * Add CHANGELOG entry
1 parent fc80091 commit 588526b

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Add support for filtering by key/value tags by @brandonc [#987](https://github.com/hashicorp/go-tfe/pull/987)
77
* Add support for reading a registry module by its unique identifier by @dsa0x
88
[#988](https://github.com/hashicorp/go-tfe/pull/988)
9+
* Adds BETA support for a variable set `Parent` relation, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @jbonhag [#992](https://github.com/hashicorp/go-tfe/pull/992)
910

1011
# v1.68.0
1112

variable_set.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ type VariableSetList struct {
6565
Items []*VariableSet
6666
}
6767

68+
// Parent represents the variable set's parent (currently only organizations and projects are supported).
69+
// This relation is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
70+
type Parent struct {
71+
Organization *Organization
72+
Project *Project
73+
}
74+
6875
// VariableSet represents a Terraform Enterprise variable set.
6976
type VariableSet struct {
7077
ID string `jsonapi:"primary,varsets"`
@@ -74,10 +81,13 @@ type VariableSet struct {
7481
Priority bool `jsonapi:"attr,priority"`
7582

7683
// Relations
77-
Organization *Organization `jsonapi:"relation,organization"`
78-
Workspaces []*Workspace `jsonapi:"relation,workspaces,omitempty"`
79-
Projects []*Project `jsonapi:"relation,projects,omitempty"`
80-
Variables []*VariableSetVariable `jsonapi:"relation,vars,omitempty"`
84+
Organization *Organization `jsonapi:"relation,organization"`
85+
// Optional: Parent represents the variable set's parent (currently only organizations and projects are supported).
86+
// This relation is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
87+
Parent *Parent `jsonapi:"polyrelation,parent"`
88+
Workspaces []*Workspace `jsonapi:"relation,workspaces,omitempty"`
89+
Projects []*Project `jsonapi:"relation,projects,omitempty"`
90+
Variables []*VariableSetVariable `jsonapi:"relation,vars,omitempty"`
8191
}
8292

8393
// A list of relations to include. See available resources
@@ -122,6 +132,10 @@ type VariableSetCreateOptions struct {
122132
// If true the variables in the set override any other variable values set
123133
// in a more specific scope including values set on the command line.
124134
Priority *bool `jsonapi:"attr,priority,omitempty"`
135+
136+
// Optional: Parent represents the variable set's parent (currently only organizations and projects are supported).
137+
// This relation is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
138+
Parent *Parent `jsonapi:"polyrelation,parent"`
125139
}
126140

127141
// VariableSetReadOptions represents the options for reading variable sets.

variable_set_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,40 @@ func TestVariableSetsCreate(t *testing.T) {
232232
assert.Nil(t, vs)
233233
assert.EqualError(t, err, ErrRequiredGlobalFlag.Error())
234234
})
235+
236+
t.Run("when creating project-owned variable set", func(t *testing.T) {
237+
skipUnlessBeta(t)
238+
239+
prjTest, prjTestCleanup := createProject(t, client, orgTest)
240+
t.Cleanup(prjTestCleanup)
241+
242+
options := VariableSetCreateOptions{
243+
Name: String("project-varset"),
244+
Description: String("a project variable set"),
245+
Global: Bool(false),
246+
Parent: &Parent{
247+
Project: prjTest,
248+
},
249+
}
250+
251+
vs, err := client.VariableSets.Create(ctx, orgTest.Name, &options)
252+
require.NoError(t, err)
253+
254+
// Get refreshed view from the API
255+
refreshed, err := client.VariableSets.Read(ctx, vs.ID, nil)
256+
require.NoError(t, err)
257+
258+
for _, item := range []*VariableSet{
259+
vs,
260+
refreshed,
261+
} {
262+
assert.NotEmpty(t, item.ID)
263+
assert.Equal(t, *options.Name, item.Name)
264+
assert.Equal(t, *options.Description, item.Description)
265+
assert.Equal(t, *options.Global, item.Global)
266+
assert.Equal(t, options.Parent.Project.ID, item.Parent.Project.ID)
267+
}
268+
})
235269
}
236270

237271
func TestVariableSetsRead(t *testing.T) {
@@ -255,6 +289,15 @@ func TestVariableSetsRead(t *testing.T) {
255289
assert.Nil(t, vs)
256290
assert.Error(t, err)
257291
})
292+
293+
t.Run("with parent relationship", func(t *testing.T) {
294+
skipUnlessBeta(t)
295+
296+
vs, err := client.VariableSets.Read(ctx, vsTest.ID, nil)
297+
require.NoError(t, err)
298+
assert.Equal(t, vsTest, vs)
299+
assert.Equal(t, orgTest.Name, vs.Parent.Organization.Name)
300+
})
258301
}
259302

260303
func TestVariableSetsUpdate(t *testing.T) {

0 commit comments

Comments
 (0)