Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ HOSTNAME=registry.terraform.io
NAMESPACE=tsuru
NAME=tsuru
BINARY=terraform-provider-${NAME}
VERSION=2.15.6
VERSION=2.15.8

UNAME_S := $(shell uname -s)
UNAME_P := $(shell uname -p)
Expand Down
15 changes: 13 additions & 2 deletions docs/resources/job.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ Tsuru Job
## Example Usage

```terraform
resource "tsuru_job" "my-job" {
resource "tsuru_job" "basic-job" {
name = "sample-job"
description = "job created with terraform"
plan = "c0.1m0.1"
team_owner = "admin"
pool = "staging"
schedule = "0 0 1 * *"
tags = ["tag1", "tag2"]
}


resource "tsuru_job" "full-featured-job" {
name = "sample-job"
description = "job created with terraform"
plan = "c0.1m0.1"
Expand Down Expand Up @@ -43,7 +54,6 @@ resource "tsuru_job" "my-job" {

### Required

- `container` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--container))
- `name` (String) Job name
- `plan` (String) Plan
- `pool` (String) The name of pool
Expand All @@ -53,6 +63,7 @@ resource "tsuru_job" "my-job" {

- `active_deadline_seconds` (Number) Time a Job can run before its terminated. Defaults is 3600
- `concurrency_policy` (String) Concurrency policy
- `container` (Block List, Max: 1) (see [below for nested schema](#nestedblock--container))
- `description` (String) Job description
- `metadata` (Block List, Max: 1) (see [below for nested schema](#nestedblock--metadata))
- `schedule` (String) Cron-like schedule for when the job should be triggered
Expand Down
13 changes: 12 additions & 1 deletion examples/resources/tsuru_job/resource.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
resource "tsuru_job" "my-job" {
resource "tsuru_job" "basic-job" {
name = "sample-job"
description = "job created with terraform"
plan = "c0.1m0.1"
team_owner = "admin"
pool = "staging"
schedule = "0 0 1 * *"
tags = ["tag1", "tag2"]
}


resource "tsuru_job" "full-featured-job" {
name = "sample-job"
description = "job created with terraform"
plan = "c0.1m0.1"
Expand Down
6 changes: 5 additions & 1 deletion internal/provider/resource_tsuru_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ func resourceTsuruJob() *schema.Resource {

"container": {
Type: schema.TypeList,
MinItems: 0,
MaxItems: 1,
Required: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"image": {
Expand Down Expand Up @@ -371,6 +372,9 @@ func jobContainerFromResourceData(meta interface{}) tsuru_client.InputJobContain
}

func flattenJobContainer(container tsuru.InputJobContainer) []interface{} {
if container.Image == "" && len(container.Command) == 0 {
return []interface{}{}
}

m := map[string]interface{}{
"image": container.Image,
Expand Down
27 changes: 8 additions & 19 deletions internal/provider/resource_tsuru_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/tsuru/go-tsuruclient/pkg/tsuru"
)

func TestAccResourceTsuruJob(t *testing.T) {
func TestAccResourceTsuruJobBasic(t *testing.T) {
fakeServer := echo.New()

iterationCount := 0
Expand All @@ -39,8 +39,8 @@ func TestAccResourceTsuruJob(t *testing.T) {
assert.Equal(t, "my-team", job.TeamOwner)
assert.Equal(t, "prod", job.Pool)
assert.Equal(t, "* * * * *", job.Schedule)
assert.Equal(t, []string{"sleep", "600"}, job.Container.Command)
assert.Equal(t, "tsuru/scratch:latest", job.Container.Image)
assert.Nil(t, job.Container.Command)
assert.Equal(t, "", job.Container.Image)

iterationCount++
return c.JSON(http.StatusOK, map[string]interface{}{
Expand All @@ -64,13 +64,6 @@ func TestAccResourceTsuruJob(t *testing.T) {
Pool: "prod",
Spec: tsuru.JobSpec{
Schedule: "* * * * *",
Container: tsuru.InputJobContainer{
Image: "tsuru/scratch:latest",
Command: []string{
"sleep",
"600",
},
},
},
}
return c.JSON(http.StatusOK, tsuru.JobInfo{Job: *job})
Expand Down Expand Up @@ -230,16 +223,12 @@ func TestAccResourceTsuruJobComplete(t *testing.T) {
func testAccResourceTsuruJob_basic() string {
return `
resource "tsuru_job" "job" {
name = "job01"
name = "job01"
description = "my job description"
plan = "c1m1"
team_owner = "my-team"
pool = "prod"
schedule = "* * * * *"
container {
image = "tsuru/scratch:latest"
command = ["sleep", 600]
}
plan = "c1m1"
team_owner = "my-team"
pool = "prod"
schedule = "* * * * *"
}
`
}
Expand Down