Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/resources/job_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The following arguments are supported:

- `cpu_limit` - (Required) The amount of vCPU computing resources to allocate to each container running the job.
- `memory_limit` - (Required) The memory computing resources in MB to allocate to each container running the job.
- `local_storage_capacity` - (Optional) The local storage capacity of the job in MiB.
- `image_uri` - (Required) The uri of the container image that will be used for the job run.
- `name` - (Optional) The name of the job.
- `description` - (Optional) The description of the job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ func TestAccActionJobDefinitionStart_Basic(t *testing.T) {
{
Config: `
resource "scaleway_job_definition" "main" {
name = "test-jobs-action-start"
cpu_limit = 120
memory_limit = 256
image_uri = "docker.io/alpine:latest"
command = "echo 'Hello World'"
name = "test-jobs-action-start"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
command = "echo 'Hello World'"

lifecycle {
action_trigger {
Expand Down
14 changes: 14 additions & 0 deletions internal/services/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func definitionSchema() map[string]*schema.Schema {
},
ValidateDiagFunc: validation.MapKeyLenBetween(0, 100),
},
"local_storage_capacity": {
Type: schema.TypeInt,
Description: "Local storage capacity of the job in MiB",
Optional: true,
},
"cron": {
Type: schema.TypeList,
Description: "Cron expression",
Expand Down Expand Up @@ -191,6 +196,10 @@ func ResourceJobDefinitionCreate(ctx context.Context, d *schema.ResourceData, m
req.JobTimeout = scw.NewDurationFromTimeDuration(duration)
}

if localStorageCapacity, ok := d.GetOk("local_storage_capacity"); ok {
req.LocalStorageCapacity = types.ExpandUint32Ptr(localStorageCapacity)
}

definition, err := api.CreateJobDefinition(req, scw.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -238,6 +247,7 @@ func ResourceJobDefinitionRead(ctx context.Context, d *schema.ResourceData, m an
_ = d.Set("name", definition.Name)
_ = d.Set("cpu_limit", int(definition.CPULimit))
_ = d.Set("memory_limit", int(definition.MemoryLimit))
_ = d.Set("local_storage_capacity", int(definition.LocalStorageCapacity))
_ = d.Set("image_uri", definition.ImageURI)
_ = d.Set("command", definition.Command)
_ = d.Set("env", types.FlattenMap(definition.EnvironmentVariables))
Expand Down Expand Up @@ -274,6 +284,10 @@ func ResourceJobDefinitionUpdate(ctx context.Context, d *schema.ResourceData, m
req.MemoryLimit = types.ExpandUint32Ptr(d.Get("memory_limit"))
}

if d.HasChange("local_storage_capacity") {
req.LocalStorageCapacity = types.ExpandUint32Ptr(d.Get("local_storage_capacity"))
}

if d.HasChange("image_uri") {
req.ImageURI = types.ExpandUpdatedStringPtr(d.Get("image_uri"))
}
Expand Down
59 changes: 58 additions & 1 deletion internal/services/jobs/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccJobDefinition_Basic(t *testing.T) {
name = "test-jobs-job-definition-basic"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
}
`,
Expand Down Expand Up @@ -58,6 +59,7 @@ func TestAccJobDefinition_Timeout(t *testing.T) {
name = "test-jobs-job-definition-timeout"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
timeout = "20m"
}
Expand All @@ -75,6 +77,7 @@ func TestAccJobDefinition_Timeout(t *testing.T) {
name = "test-jobs-job-definition-timeout"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
timeout = "1h30m"
}
Expand All @@ -90,6 +93,52 @@ func TestAccJobDefinition_Timeout(t *testing.T) {
})
}

func TestAccJobDefinition_LocalStorageCapacity(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()

resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: tt.ProviderFactories,
CheckDestroy: testAccCheckJobDefinitionDestroy(tt),
Steps: []resource.TestStep{
{
Config: `
resource scaleway_job_definition main {
name = "test-jobs-job-definition-local-storage"
cpu_limit = 120
memory_limit = 256
image_uri = "docker.io/alpine:latest"
local_storage_capacity = 1000
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckJobDefinitionExists(tt, "scaleway_job_definition.main"),
acctest.CheckResourceAttrUUID("scaleway_job_definition.main", "id"),
resource.TestCheckResourceAttr("scaleway_job_definition.main", "name", "test-jobs-job-definition-local-storage"),
resource.TestCheckResourceAttr("scaleway_job_definition.main", "local_storage_capacity", "1000"),
),
},
{
Config: `
resource scaleway_job_definition main {
name = "test-jobs-job-definition-local-storage"
cpu_limit = 120
memory_limit = 256
image_uri = "docker.io/alpine:latest"
local_storage_capacity = 2000
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckJobDefinitionExists(tt, "scaleway_job_definition.main"),
acctest.CheckResourceAttrUUID("scaleway_job_definition.main", "id"),
resource.TestCheckResourceAttr("scaleway_job_definition.main", "name", "test-jobs-job-definition-local-storage"),
resource.TestCheckResourceAttr("scaleway_job_definition.main", "local_storage_capacity", "2000"),
),
},
},
})
}

func TestAccJobDefinition_Cron(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
Expand All @@ -104,6 +153,7 @@ func TestAccJobDefinition_Cron(t *testing.T) {
name = "test-jobs-job-definition-cron"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
cron {
schedule = "5 4 1 * *"
Expand All @@ -126,6 +176,7 @@ func TestAccJobDefinition_Cron(t *testing.T) {
name = "test-jobs-job-definition-cron"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
cron {
schedule = "5 5 * * *"
Expand All @@ -148,6 +199,7 @@ func TestAccJobDefinition_Cron(t *testing.T) {
name = "test-jobs-job-definition-cron"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
}
`,
Expand Down Expand Up @@ -185,6 +237,7 @@ func TestAccJobDefinition_SecretReference(t *testing.T) {
name = "test-jobs-job-definition-secret"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
secret_reference {
secret_id = scaleway_secret.main.id
Expand Down Expand Up @@ -222,6 +275,7 @@ func TestAccJobDefinition_SecretReference(t *testing.T) {
name = "test-jobs-job-definition-secret"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
secret_reference {
secret_id = split("/", scaleway_secret.main.id)[1]
Expand Down Expand Up @@ -260,6 +314,7 @@ func TestAccJobDefinition_SecretReference(t *testing.T) {
name = "test-jobs-job-definition-secret"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
secret_reference {
secret_id = scaleway_secret.main.id
Expand Down Expand Up @@ -302,6 +357,7 @@ func TestAccJobDefinition_WrongSecretReference(t *testing.T) {
name = "test-jobs-job-definition-secret"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
secret_reference {
secret_id = scaleway_secret.main.id
Expand All @@ -319,11 +375,12 @@ func TestAccJobDefinition_WrongSecretReference(t *testing.T) {
secret_id = scaleway_secret.main.id
data = "your_secret"
}

resource scaleway_job_definition main {
name = "test-jobs-job-definition-secret"
cpu_limit = 120
memory_limit = 256
local_storage_capacity = 5120
image_uri = "docker.io/alpine:latest"
secret_reference {
secret_id = scaleway_secret.main.id
Expand Down
Loading
Loading