Skip to content

Commit 0e4a53d

Browse files
committed
feat(jobs): add local_storage_capacity to job_definition resource
The Scaleway Jobs API supports configuring local storage capacity for job definitions, but this option was not exposed in the Terraform provider. This change adds the local_storage_capacity attribute to allow users to specify local storage in MiB for their job containers.
1 parent 6900a12 commit 0e4a53d

File tree

6 files changed

+869
-6
lines changed

6 files changed

+869
-6
lines changed

docs/resources/job_definition.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The following arguments are supported:
6666

6767
- `cpu_limit` - (Required) The amount of vCPU computing resources to allocate to each container running the job.
6868
- `memory_limit` - (Required) The memory computing resources in MB to allocate to each container running the job.
69+
- `local_storage_capacity` - (Optional) The local storage capacity of the job in MiB.
6970
- `image_uri` - (Required) The uri of the container image that will be used for the job run.
7071
- `name` - (Optional) The name of the job.
7172
- `description` - (Optional) The description of the job

internal/services/jobs/action_start_job_definition_action_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ func TestAccActionJobDefinitionStart_Basic(t *testing.T) {
183183
{
184184
Config: `
185185
resource "scaleway_job_definition" "main" {
186-
name = "test-jobs-action-start"
187-
cpu_limit = 120
188-
memory_limit = 256
189-
image_uri = "docker.io/alpine:latest"
190-
command = "echo 'Hello World'"
186+
name = "test-jobs-action-start"
187+
cpu_limit = 120
188+
memory_limit = 256
189+
local_storage_capacity = 5120
190+
image_uri = "docker.io/alpine:latest"
191+
command = "echo 'Hello World'"
191192
192193
lifecycle {
193194
action_trigger {

internal/services/jobs/jobs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ func definitionSchema() map[string]*schema.Schema {
8484
},
8585
ValidateDiagFunc: validation.MapKeyLenBetween(0, 100),
8686
},
87+
"local_storage_capacity": {
88+
Type: schema.TypeInt,
89+
Description: "Local storage capacity of the job in MiB",
90+
Optional: true,
91+
},
8792
"cron": {
8893
Type: schema.TypeList,
8994
Description: "Cron expression",
@@ -190,6 +195,10 @@ func ResourceJobDefinitionCreate(ctx context.Context, d *schema.ResourceData, m
190195
req.JobTimeout = scw.NewDurationFromTimeDuration(duration)
191196
}
192197

198+
if localStorageCapacity, ok := d.GetOk("local_storage_capacity"); ok {
199+
req.LocalStorageCapacity = types.ExpandUint32Ptr(localStorageCapacity)
200+
}
201+
193202
definition, err := api.CreateJobDefinition(req, scw.WithContext(ctx))
194203
if err != nil {
195204
return diag.FromErr(err)
@@ -237,6 +246,7 @@ func ResourceJobDefinitionRead(ctx context.Context, d *schema.ResourceData, m an
237246
_ = d.Set("name", definition.Name)
238247
_ = d.Set("cpu_limit", int(definition.CPULimit))
239248
_ = d.Set("memory_limit", int(definition.MemoryLimit))
249+
_ = d.Set("local_storage_capacity", int(definition.LocalStorageCapacity))
240250
_ = d.Set("image_uri", definition.ImageURI)
241251
_ = d.Set("command", definition.Command)
242252
_ = d.Set("env", types.FlattenMap(definition.EnvironmentVariables))
@@ -273,6 +283,10 @@ func ResourceJobDefinitionUpdate(ctx context.Context, d *schema.ResourceData, m
273283
req.MemoryLimit = types.ExpandUint32Ptr(d.Get("memory_limit"))
274284
}
275285

286+
if d.HasChange("local_storage_capacity") {
287+
req.LocalStorageCapacity = types.ExpandUint32Ptr(d.Get("local_storage_capacity"))
288+
}
289+
276290
if d.HasChange("image_uri") {
277291
req.ImageURI = types.ExpandUpdatedStringPtr(d.Get("image_uri"))
278292
}

internal/services/jobs/jobs_test.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestAccJobDefinition_Basic(t *testing.T) {
3131
name = "test-jobs-job-definition-basic"
3232
cpu_limit = 120
3333
memory_limit = 256
34+
local_storage_capacity = 5120
3435
image_uri = "docker.io/alpine:latest"
3536
}
3637
`,
@@ -58,6 +59,7 @@ func TestAccJobDefinition_Timeout(t *testing.T) {
5859
name = "test-jobs-job-definition-timeout"
5960
cpu_limit = 120
6061
memory_limit = 256
62+
local_storage_capacity = 5120
6163
image_uri = "docker.io/alpine:latest"
6264
timeout = "20m"
6365
}
@@ -75,6 +77,7 @@ func TestAccJobDefinition_Timeout(t *testing.T) {
7577
name = "test-jobs-job-definition-timeout"
7678
cpu_limit = 120
7779
memory_limit = 256
80+
local_storage_capacity = 5120
7881
image_uri = "docker.io/alpine:latest"
7982
timeout = "1h30m"
8083
}
@@ -90,6 +93,52 @@ func TestAccJobDefinition_Timeout(t *testing.T) {
9093
})
9194
}
9295

96+
func TestAccJobDefinition_LocalStorageCapacity(t *testing.T) {
97+
tt := acctest.NewTestTools(t)
98+
defer tt.Cleanup()
99+
100+
resource.ParallelTest(t, resource.TestCase{
101+
ProtoV6ProviderFactories: tt.ProviderFactories,
102+
CheckDestroy: testAccCheckJobDefinitionDestroy(tt),
103+
Steps: []resource.TestStep{
104+
{
105+
Config: `
106+
resource scaleway_job_definition main {
107+
name = "test-jobs-job-definition-local-storage"
108+
cpu_limit = 120
109+
memory_limit = 256
110+
image_uri = "docker.io/alpine:latest"
111+
local_storage_capacity = 1000
112+
}
113+
`,
114+
Check: resource.ComposeTestCheckFunc(
115+
testAccCheckJobDefinitionExists(tt, "scaleway_job_definition.main"),
116+
acctest.CheckResourceAttrUUID("scaleway_job_definition.main", "id"),
117+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "name", "test-jobs-job-definition-local-storage"),
118+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "local_storage_capacity", "1000"),
119+
),
120+
},
121+
{
122+
Config: `
123+
resource scaleway_job_definition main {
124+
name = "test-jobs-job-definition-local-storage"
125+
cpu_limit = 120
126+
memory_limit = 256
127+
image_uri = "docker.io/alpine:latest"
128+
local_storage_capacity = 2000
129+
}
130+
`,
131+
Check: resource.ComposeTestCheckFunc(
132+
testAccCheckJobDefinitionExists(tt, "scaleway_job_definition.main"),
133+
acctest.CheckResourceAttrUUID("scaleway_job_definition.main", "id"),
134+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "name", "test-jobs-job-definition-local-storage"),
135+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "local_storage_capacity", "2000"),
136+
),
137+
},
138+
},
139+
})
140+
}
141+
93142
func TestAccJobDefinition_Cron(t *testing.T) {
94143
tt := acctest.NewTestTools(t)
95144
defer tt.Cleanup()
@@ -104,6 +153,7 @@ func TestAccJobDefinition_Cron(t *testing.T) {
104153
name = "test-jobs-job-definition-cron"
105154
cpu_limit = 120
106155
memory_limit = 256
156+
local_storage_capacity = 5120
107157
image_uri = "docker.io/alpine:latest"
108158
cron {
109159
schedule = "5 4 1 * *"
@@ -126,6 +176,7 @@ func TestAccJobDefinition_Cron(t *testing.T) {
126176
name = "test-jobs-job-definition-cron"
127177
cpu_limit = 120
128178
memory_limit = 256
179+
local_storage_capacity = 5120
129180
image_uri = "docker.io/alpine:latest"
130181
cron {
131182
schedule = "5 5 * * *"
@@ -148,6 +199,7 @@ func TestAccJobDefinition_Cron(t *testing.T) {
148199
name = "test-jobs-job-definition-cron"
149200
cpu_limit = 120
150201
memory_limit = 256
202+
local_storage_capacity = 5120
151203
image_uri = "docker.io/alpine:latest"
152204
}
153205
`,
@@ -185,6 +237,7 @@ func TestAccJobDefinition_SecretReference(t *testing.T) {
185237
name = "test-jobs-job-definition-secret"
186238
cpu_limit = 120
187239
memory_limit = 256
240+
local_storage_capacity = 5120
188241
image_uri = "docker.io/alpine:latest"
189242
secret_reference {
190243
secret_id = scaleway_secret.main.id
@@ -222,6 +275,7 @@ func TestAccJobDefinition_SecretReference(t *testing.T) {
222275
name = "test-jobs-job-definition-secret"
223276
cpu_limit = 120
224277
memory_limit = 256
278+
local_storage_capacity = 5120
225279
image_uri = "docker.io/alpine:latest"
226280
secret_reference {
227281
secret_id = split("/", scaleway_secret.main.id)[1]
@@ -260,6 +314,7 @@ func TestAccJobDefinition_SecretReference(t *testing.T) {
260314
name = "test-jobs-job-definition-secret"
261315
cpu_limit = 120
262316
memory_limit = 256
317+
local_storage_capacity = 5120
263318
image_uri = "docker.io/alpine:latest"
264319
secret_reference {
265320
secret_id = scaleway_secret.main.id
@@ -302,6 +357,7 @@ func TestAccJobDefinition_WrongSecretReference(t *testing.T) {
302357
name = "test-jobs-job-definition-secret"
303358
cpu_limit = 120
304359
memory_limit = 256
360+
local_storage_capacity = 5120
305361
image_uri = "docker.io/alpine:latest"
306362
secret_reference {
307363
secret_id = scaleway_secret.main.id
@@ -319,11 +375,12 @@ func TestAccJobDefinition_WrongSecretReference(t *testing.T) {
319375
secret_id = scaleway_secret.main.id
320376
data = "your_secret"
321377
}
322-
378+
323379
resource scaleway_job_definition main {
324380
name = "test-jobs-job-definition-secret"
325381
cpu_limit = 120
326382
memory_limit = 256
383+
local_storage_capacity = 5120
327384
image_uri = "docker.io/alpine:latest"
328385
secret_reference {
329386
secret_id = scaleway_secret.main.id

0 commit comments

Comments
 (0)