Skip to content

Commit

Permalink
Merge pull request #75 from hashicorp/add-workspace-filtering-fields
Browse files Browse the repository at this point in the history
Add workspace filtering fields
  • Loading branch information
alisdair authored Jun 3, 2019
2 parents f2cf23a + 9213905 commit e4644f2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
22 changes: 22 additions & 0 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ type Workspace struct {
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Environment string `jsonapi:"attr,environment"`
FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"`
Locked bool `jsonapi:"attr,locked"`
MigrationEnvironment string `jsonapi:"attr,migration-environment"`
Name string `jsonapi:"attr,name"`
Operations bool `jsonapi:"attr,operations"`
Permissions *WorkspacePermissions `jsonapi:"attr,permissions"`
QueueAllRuns bool `jsonapi:"attr,queue-all-runs"`
TerraformVersion string `jsonapi:"attr,terraform-version"`
TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes"`
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
WorkingDirectory string `jsonapi:"attr,working-directory"`

Expand Down Expand Up @@ -149,6 +151,12 @@ type WorkspaceCreateOptions struct {
// Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

// Whether to filter runs based on the changed files in a VCS push. If
// enabled, the working directory and trigger prefixes describe a set of
// paths which must contain changes for a VCS push to trigger a run. If
// disabled, any push will trigger a run.
FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"`

// The legacy TFE environment to use as the source of the migration, in the
// form organization/environment. Omit this unless you are migrating a legacy
// environment.
Expand All @@ -167,6 +175,10 @@ type WorkspaceCreateOptions struct {
// workspace, the latest version is selected unless otherwise specified.
TerraformVersion *string `jsonapi:"attr,terraform-version,omitempty"`

// List of repository-root-relative paths which list all locations to be
// tracked for changes. See FileTriggersEnabled above for more details.
TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes,omitempty"`

// Settings for the workspace's VCS repository. If omitted, the workspace is
// created without a VCS repo. If included, you must specify at least the
// oauth-token-id and identifier keys below.
Expand Down Expand Up @@ -265,13 +277,23 @@ type WorkspaceUpdateOptions struct {
// API and UI.
Name *string `jsonapi:"attr,name,omitempty"`

// Whether to filter runs based on the changed files in a VCS push. If
// enabled, the working directory and trigger prefixes describe a set of
// paths which must contain changes for a VCS push to trigger a run. If
// disabled, any push will trigger a run.
FileTriggersEnabled *bool `jsonapi:"attr,file-triggers-enabled,omitempty"`

// Whether to queue all runs. Unless this is set to true, runs triggered by
// a webhook will not be queued until at least one run is manually queued.
QueueAllRuns *bool `jsonapi:"attr,queue-all-runs,omitempty"`

// The version of Terraform to use for this workspace.
TerraformVersion *string `jsonapi:"attr,terraform-version,omitempty"`

// List of repository-root-relative paths which list all locations to be
// tracked for changes. See FileTriggersEnabled above for more details.
TriggerPrefixes []string `jsonapi:"attr,trigger-prefixes,omitempty"`

// To delete a workspace's existing VCS repo, specify null instead of an
// object. To modify a workspace's existing VCS repo, include whichever of
// the keys below you wish to modify. To add a new VCS repo to a workspace
Expand Down
28 changes: 18 additions & 10 deletions workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ func TestWorkspacesCreate(t *testing.T) {

t.Run("with valid options", func(t *testing.T) {
options := WorkspaceCreateOptions{
Name: String("foo"),
AutoApply: Bool(true),
QueueAllRuns: Bool(true),
TerraformVersion: String("0.11.0"),
WorkingDirectory: String("bar/"),
Name: String("foo"),
AutoApply: Bool(true),
FileTriggersEnabled: Bool(true),
QueueAllRuns: Bool(true),
TerraformVersion: String("0.11.0"),
TriggerPrefixes: []string{"/modules", "/shared"},
WorkingDirectory: String("bar/"),
}

w, err := client.Workspaces.Create(ctx, orgTest.Name, options)
Expand All @@ -107,8 +109,10 @@ func TestWorkspacesCreate(t *testing.T) {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled)
assert.Equal(t, *options.QueueAllRuns, item.QueueAllRuns)
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
assert.Equal(t, options.TriggerPrefixes, item.TriggerPrefixes)
assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory)
}
})
Expand Down Expand Up @@ -227,11 +231,13 @@ func TestWorkspacesUpdate(t *testing.T) {

t.Run("with valid options", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(randomString(t)),
AutoApply: Bool(false),
QueueAllRuns: Bool(false),
TerraformVersion: String("0.11.1"),
WorkingDirectory: String("baz/"),
Name: String(randomString(t)),
AutoApply: Bool(false),
FileTriggersEnabled: Bool(true),
QueueAllRuns: Bool(false),
TerraformVersion: String("0.11.1"),
TriggerPrefixes: []string{"/modules", "/shared"},
WorkingDirectory: String("baz/"),
}

w, err := client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, options)
Expand All @@ -247,8 +253,10 @@ func TestWorkspacesUpdate(t *testing.T) {
} {
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled)
assert.Equal(t, *options.QueueAllRuns, item.QueueAllRuns)
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
assert.Equal(t, options.TriggerPrefixes, item.TriggerPrefixes)
assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory)
}
})
Expand Down

0 comments on commit e4644f2

Please sign in to comment.