diff --git a/workspace.go b/workspace.go index 7b95ac132..cdcd228cd 100644 --- a/workspace.go +++ b/workspace.go @@ -69,6 +69,7 @@ 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"` @@ -76,6 +77,7 @@ type Workspace struct { 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"` @@ -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. @@ -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. @@ -265,6 +277,12 @@ 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"` @@ -272,6 +290,10 @@ type WorkspaceUpdateOptions struct { // 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 diff --git a/workspace_test.go b/workspace_test.go index fc853ecac..6ceaf6925 100644 --- a/workspace_test.go +++ b/workspace_test.go @@ -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) @@ -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) } }) @@ -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) @@ -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) } })