diff --git a/CHANGELOG.md b/CHANGELOG.md index e229f8e39..884aa8c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Unreleased * Add `Query` param field to `OrganizationListOptions` to allow searching based on name or email by @laurenolivia [#529](https://github.com/hashicorp/go-tfe/pull/529) +* Add support for managing workspace and organization health assessment (drift detection) setting [#462](https://github.com/hashicorp/go-tfe/pull/462) + ## Bug Fixes * Fixes null value returned in variable set relationship in `VariableSetVariable` by @sebasslash [#521](https://github.com/hashicorp/go-tfe/pull/521) diff --git a/organization.go b/organization.go index 790b1627b..d7b0a2b0a 100644 --- a/organization.go +++ b/organization.go @@ -64,6 +64,7 @@ type OrganizationList struct { // Organization represents a Terraform Enterprise organization. type Organization struct { Name string `jsonapi:"primary,organizations"` + AssessmentsEnforced bool `jsonapi:"attr,assessments-enforced"` CollaboratorAuthPolicy AuthPolicyType `jsonapi:"attr,collaborator-auth-policy"` CostEstimationEnabled bool `jsonapi:"attr,cost-estimation-enabled"` CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` @@ -142,6 +143,9 @@ type OrganizationCreateOptions struct { // Required: Name of the organization. Name *string `jsonapi:"attr,name"` + // Optional: AssessmentsEnforced toggles whether health assessment enablement is enforced across all assessable workspaces (those with a minimum terraform versio of 0.15.4 and not running in local execution mode) or if the decision to enabled health assessments is delegated to the workspace setting AssessmentsEnabled. + AssessmentsEnforced *bool `jsonapi:"attr,assessments-enforced,omitempty"` + // Required: Admin email address. Email *string `jsonapi:"attr,email"` @@ -175,6 +179,9 @@ type OrganizationUpdateOptions struct { // New name for the organization. Name *string `jsonapi:"attr,name,omitempty"` + // Optional: AssessmentsEnforced toggles whether health assessment enablement is enforced across all assessable workspaces (those with a minimum terraform versio of 0.15.4 and not running in local execution mode) or if the decision to enabled health assessments is delegated to the workspace setting AssessmentsEnabled. + AssessmentsEnforced *bool `jsonapi:"attr,assessments-enforced,omitempty"` + // New admin email address. Email *string `jsonapi:"attr,email,omitempty"` diff --git a/organization_integration_test.go b/organization_integration_test.go index 46ecccd9c..89c66765d 100644 --- a/organization_integration_test.go +++ b/organization_integration_test.go @@ -478,6 +478,7 @@ func TestOrganization_Unmarshal(t *testing.T) { "type": "organizations", "id": "org-name", "attributes": map[string]interface{}{ + "assessments-enforced": true, "collaborator-auth-policy": AuthPolicyPassword, "cost-estimation-enabled": true, "created-at": "2018-03-02T23:42:06.651Z", @@ -500,6 +501,7 @@ func TestOrganization_Unmarshal(t *testing.T) { parsedTime, err := time.Parse(iso8601TimeFormat, "2018-03-02T23:42:06.651Z") require.NoError(t, err) assert.Equal(t, org.Name, "org-name") + assert.Equal(t, org.AssessmentsEnforced, true) assert.Equal(t, org.CreatedAt, parsedTime) assert.Equal(t, org.CollaboratorAuthPolicy, AuthPolicyPassword) assert.Equal(t, org.CostEstimationEnabled, true) diff --git a/workspace.go b/workspace.go index d5fe03611..462048e3b 100644 --- a/workspace.go +++ b/workspace.go @@ -111,6 +111,7 @@ type Workspace struct { Actions *WorkspaceActions `jsonapi:"attr,actions"` AgentPoolID string `jsonapi:"attr,agent-pool-id"` AllowDestroyPlan bool `jsonapi:"attr,allow-destroy-plan"` + AssessmentsEnabled bool `jsonapi:"attr,assessments-enabled"` AutoApply bool `jsonapi:"attr,auto-apply"` CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"` CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` @@ -264,6 +265,11 @@ type WorkspaceCreateOptions struct { // Optional: Whether destroy plans can be queued on the workspace. AllowDestroyPlan *bool `jsonapi:"attr,allow-destroy-plan,omitempty"` + // Optional: Whether to enable health assessments (drift detection etc.) for the workspace. + // Reference: https://www.terraform.io/cloud-docs/api-docs/workspaces#create-a-workspace + // Requires remote execution mode, Terraform Cloud Business entitlement, and a valid agent pool to work + AssessmentsEnabled *bool `jsonapi:"attr,assessments-enabled,omitempty"` + // Optional: Whether to automatically apply changes when a Terraform plan is successful. AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"` @@ -377,6 +383,11 @@ type WorkspaceUpdateOptions struct { // Optional: Whether destroy plans can be queued on the workspace. AllowDestroyPlan *bool `jsonapi:"attr,allow-destroy-plan,omitempty"` + // Optional: Whether to enable health assessments (drift detection etc.) for the workspace. + // Reference: https://www.terraform.io/cloud-docs/api-docs/workspaces#update-a-workspace + // Requires remote execution mode, Terraform Cloud Business entitlement, and a valid agent pool to work + AssessmentsEnabled *bool `jsonapi:"attr,assessments-enabled,omitempty"` + // Optional: Whether to automatically apply changes when a Terraform plan is successful. AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"` diff --git a/workspace_integration_test.go b/workspace_integration_test.go index 9c3b5eb0b..a24b309d3 100644 --- a/workspace_integration_test.go +++ b/workspace_integration_test.go @@ -327,6 +327,7 @@ func TestWorkspacesCreate(t *testing.T) { AllowDestroyPlan: Bool(false), AutoApply: Bool(true), Description: String("qux"), + AssessmentsEnabled: Bool(false), FileTriggersEnabled: Bool(true), Operations: Bool(true), QueueAllRuns: Bool(true), @@ -363,6 +364,7 @@ func TestWorkspacesCreate(t *testing.T) { assert.Equal(t, *options.Description, item.Description) assert.Equal(t, *options.AllowDestroyPlan, item.AllowDestroyPlan) assert.Equal(t, *options.AutoApply, item.AutoApply) + assert.Equal(t, *options.AssessmentsEnabled, item.AssessmentsEnabled) assert.Equal(t, *options.FileTriggersEnabled, item.FileTriggersEnabled) assert.Equal(t, *options.Operations, item.Operations) assert.Equal(t, *options.QueueAllRuns, item.QueueAllRuns) @@ -715,16 +717,19 @@ func TestWorkspacesUpdate(t *testing.T) { orgTest, orgTestCleanup := createOrganization(t, client) defer orgTestCleanup() + upgradeOrganizationSubscription(t, client, orgTest) + wTest, _ := createWorkspace(t, client, orgTest) t.Run("when updating a subset of values", func(t *testing.T) { options := WorkspaceUpdateOptions{ - Name: String(wTest.Name), - AllowDestroyPlan: Bool(false), - AutoApply: Bool(true), - Operations: Bool(true), - QueueAllRuns: Bool(true), - TerraformVersion: String("0.10.0"), + Name: String(wTest.Name), + AllowDestroyPlan: Bool(false), + AutoApply: Bool(true), + Operations: Bool(true), + QueueAllRuns: Bool(true), + AssessmentsEnabled: Bool(true), + TerraformVersion: String("0.15.4"), } wAfter, err := client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, options) @@ -734,6 +739,7 @@ func TestWorkspacesUpdate(t *testing.T) { assert.NotEqual(t, wTest.AllowDestroyPlan, wAfter.AllowDestroyPlan) assert.NotEqual(t, wTest.AutoApply, wAfter.AutoApply) assert.NotEqual(t, wTest.QueueAllRuns, wAfter.QueueAllRuns) + assert.NotEqual(t, wTest.AssessmentsEnabled, wAfter.AssessmentsEnabled) assert.NotEqual(t, wTest.TerraformVersion, wAfter.TerraformVersion) assert.Equal(t, wTest.WorkingDirectory, wAfter.WorkingDirectory) })