Skip to content

Commit ed7af2e

Browse files
authored
feat(serverless): add http_option attribute (#1678)
1 parent 7f8e180 commit ed7af2e

28 files changed

+13351
-4161
lines changed

scaleway/helpers_container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ func setCreateContainerRequest(d *schema.ResourceData, region scw.Region) (*cont
4848
name := expandOrGenerateString(nameRaw.(string), "co")
4949
privacyType := d.Get("privacy")
5050
protocol := d.Get("protocol")
51+
httpOption := d.Get("http_option")
5152

5253
req := &container.CreateContainerRequest{
5354
Region: region,
5455
NamespaceID: expandID(namespaceID),
5556
Name: name,
5657
Privacy: container.ContainerPrivacy(privacyType.(string)),
5758
Protocol: container.ContainerProtocol(*expandStringPtr(protocol)),
59+
HTTPOption: container.ContainerHTTPOption(httpOption.(string)),
5860
}
5961

6062
// optional

scaleway/resource_container.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ func resourceScalewayContainer() *schema.Resource {
157157
Description: "This allows you to control your production environment",
158158
Default: false,
159159
},
160+
"http_option": {
161+
Type: schema.TypeString,
162+
Optional: true,
163+
Description: "HTTP traffic configuration",
164+
Default: container.ContainerHTTPOptionEnabled.String(),
165+
ValidateFunc: validation.StringInSlice([]string{
166+
container.ContainerHTTPOptionEnabled.String(),
167+
container.ContainerHTTPOptionRedirected.String(),
168+
}, false),
169+
},
160170
// computed
161171
"status": {
162172
Type: schema.TypeString,
@@ -268,6 +278,7 @@ func resourceScalewayContainerRead(ctx context.Context, d *schema.ResourceData,
268278
_ = d.Set("cron_status", co.Status.String())
269279
_ = d.Set("port", int(co.Port))
270280
_ = d.Set("deploy", scw.BoolPtr(*expandBoolPtr(d.Get("deploy"))))
281+
_ = d.Set("http_option", co.HTTPOption)
271282
_ = d.Set("region", co.Region.String())
272283

273284
return nil
@@ -347,6 +358,10 @@ func resourceScalewayContainerUpdate(ctx context.Context, d *schema.ResourceData
347358
req.Port = scw.Uint32Ptr(uint32(d.Get("port").(int)))
348359
}
349360

361+
if d.HasChanges("http_option") {
362+
req.HTTPOption = container.ContainerHTTPOption(d.Get("http_option").(string))
363+
}
364+
350365
if d.HasChanges("deploy") {
351366
req.Redeploy = expandBoolPtr(d.Get("deploy"))
352367
}

scaleway/resource_container_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,62 @@ func TestAccScalewayContainer_WithIMG(t *testing.T) {
315315
})
316316
}
317317

318+
func TestAccScalewayContainer_HTTPOption(t *testing.T) {
319+
tt := NewTestTools(t)
320+
defer tt.Cleanup()
321+
resource.ParallelTest(t, resource.TestCase{
322+
PreCheck: func() { testAccPreCheck(t) },
323+
ProviderFactories: tt.ProviderFactories,
324+
CheckDestroy: testAccCheckScalewayContainerDestroy(tt),
325+
Steps: []resource.TestStep{
326+
{
327+
Config: `
328+
resource scaleway_container_namespace main {}
329+
330+
resource scaleway_container main {
331+
namespace_id = scaleway_container_namespace.main.id
332+
deploy = false
333+
http_option = "enabled"
334+
}
335+
`,
336+
Check: resource.ComposeTestCheckFunc(
337+
testAccCheckScalewayContainerExists(tt, "scaleway_container.main"),
338+
resource.TestCheckResourceAttr("scaleway_container.main", "http_option", container.ContainerHTTPOptionEnabled.String()),
339+
),
340+
},
341+
{
342+
Config: `
343+
resource scaleway_container_namespace main {}
344+
345+
resource scaleway_container main {
346+
namespace_id = scaleway_container_namespace.main.id
347+
deploy = false
348+
http_option = "redirected"
349+
}
350+
`,
351+
Check: resource.ComposeTestCheckFunc(
352+
testAccCheckScalewayContainerExists(tt, "scaleway_container.main"),
353+
resource.TestCheckResourceAttr("scaleway_container.main", "http_option", container.ContainerHTTPOptionRedirected.String()),
354+
),
355+
},
356+
{
357+
Config: `
358+
resource scaleway_container_namespace main {}
359+
360+
resource scaleway_container main {
361+
namespace_id = scaleway_container_namespace.main.id
362+
deploy = false
363+
}
364+
`,
365+
Check: resource.ComposeTestCheckFunc(
366+
testAccCheckScalewayContainerExists(tt, "scaleway_container.main"),
367+
resource.TestCheckResourceAttr("scaleway_container.main", "http_option", container.ContainerHTTPOptionEnabled.String()),
368+
),
369+
},
370+
},
371+
})
372+
}
373+
318374
func testAccCheckScalewayContainerExists(tt *TestTools, n string) resource.TestCheckFunc {
319375
return func(state *terraform.State) error {
320376
rs, ok := state.RootModule().Resources[n]

scaleway/resource_container_token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestAccScalewayContainerToken_Basic(t *testing.T) {
1515
defer tt.Cleanup()
1616
expiresAt := time.Now().Add(time.Hour * 24).Format(time.RFC3339)
1717
if !*UpdateCassettes {
18-
expiresAt = "2022-10-18T11:35:15+02:00"
18+
expiresAt = "2023-01-05T13:12:46Z"
1919
}
2020

2121
resource.ParallelTest(t, resource.TestCase{

scaleway/resource_function.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ func resourceScalewayFunction() *schema.Resource {
131131
Optional: true,
132132
Description: "Define if the function should be deployed, terraform will wait for function to be deployed",
133133
},
134+
"http_option": {
135+
Type: schema.TypeString,
136+
Optional: true,
137+
Description: "HTTP traffic configuration",
138+
Default: function.FunctionHTTPOptionEnabled.String(),
139+
ValidateFunc: validation.StringInSlice([]string{
140+
function.FunctionHTTPOptionEnabled.String(),
141+
function.FunctionHTTPOptionRedirected.String(),
142+
}, false),
143+
},
134144
"cpu_limit": {
135145
Type: schema.TypeInt,
136146
Computed: true,
@@ -172,6 +182,7 @@ func resourceScalewayFunctionCreate(ctx context.Context, d *schema.ResourceData,
172182
Privacy: function.FunctionPrivacy(d.Get("privacy").(string)),
173183
Region: region,
174184
Runtime: function.FunctionRuntime(d.Get("runtime").(string)),
185+
HTTPOption: function.FunctionHTTPOption(d.Get("http_option").(string)),
175186
}
176187

177188
if timeout, ok := d.GetOk("timeout"); ok {
@@ -280,6 +291,7 @@ func resourceScalewayFunctionRead(ctx context.Context, d *schema.ResourceData, m
280291
_ = d.Set("region", f.Region.String())
281292
_ = d.Set("timeout", f.Timeout.Seconds)
282293
_ = d.Set("domain_name", f.DomainName)
294+
_ = d.Set("http_option", f.HTTPOption)
283295

284296
return diags
285297
}
@@ -344,6 +356,11 @@ func resourceScalewayFunctionUpdate(ctx context.Context, d *schema.ResourceData,
344356
updated = true
345357
}
346358

359+
if d.HasChange("http_option") {
360+
req.HTTPOption = function.FunctionHTTPOption(d.Get("http_option").(string))
361+
updated = true
362+
}
363+
347364
if updated {
348365
_, err = api.UpdateFunction(req, scw.WithContext(ctx))
349366
if err != nil {

scaleway/resource_function_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,72 @@ func TestAccScalewayFunction_Deploy(t *testing.T) {
285285
})
286286
}
287287

288+
func TestAccScalewayFunction_HTTPOption(t *testing.T) {
289+
tt := NewTestTools(t)
290+
defer tt.Cleanup()
291+
292+
resource.ParallelTest(t, resource.TestCase{
293+
PreCheck: func() { testAccPreCheck(t) },
294+
ProviderFactories: tt.ProviderFactories,
295+
CheckDestroy: testAccCheckScalewayFunctionDestroy(tt),
296+
Steps: []resource.TestStep{
297+
{
298+
Config: `
299+
resource scaleway_function_namespace main {}
300+
301+
resource scaleway_function main {
302+
name = "foobar"
303+
namespace_id = scaleway_function_namespace.main.id
304+
runtime = "node14"
305+
privacy = "private"
306+
handler = "handler.handle"
307+
http_option = "enabled"
308+
}
309+
`,
310+
Check: resource.ComposeTestCheckFunc(
311+
testAccCheckScalewayFunctionExists(tt, "scaleway_function.main"),
312+
resource.TestCheckResourceAttr("scaleway_function.main", "http_option", function.FunctionHTTPOptionEnabled.String()),
313+
),
314+
},
315+
{
316+
Config: `
317+
resource scaleway_function_namespace main {}
318+
319+
resource scaleway_function main {
320+
name = "foobar"
321+
namespace_id = scaleway_function_namespace.main.id
322+
runtime = "node14"
323+
privacy = "private"
324+
handler = "handler.handle"
325+
http_option = "redirected"
326+
}
327+
`,
328+
Check: resource.ComposeTestCheckFunc(
329+
testAccCheckScalewayFunctionExists(tt, "scaleway_function.main"),
330+
resource.TestCheckResourceAttr("scaleway_function.main", "http_option", function.FunctionHTTPOptionRedirected.String()),
331+
),
332+
},
333+
{
334+
Config: `
335+
resource scaleway_function_namespace main {}
336+
337+
resource scaleway_function main {
338+
name = "foobar"
339+
namespace_id = scaleway_function_namespace.main.id
340+
runtime = "node14"
341+
privacy = "private"
342+
handler = "handler.handle"
343+
}
344+
`,
345+
Check: resource.ComposeTestCheckFunc(
346+
testAccCheckScalewayFunctionExists(tt, "scaleway_function.main"),
347+
resource.TestCheckResourceAttr("scaleway_function.main", "http_option", function.FunctionHTTPOptionEnabled.String()),
348+
),
349+
},
350+
},
351+
})
352+
}
353+
288354
func testAccCheckScalewayFunctionExists(tt *TestTools, n string) resource.TestCheckFunc {
289355
return func(state *terraform.State) error {
290356
rs, ok := state.RootModule().Resources[n]

scaleway/resource_function_token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestAccScalewayFunctionToken_Basic(t *testing.T) {
1515
defer tt.Cleanup()
1616
expiresAt := time.Now().Add(time.Hour * 24).Format(time.RFC3339)
1717
if !*UpdateCassettes {
18-
expiresAt = "2022-10-18T14:04:37+02:00"
18+
expiresAt = "2023-01-05T12:53:11Z"
1919
}
2020

2121
resource.ParallelTest(t, resource.TestCase{

0 commit comments

Comments
 (0)