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

Enable workspace and organization Health Assessment (drift detection) setting management #462

Merged
merged 11 commits into from Sep 14, 2022
2 changes: 2 additions & 0 deletions 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)

Expand Down
7 changes: 7 additions & 0 deletions organization.go
Expand Up @@ -68,6 +68,7 @@ type Organization struct {
CostEstimationEnabled bool `jsonapi:"attr,cost-estimation-enabled"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Email string `jsonapi:"attr,email"`
AssessmentsEnforced bool `jsonapi:"attr,assessments-enforced"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃拝 Could you add this attribute in alphabetical order?

ExternalID string `jsonapi:"attr,external-id"`
OwnersTeamSAMLRoleID string `jsonapi:"attr,owners-team-saml-role-id"`
Permissions *OrganizationPermissions `jsonapi:"attr,permissions"`
Expand Down Expand Up @@ -162,6 +163,9 @@ type OrganizationCreateOptions struct {

// Optional: SendPassingStatusesForUntriggeredSpeculativePlans toggles behavior of untriggered speculative plans to send status updates to version control systems like GitHub.
SendPassingStatusesForUntriggeredSpeculativePlans *bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans,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"`
}

// OrganizationUpdateOptions represents the options for updating an organization.
Expand Down Expand Up @@ -195,6 +199,9 @@ type OrganizationUpdateOptions struct {

// SendPassingStatusesForUntriggeredSpeculativePlans toggles behavior of untriggered speculative plans to send status updates to version control systems like GitHub.
SendPassingStatusesForUntriggeredSpeculativePlans *bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans,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"`
}

// ReadRunQueueOptions represents the options for showing the queue.
Expand Down
2 changes: 2 additions & 0 deletions organization_integration_test.go
Expand Up @@ -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",
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions workspace.go
Expand Up @@ -115,6 +115,7 @@ type Workspace struct {
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
Description string `jsonapi:"attr,description"`
AssessmentsEnabled bool `jsonapi:"attr,assessments-enabled"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃拝 Could you add this attribute in alphabetical order?

Environment string `jsonapi:"attr,environment"`
ExecutionMode string `jsonapi:"attr,execution-mode"`
FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"`
Expand Down Expand Up @@ -270,6 +271,11 @@ type WorkspaceCreateOptions struct {
// Optional: A description for the workspace.
Description *string `jsonapi:"attr,description,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: Which execution mode to use. Valid values are remote, local, and agent.
// When set to local, the workspace will be used for state storage only.
// This value must not be specified if operations is specified.
Expand Down Expand Up @@ -389,6 +395,11 @@ type WorkspaceUpdateOptions struct {
// Optional: A description for the workspace.
Description *string `jsonapi:"attr,description,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: Which execution mode to use. Valid values are remote, local, and agent.
// When set to local, the workspace will be used for state storage only.
// This value must not be specified if operations is specified.
Expand Down
18 changes: 12 additions & 6 deletions workspace_integration_test.go
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
rexredinger marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand All @@ -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)
})
Expand Down