Skip to content

Commit

Permalink
Merge pull request #585 from hashicorp/gs/add-run-task-description-field
Browse files Browse the repository at this point in the history
Add Organization run task description field
  • Loading branch information
glennsarti committed Aug 3, 2022
2 parents 08c9a7d + 55da8cb commit 939126d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## Unreleased

FEATURES:
* r/tfe_organization_run_task, d/tfe_organization_run_task: Add `description` attribute to organization run tasks. ([#585](https://github.com/hashicorp/terraform-provider-tfe/pull/585))

## 0.35.0 (July 27th, 2022)

BREAKING CHANGES:
Expand Down
6 changes: 6 additions & 0 deletions tfe/data_source_organization_run_task.go
Expand Up @@ -34,6 +34,11 @@ func dataSourceTFEOrganizationRunTask() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand All @@ -51,6 +56,7 @@ func dataSourceTFEOrganizationRunTaskRead(d *schema.ResourceData, meta interface
d.Set("url", task.URL)
d.Set("category", task.Category)
d.Set("enabled", task.Enabled)
d.Set("description", task.Description)
d.SetId(task.ID)

return nil
Expand Down
2 changes: 2 additions & 0 deletions tfe/data_source_organization_run_task_test.go
Expand Up @@ -28,6 +28,7 @@ func TestAccTFEOrganizationRunTaskDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.tfe_organization_run_task.foobar", "url", runTasksURL()),
resource.TestCheckResourceAttr("data.tfe_organization_run_task.foobar", "category", "task"),
resource.TestCheckResourceAttr("data.tfe_organization_run_task.foobar", "enabled", "false"),
resource.TestCheckResourceAttr("data.tfe_organization_run_task.foobar", "description", "a description"),
resource.TestCheckResourceAttrSet("data.tfe_organization_run_task.foobar", "id"),
resource.TestCheckResourceAttrSet("data.tfe_organization_run_task.foobar", "organization"),
),
Expand All @@ -49,6 +50,7 @@ resource "tfe_organization_run_task" "foobar" {
name = "foobar-task-%d"
hmac_key = "Password1"
enabled = false
description = "a description"
}
data "tfe_organization_run_task" "foobar" {
Expand Down
21 changes: 15 additions & 6 deletions tfe/resource_tfe_organization_run_task.go
Expand Up @@ -56,6 +56,11 @@ func resourceTFEOrganizationRunTask() *schema.Resource {
Default: true,
Optional: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand All @@ -69,11 +74,12 @@ func resourceTFEOrganizationRunTaskCreate(d *schema.ResourceData, meta interface

// Create a new options struct.
options := tfe.RunTaskCreateOptions{
Name: name,
URL: d.Get("url").(string),
Category: d.Get("category").(string),
HMACKey: tfe.String(d.Get("hmac_key").(string)),
Enabled: tfe.Bool(d.Get("enabled").(bool)),
Name: name,
URL: d.Get("url").(string),
Category: d.Get("category").(string),
HMACKey: tfe.String(d.Get("hmac_key").(string)),
Enabled: tfe.Bool(d.Get("enabled").(bool)),
Description: tfe.String(d.Get("description").(string)),
}

log.Printf("[DEBUG] Create task %s for organization: %s", name, organization)
Expand Down Expand Up @@ -123,6 +129,9 @@ func resourceTFEOrganizationRunTaskUpdate(d *schema.ResourceData, meta interface
if d.HasChange("hmac_key") {
options.HMACKey = tfe.String(d.Get("hmac_key").(string))
}
if d.HasChange("description") {
options.Description = tfe.String(d.Get("description").(string))
}

log.Printf("[DEBUG] Update configuration of task: %s", d.Id())
task, err := tfeClient.RunTasks.Update(ctx, d.Id(), options)
Expand Down Expand Up @@ -158,7 +167,7 @@ func resourceTFEOrganizationRunTaskRead(d *schema.ResourceData, meta interface{}
// The HMAC Key is always empty from the API so all we can do is
// echo the request's key to the response
d.Set("hmac_key", tfe.String(d.Get("hmac_key").(string)))

d.Set("description", task.Description)
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions tfe/resource_tfe_organization_run_task_test.go
Expand Up @@ -56,6 +56,7 @@ func TestAccTFEOrganizationRunTask_create(t *testing.T) {
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "category", "task"),
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "hmac_key", ""),
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "enabled", "false"),
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "description", ""),
),
},
{
Expand All @@ -66,6 +67,7 @@ func TestAccTFEOrganizationRunTask_create(t *testing.T) {
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "category", "task"),
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "hmac_key", "somepassword"),
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "enabled", "true"),
resource.TestCheckResourceAttr("tfe_organization_run_task.foobar", "description", "a description"),
),
},
},
Expand Down Expand Up @@ -175,6 +177,7 @@ func testAccTFEOrganizationRunTask_update(orgName string, rInt int, runTaskURL s
name = "foobar-task-%d-new"
enabled = true
hmac_key = "somepassword"
description = "a description"
}
`, orgName, runTaskURL, rInt)
}
5 changes: 3 additions & 2 deletions website/docs/d/organization_run_task.html.markdown
Expand Up @@ -33,6 +33,7 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `category` - The type of task.
* `description` - A short description of the the task.
* `enabled` - Whether the task will be run.
* `id` - The ID of the Run task.
* `url` - URL to send a run task payload.
* `id` - The ID of the task.
* `url` - URL to send a task payload.
2 changes: 2 additions & 0 deletions website/docs/r/organization_run_task.html.markdown
Expand Up @@ -22,6 +22,7 @@ resource "tfe_organization_run_task" "example" {
url = "https://external.service.com"
name = "task-name"
enabled = true
description = "An example task"
}
```

Expand All @@ -31,6 +32,7 @@ The following arguments are supported:

* `category` - (Optional) The type of task.
* `enabled` - (Optional) Whether the task will be run.
* `description` - (Optional) A short description of the the task.
* `hmac_key` - (Optional) HMAC key to verify run task.
* `name` - (Required) Name of the task.
* `organization` - (Required) Name of the organization.
Expand Down

0 comments on commit 939126d

Please sign in to comment.