Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable sets #305

Merged
merged 32 commits into from Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cffa1a2
Add VariableSets
rexredinger Feb 7, 2022
be30a5e
Add VariableSetVariables, needs more tests
rexredinger Feb 7, 2022
3b76d5b
VariableSetVariable tests (not working yet)
rexredinger Feb 8, 2022
86c145f
Fix variableSetVariable tests
rexredinger Feb 10, 2022
20c32bf
Cleanup ws and go.sum
rexredinger Feb 10, 2022
f0c80c7
Remove TODOs
rexredinger Feb 10, 2022
95f8fc0
Use typed strings for include options
rexredinger Feb 15, 2022
a1990e6
Use option pointers in the 1.0 style
rexredinger Feb 15, 2022
30d11f1
fix lint complaint
rexredinger Feb 15, 2022
b3e6a26
recognize organizaiton relation for VariableSet
rexredinger Feb 17, 2022
79ddc1a
Fix varset interface typo
rexredinger Mar 2, 2022
d4e919d
Add VariablSetVariable Read function
rexredinger Mar 2, 2022
e815f86
Fix style issue in params
rexredinger Mar 15, 2022
b9513fc
omitempty for nonessential create params
rexredinger Mar 15, 2022
a351fa4
fix bad merge
rexredinger Mar 21, 2022
e946aae
Refactor to typed errors
rexredinger Mar 21, 2022
31b4676
Address more error typing and lint fixes
rexredinger Mar 21, 2022
ddf76d7
somehow I thought I already committed this
rexredinger Mar 21, 2022
566ce6f
variable set variable test fix
rexredinger Mar 21, 2022
30c245e
Remove latin that go lint hates
rexredinger Mar 21, 2022
716b4e4
Merge branch 'main' into variable_sets
rexredinger Mar 22, 2022
d7c7b8c
Update Assign documentation to be clearer
rexredinger Mar 22, 2022
fa9ea31
remove more latin from the lint trap
rexredinger Mar 22, 2022
2ca2ccf
Bring include opt usage inline with other resources
rexredinger Mar 22, 2022
6ab16fd
fix missing url.QueryEscape
rexredinger Mar 22, 2022
7ef83ee
Put that back. Can you tell I'm not firing on all cylinders
rexredinger Mar 22, 2022
6bd3ead
_Apply_ variable sets
rexredinger Mar 22, 2022
20889e3
typo
rexredinger Mar 22, 2022
8ca362f
Rename, use pointers, validate, hide details
rexredinger Mar 23, 2022
5bb1a6c
spelling~
rexredinger Mar 24, 2022
c67cf9b
spelling~
rexredinger Mar 24, 2022
9188b96
spelling~
rexredinger Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions errors.go
Expand Up @@ -146,6 +146,8 @@ var (

ErrInvalidNotificationTrigger = errors.New("invalid value for notification trigger")

ErrInvalidVariableSetID = errors.New("invalid variable set ID")

ErrInvalidCommentID = errors.New("invalid value for comment ID")

ErrInvalidCommentBody = errors.New("invalid value for comment body")
Expand Down Expand Up @@ -253,5 +255,9 @@ var (

ErrRequiredUsernameOrMembershipIds = errors.New("usernames or organization membership ids are required")

ErrRequiredGlobalFlag = errors.New("global flag is required")

ErrRequiredWorkspacesList = errors.New("no workspaces list provided")

ErrCommentBody = errors.New("comment body is required")
)
84 changes: 84 additions & 0 deletions helper_test.go
Expand Up @@ -1077,6 +1077,90 @@ func createWorkspaceRunTask(t *testing.T, client *Client, workspace *Workspace,
}
}

func createVariableSet(t *testing.T, client *Client, org *Organization, options VariableSetCreateOptions) (*VariableSet, func()) {
var orgCleanup func()

if org == nil {
org, orgCleanup = createOrganization(t, client)
}

if options.Name == nil {
options.Name = String(randomString(t))
}

if options.Global == nil {
options.Global = Bool(false)
}

ctx := context.Background()
vs, err := client.VariableSets.Create(ctx, org.Name, &options)
if err != nil {
t.Fatal(err)
}

return vs, func() {
if err := client.VariableSets.Delete(ctx, vs.ID); err != nil {
t.Errorf("Error destroying variable set! WARNING: Dangling resources\n"+
"may exist! The full error is shown below.\n\n"+
"VariableSet: %s\nError: %s", vs.Name, err)
}

if orgCleanup != nil {
orgCleanup()
}
}
}

func createVariableSetVariable(t *testing.T, client *Client, vs *VariableSet, options VariableSetVariableCreateOptions) (*VariableSetVariable, func()) {
var vsCleanup func()

if vs == nil {
vs, vsCleanup = createVariableSet(t, client, nil, VariableSetCreateOptions{})
}

if options.Key == nil {
options.Key = String(randomString(t))
}

if options.Value == nil {
options.Value = String(randomString(t))
}

if options.Description == nil {
options.Description = String("")
}

if options.Category == nil {
options.Category = Category(CategoryTerraform)
}

if options.HCL == nil {
options.HCL = Bool(false)
}

if options.Sensitive == nil {
options.Sensitive = Bool(false)
}

ctx := context.Background()
v, err := client.VariableSetVariables.Create(ctx, vs.ID, &options)
if err != nil {
t.Fatal(err)
}

return v, func() {
if err := client.VariableSetVariables.Delete(ctx, vs.ID, v.ID); err != nil {
t.Errorf("Error destroying variable! WARNING: Dangling resources\n"+
"may exist! The full error is shown below.\n\n"+
"Variable: %s\nError: %s", v.Key, err)
}

if vsCleanup != nil {
vsCleanup()
}
}
}

func genSha(t *testing.T, secret, data string) string {
h := hmac.New(sha256.New, []byte(secret))
_, err := h.Write([]byte(data))
Expand Down
4 changes: 4 additions & 0 deletions tfe.go
Expand Up @@ -143,6 +143,8 @@ type Client struct {
Users Users
UserTokens UserTokens
Variables Variables
VariableSets VariableSets
VariableSetVariables VariableSetVariables
Workspaces Workspaces
WorkspaceRunTasks WorkspaceRunTasks

Expand Down Expand Up @@ -284,6 +286,8 @@ func NewClient(cfg *Config) (*Client, error) {
client.Users = &users{client: client}
client.UserTokens = &userTokens{client: client}
client.Variables = &variables{client: client}
client.VariableSets = &variableSets{client: client}
client.VariableSetVariables = &variableSetVariables{client: client}
client.Workspaces = &workspaces{client: client}
client.WorkspaceRunTasks = &workspaceRunTasks{client: client}

Expand Down
2 changes: 1 addition & 1 deletion variable_integration_test.go
Expand Up @@ -128,7 +128,7 @@ func TestVariablesCreate(t *testing.T) {
options := VariableCreateOptions{
Key: String(randomString(t)),
Value: String(randomString(t)),
Description: String("tortor aliquam nulla facilisi cras fermentum odio eu feugiat pretium nibh ipsum consequat nisl vel pretium lectus quam id leo in vitae turpis massa sed elementum tempus egestas sed sed risus pretium quam vulputate dignissim suspendisse in est ante in nibh mauris cursus mattis molestie a iaculis at erat pellentesque adipiscing commodo elit at imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean et tortor"),
Description: String("tortor aliquam nulla go lint is fussy about spelling cras fermentum odio eu feugiat pretium nibh ipsum consequat nisl vel pretium lectus quam id leo in vitae turpis massa sed elementum tempus egestas sed sed risus pretium quam vulputate dignissim suspendisse in est ante in nibh mauris cursus mattis molestie a iaculis at erat pellentesque adipiscing commodo elit at imperdiet dui accumsan sit amet nulla redacted morbi tempus iaculis urna id volutpat lacus laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean et tortor"),
Category: Category(CategoryTerraform),
}

Expand Down