Skip to content

Commit 330917c

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 c9cdc2d commit 330917c

File tree

5 files changed

+851
-0
lines changed

5 files changed

+851
-0
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/jobs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func ResourceDefinition() *schema.Resource {
5252
Description: "Memory limit of the job",
5353
Required: true,
5454
},
55+
"local_storage_capacity": {
56+
Type: schema.TypeInt,
57+
Description: "Local storage capacity of the job in MiB",
58+
Optional: true,
59+
},
5560
"image_uri": {
5661
Type: schema.TypeString,
5762
Description: "Image URI to use for the job",
@@ -187,6 +192,10 @@ func ResourceJobDefinitionCreate(ctx context.Context, d *schema.ResourceData, m
187192
req.JobTimeout = scw.NewDurationFromTimeDuration(duration)
188193
}
189194

195+
if localStorageCapacity, ok := d.GetOk("local_storage_capacity"); ok {
196+
req.LocalStorageCapacity = types.ExpandUint32Ptr(localStorageCapacity)
197+
}
198+
190199
definition, err := api.CreateJobDefinition(req, scw.WithContext(ctx))
191200
if err != nil {
192201
return diag.FromErr(err)
@@ -234,6 +243,7 @@ func ResourceJobDefinitionRead(ctx context.Context, d *schema.ResourceData, m an
234243
_ = d.Set("name", definition.Name)
235244
_ = d.Set("cpu_limit", int(definition.CPULimit))
236245
_ = d.Set("memory_limit", int(definition.MemoryLimit))
246+
_ = d.Set("local_storage_capacity", int(definition.LocalStorageCapacity))
237247
_ = d.Set("image_uri", definition.ImageURI)
238248
_ = d.Set("command", definition.Command)
239249
_ = d.Set("env", types.FlattenMap(definition.EnvironmentVariables))
@@ -270,6 +280,10 @@ func ResourceJobDefinitionUpdate(ctx context.Context, d *schema.ResourceData, m
270280
req.MemoryLimit = types.ExpandUint32Ptr(d.Get("memory_limit"))
271281
}
272282

283+
if d.HasChange("local_storage_capacity") {
284+
req.LocalStorageCapacity = types.ExpandUint32Ptr(d.Get("local_storage_capacity"))
285+
}
286+
273287
if d.HasChange("image_uri") {
274288
req.ImageURI = types.ExpandUpdatedStringPtr(d.Get("image_uri"))
275289
}

internal/services/jobs/jobs_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,52 @@ func TestAccJobDefinition_Timeout(t *testing.T) {
9090
})
9191
}
9292

93+
func TestAccJobDefinition_LocalStorageCapacity(t *testing.T) {
94+
tt := acctest.NewTestTools(t)
95+
defer tt.Cleanup()
96+
97+
resource.ParallelTest(t, resource.TestCase{
98+
ProtoV6ProviderFactories: tt.ProviderFactories,
99+
CheckDestroy: testAccCheckJobDefinitionDestroy(tt),
100+
Steps: []resource.TestStep{
101+
{
102+
Config: `
103+
resource scaleway_job_definition main {
104+
name = "test-jobs-job-definition-local-storage"
105+
cpu_limit = 120
106+
memory_limit = 256
107+
image_uri = "docker.io/alpine:latest"
108+
local_storage_capacity = 1000
109+
}
110+
`,
111+
Check: resource.ComposeTestCheckFunc(
112+
testAccCheckJobDefinitionExists(tt, "scaleway_job_definition.main"),
113+
acctest.CheckResourceAttrUUID("scaleway_job_definition.main", "id"),
114+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "name", "test-jobs-job-definition-local-storage"),
115+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "local_storage_capacity", "1000"),
116+
),
117+
},
118+
{
119+
Config: `
120+
resource scaleway_job_definition main {
121+
name = "test-jobs-job-definition-local-storage"
122+
cpu_limit = 120
123+
memory_limit = 256
124+
image_uri = "docker.io/alpine:latest"
125+
local_storage_capacity = 2000
126+
}
127+
`,
128+
Check: resource.ComposeTestCheckFunc(
129+
testAccCheckJobDefinitionExists(tt, "scaleway_job_definition.main"),
130+
acctest.CheckResourceAttrUUID("scaleway_job_definition.main", "id"),
131+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "name", "test-jobs-job-definition-local-storage"),
132+
resource.TestCheckResourceAttr("scaleway_job_definition.main", "local_storage_capacity", "2000"),
133+
),
134+
},
135+
},
136+
})
137+
}
138+
93139
func TestAccJobDefinition_Cron(t *testing.T) {
94140
tt := acctest.NewTestTools(t)
95141
defer tt.Cleanup()

0 commit comments

Comments
 (0)