Skip to content

Commit 113b986

Browse files
authored
feat(lb): add ssl compatibility (#1439)
1 parent adb82ac commit 113b986

File tree

7 files changed

+4176
-2891
lines changed

7 files changed

+4176
-2891
lines changed

docs/resources/lb.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ The following arguments are supported:
110110

111111
- `name` - (Optional) The name of the load-balancer.
112112

113+
- `description` - (Optional) The description of the load-balancer.
114+
113115
- `tags` - (Optional) The tags associated with the load-balancers.
114116

115117
- `release_ip` - (Defaults to false) The release_ip allow release the ip address associated with the load-balancers.
116118

119+
- `ssl_compatibility_level` - (Optional) Enforces minimal SSL version (in SSL/TLS offloading context). Please check [possible values](https://developers.scaleway.com/en/products/lb/zoned_api/#ssl-compatibility-level-442f99).
120+
117121
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
118122

119123
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the load-balancer is associated with.

scaleway/resource_lb.go

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func resourceScalewayLb() *schema.Resource {
4545
Computed: true,
4646
Description: "Name of the lb",
4747
},
48+
"description": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
Description: "The description of the lb",
52+
},
4853
"type": {
4954
Type: schema.TypeString,
5055
Required: true,
@@ -115,6 +120,18 @@ func resourceScalewayLb() *schema.Resource {
115120
},
116121
},
117122
},
123+
"ssl_compatibility_level": {
124+
Type: schema.TypeString,
125+
Optional: true,
126+
Description: "Enforces minimal SSL version (in SSL/TLS offloading context)",
127+
Default: lbSDK.SSLCompatibilityLevelSslCompatibilityLevelIntermediate.String(),
128+
ValidateFunc: validation.StringInSlice([]string{
129+
lbSDK.SSLCompatibilityLevelSslCompatibilityLevelUnknown.String(),
130+
lbSDK.SSLCompatibilityLevelSslCompatibilityLevelIntermediate.String(),
131+
lbSDK.SSLCompatibilityLevelSslCompatibilityLevelModern.String(),
132+
lbSDK.SSLCompatibilityLevelSslCompatibilityLevelOld.String(),
133+
}, false),
134+
},
118135
"region": regionComputedSchema(),
119136
"zone": zoneSchema(),
120137
"organization_id": organizationIDSchema(),
@@ -130,11 +147,13 @@ func resourceScalewayLbCreate(ctx context.Context, d *schema.ResourceData, meta
130147
}
131148

132149
createReq := &lbSDK.ZonedAPICreateLBRequest{
133-
Zone: zone,
134-
IPID: expandStringPtr(expandID(d.Get("ip_id"))),
135-
ProjectID: expandStringPtr(d.Get("project_id")),
136-
Name: expandOrGenerateString(d.Get("name"), "lb"),
137-
Type: d.Get("type").(string),
150+
Zone: zone,
151+
IPID: expandStringPtr(expandID(d.Get("ip_id"))),
152+
ProjectID: expandStringPtr(d.Get("project_id")),
153+
Name: expandOrGenerateString(d.Get("name"), "lb"),
154+
Description: d.Get("description").(string),
155+
Type: d.Get("type").(string),
156+
SslCompatibilityLevel: lbSDK.SSLCompatibilityLevel(*expandStringPtr(d.Get("ssl_compatibility_level"))),
138157
}
139158

140159
if raw, ok := d.GetOk("tags"); ok {
@@ -199,6 +218,7 @@ func resourceScalewayLbRead(ctx context.Context, d *schema.ResourceData, meta in
199218

200219
_ = d.Set("release_ip", false)
201220
_ = d.Set("name", lb.Name)
221+
_ = d.Set("description", lb.Description)
202222
_ = d.Set("zone", lb.Zone.String())
203223
_ = d.Set("region", region.String())
204224
_ = d.Set("organization_id", lb.OrganizationID)
@@ -208,6 +228,7 @@ func resourceScalewayLbRead(ctx context.Context, d *schema.ResourceData, meta in
208228
_ = d.Set("type", strings.ToUpper(lb.Type))
209229
_ = d.Set("ip_id", newZonedIDString(zone, lb.IP[0].ID))
210230
_ = d.Set("ip_address", lb.IP[0].IPAddress)
231+
_ = d.Set("ssl_compatibility_level", lb.SslCompatibilityLevel.String())
211232

212233
// retrieve attached private networks
213234
privateNetworks, err := waitForLBPN(ctx, lbAPI, zone, ID, d.Timeout(schema.TimeoutRead))
@@ -229,6 +250,41 @@ func resourceScalewayLbUpdate(ctx context.Context, d *schema.ResourceData, meta
229250
return diag.FromErr(err)
230251
}
231252

253+
req := &lbSDK.ZonedAPIUpdateLBRequest{
254+
Zone: zone,
255+
LBID: ID,
256+
}
257+
258+
hasChanged := false
259+
260+
if d.HasChanges("name", "tags") {
261+
req.Name = d.Get("name").(string)
262+
req.Tags = expandStrings(d.Get("tags"))
263+
hasChanged = true
264+
}
265+
266+
if d.HasChange("description") {
267+
req.Description = d.Get("description").(string)
268+
hasChanged = true
269+
}
270+
271+
if d.HasChange("ssl_compatibility_level") {
272+
req.SslCompatibilityLevel = lbSDK.SSLCompatibilityLevel(*expandStringPtr(d.Get("ssl_compatibility_level")))
273+
hasChanged = true
274+
}
275+
276+
if hasChanged {
277+
_, err = lbAPI.UpdateLB(req, scw.WithContext(ctx))
278+
if err != nil && !is404Error(err) {
279+
return diag.FromErr(err)
280+
}
281+
282+
_, err = waitForLB(ctx, lbAPI, zone, ID, d.Timeout(schema.TimeoutUpdate))
283+
if err != nil && !is404Error(err) {
284+
return diag.FromErr(err)
285+
}
286+
}
287+
232288
if d.HasChange("type") {
233289
lbType := d.Get("type").(string)
234290
migrateReq := &lbSDK.ZonedAPIMigrateLBRequest{
@@ -248,28 +304,16 @@ func resourceScalewayLbUpdate(ctx context.Context, d *schema.ResourceData, meta
248304
}
249305
}
250306

251-
if d.HasChanges("name", "tags") {
252-
req := &lbSDK.ZonedAPIUpdateLBRequest{
253-
Zone: zone,
254-
LBID: ID,
255-
Name: d.Get("name").(string),
256-
Tags: expandStrings(d.Get("tags")),
257-
}
258-
259-
_, err = waitForLB(ctx, lbAPI, zone, ID, d.Timeout(schema.TimeoutUpdate))
260-
if err != nil && !is404Error(err) {
261-
return diag.FromErr(err)
262-
}
263-
264-
_, err = lbAPI.UpdateLB(req, scw.WithContext(ctx))
265-
if err != nil && !is404Error(err) {
266-
return diag.FromErr(err)
267-
}
268-
}
269307
////
270308
// Attach / Detach Private Networks
271309
////
272310
if d.HasChange("private_network") {
311+
// check current lb stability state
312+
_, err = waitForLB(ctx, lbAPI, zone, ID, d.Timeout(schema.TimeoutUpdate))
313+
if err != nil {
314+
return diag.FromErr(err)
315+
}
316+
273317
// check that pns are in a stable state
274318
pns, err := waitForLBPN(ctx, lbAPI, zone, ID, d.Timeout(schema.TimeoutUpdate))
275319
if err != nil && !is404Error(err) {

scaleway/resource_lb_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,64 @@ func testSweepLB(_ string) error {
6161
})
6262
}
6363

64+
func TestAccScalewayLbLb_Basic(t *testing.T) {
65+
tt := NewTestTools(t)
66+
defer tt.Cleanup()
67+
resource.ParallelTest(t, resource.TestCase{
68+
PreCheck: func() { testAccPreCheck(t) },
69+
ProviderFactories: tt.ProviderFactories,
70+
CheckDestroy: testAccCheckScalewayLbDestroy(tt),
71+
Steps: []resource.TestStep{
72+
{
73+
Config: `
74+
resource scaleway_lb_ip main {
75+
}
76+
77+
resource scaleway_lb main {
78+
ip_id = scaleway_lb_ip.main.id
79+
name = "test-lb-basic"
80+
description = "a description"
81+
type = "LB-S"
82+
tags = ["basic"]
83+
}
84+
`,
85+
Check: resource.ComposeTestCheckFunc(
86+
testAccCheckScalewayLbExists(tt, "scaleway_lb.main"),
87+
testCheckResourceAttrUUID("scaleway_lb.main", "id"),
88+
resource.TestCheckResourceAttr("scaleway_lb.main", "name", "test-lb-basic"),
89+
resource.TestCheckResourceAttr("scaleway_lb.main", "type", "LB-S"),
90+
resource.TestCheckResourceAttr("scaleway_lb.main", "tags.#", "1"),
91+
resource.TestCheckResourceAttr("scaleway_lb.main", "description", "a description"),
92+
resource.TestCheckResourceAttr("scaleway_lb.main", "ssl_compatibility_level", lbSDK.SSLCompatibilityLevelSslCompatibilityLevelIntermediate.String()),
93+
),
94+
},
95+
{
96+
Config: `
97+
resource scaleway_lb_ip main {
98+
}
99+
100+
resource scaleway_lb main {
101+
ip_id = scaleway_lb_ip.main.id
102+
name = "test-lb-rename"
103+
description = "another description"
104+
type = "LB-S"
105+
tags = ["basic", "tag2"]
106+
ssl_compatibility_level = "ssl_compatibility_level_modern"
107+
}
108+
`,
109+
Check: resource.ComposeTestCheckFunc(
110+
testAccCheckScalewayLbExists(tt, "scaleway_lb.main"),
111+
testCheckResourceAttrUUID("scaleway_lb.main", "id"),
112+
resource.TestCheckResourceAttr("scaleway_lb.main", "name", "test-lb-rename"),
113+
resource.TestCheckResourceAttr("scaleway_lb.main", "tags.#", "2"),
114+
resource.TestCheckResourceAttr("scaleway_lb.main", "description", "another description"),
115+
resource.TestCheckResourceAttr("scaleway_lb.main", "ssl_compatibility_level", lbSDK.SSLCompatibilityLevelSslCompatibilityLevelModern.String()),
116+
),
117+
},
118+
},
119+
})
120+
}
121+
64122
func TestAccScalewayLbLb_Migrate(t *testing.T) {
65123
tt := NewTestTools(t)
66124
defer tt.Cleanup()

0 commit comments

Comments
 (0)