Skip to content

Commit 7730ca3

Browse files
authored
resolve conflicts (#2507)
1 parent 57a06da commit 7730ca3

File tree

13 files changed

+4937
-27
lines changed

13 files changed

+4937
-27
lines changed

docs/resources/lb.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ resource "scaleway_lb_ip" "main" {
1818
}
1919
2020
resource "scaleway_lb" "base" {
21-
ip_id = scaleway_lb_ip.main.id
22-
zone = scaleway_lb_ip.main.zone
23-
type = "LB-S"
21+
ip_ids = [scaleway_lb_ip.main.id]
22+
zone = scaleway_lb_ip.main.zone
23+
type = "LB-S"
2424
}
2525
```
2626

@@ -29,13 +29,27 @@ resource "scaleway_lb" "base" {
2929
```terraform
3030
3131
resource "scaleway_lb" "base" {
32-
ip_id = scaleway_lb_ip.main.id
33-
zone = scaleway_lb_ip.main.zone
34-
type = "LB-S"
32+
name = "private-lb"
33+
type = "LB-S"
3534
assign_flexible_ip = false
3635
}
3736
```
3837

38+
### With IPv6
39+
40+
```terraform
41+
resource "scaleway_lb_ip" "v4" {
42+
}
43+
resource "scaleway_lb_ip" "v6" {
44+
is_ipv6 = true
45+
}
46+
resource scaleway_lb main {
47+
ip_ids = [scaleway_lb_ip.v4.id, scaleway_lb_ip.v6.id]
48+
name = "ipv6-lb"
49+
type = "LB-S"
50+
}
51+
```
52+
3953
### Multiple configurations
4054

4155
```terraform
@@ -113,7 +127,9 @@ resource scaleway_lb main {
113127

114128
The following arguments are supported:
115129

116-
- `ip_id` - (Optional) The ID of the associated LB IP. See below.
130+
- `ip_ids` - (Optional) The List of IP IDs to attach to the Load Balancer.
131+
132+
- `ip_id` - (Deprecated) The ID of the associated LB IP. See below.
117133

118134
~> **Important:** Updates to `ip_id` will recreate the load-balancer.
119135

@@ -145,7 +161,8 @@ In addition to all arguments above, the following attributes are exported:
145161

146162
~> **Important:** Load-Balancers' IDs are [zoned](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{zone}/{id}`, e.g. `fr-par-1/11111111-1111-1111-1111-111111111111`
147163

148-
- `ip_address` - The load-balance public IP Address
164+
- `ip_address` - The load-balancer public IPv4 Address.
165+
- `ipv6_address` - The load-balancer public IPv6 Address.
149166
- `organization_id` - The organization ID the load-balancer is associated with.
150167

151168
~> **Important:** `release_ip` will not be supported. This prevents the destruction of the IP from releasing a LBs.

docs/resources/lb_ip.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ resource "scaleway_lb_ip" "ip" {
1818
}
1919
```
2020

21+
### With IPv6
22+
23+
```terraform
24+
resource "scaleway_lb_ip" "ipv6" {
25+
is_ipv6 = true
26+
}
27+
```
28+
2129
## Argument Reference
2230

2331
The following arguments are supported:
2432

2533
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
2634
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the IP is associated with.
2735
- `reverse` - (Optional) The reverse domain associated with this IP.
36+
- `is_ipv6` - (Optional) If true, creates a Flexible IP with an IPv6 address.
2837

2938
## Attributes Reference
3039

internal/services/lb/helpers_lb.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,34 @@ func GetKeyInRawConfigMap(rawConfig map[string]cty.Value, key string, ty cty.Typ
237237
}
238238
return nil, false
239239
}
240+
241+
func customizeDiffLBIPIDs(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
242+
oldIPIDs, newIPIDs := diff.GetChange("ip_ids")
243+
oldIPIDsSet := make(map[string]struct{})
244+
newIPIDsSet := make(map[string]struct{})
245+
246+
for _, id := range oldIPIDs.([]interface{}) {
247+
oldIPIDsSet[id.(string)] = struct{}{}
248+
}
249+
250+
for _, id := range newIPIDs.([]interface{}) {
251+
newIPIDsSet[id.(string)] = struct{}{}
252+
}
253+
254+
// Check if any IP ID is being removed
255+
for id := range oldIPIDsSet {
256+
if _, ok := newIPIDsSet[id]; !ok {
257+
return diff.ForceNew("ip_ids")
258+
}
259+
}
260+
261+
return nil
262+
}
263+
264+
func customizeDiffAssignFlexibleIPv6(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
265+
oldValue, newValue := diff.GetChange("assign_flexible_ipv6")
266+
if oldValue.(bool) && !newValue.(bool) {
267+
return diff.ForceNew("assign_flexible_ipv6")
268+
}
269+
return nil
270+
}

internal/services/lb/ip.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55

66
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
lbSDK "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
1010
"github.com/scaleway/scaleway-sdk-go/scw"
@@ -55,6 +55,13 @@ func ResourceIP() *schema.Resource {
5555
Computed: true,
5656
Description: "The ID of the load balancer attached to this IP, if any",
5757
},
58+
"is_ipv6": {
59+
Type: schema.TypeBool,
60+
Optional: true,
61+
ForceNew: true,
62+
Default: false,
63+
Description: "If true, creates a Flexible IP with an IPv6 address",
64+
},
5865
"region": regional.ComputedSchema(),
5966
},
6067
}
@@ -75,6 +82,7 @@ func resourceLbIPCreate(ctx context.Context, d *schema.ResourceData, m interface
7582
Zone: zone,
7683
ProjectID: types.ExpandStringPtr(d.Get("project_id")),
7784
Reverse: types.ExpandStringPtr(d.Get("reverse")),
85+
IsIPv6: d.Get("is_ipv6").(bool),
7886
}
7987

8088
res, err := lbAPI.CreateIP(createReq, scw.WithContext(ctx))
@@ -141,16 +149,16 @@ func resourceLbIPUpdate(ctx context.Context, d *schema.ResourceData, m interface
141149
}
142150

143151
var ip *lbSDK.IP
144-
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
152+
err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError {
145153
res, errGet := lbAPI.GetIP(&lbSDK.ZonedAPIGetIPRequest{
146154
Zone: zone,
147155
IPID: ID,
148156
}, scw.WithContext(ctx))
149157
if err != nil {
150158
if httperrors.Is403(errGet) {
151-
return resource.RetryableError(errGet)
159+
return retry.RetryableError(errGet)
152160
}
153-
return resource.NonRetryableError(errGet)
161+
return retry.NonRetryableError(errGet)
154162
}
155163

156164
ip = res
@@ -210,16 +218,16 @@ func resourceLbIPDelete(ctx context.Context, d *schema.ResourceData, m interface
210218
}
211219

212220
var ip *lbSDK.IP
213-
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
221+
err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError {
214222
res, errGet := lbAPI.GetIP(&lbSDK.ZonedAPIGetIPRequest{
215223
Zone: zone,
216224
IPID: ID,
217225
}, scw.WithContext(ctx))
218226
if err != nil {
219227
if httperrors.Is403(errGet) {
220-
return resource.RetryableError(errGet)
228+
return retry.RetryableError(errGet)
221229
}
222-
return resource.NonRetryableError(errGet)
230+
return retry.NonRetryableError(errGet)
223231
}
224232

225233
ip = res

internal/services/lb/ip_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,29 @@ func TestAccIP_Basic(t *testing.T) {
113113
})
114114
}
115115

116+
func TestAccIP_IPv6(t *testing.T) {
117+
tt := acctest.NewTestTools(t)
118+
defer tt.Cleanup()
119+
resource.ParallelTest(t, resource.TestCase{
120+
PreCheck: func() { acctest.PreCheck(t) },
121+
ProviderFactories: tt.ProviderFactories,
122+
CheckDestroy: lbchecks.IsIPDestroyed(tt),
123+
Steps: []resource.TestStep{
124+
{
125+
Config: `
126+
resource scaleway_lb_ip ipv6 {
127+
is_ipv6 = true
128+
}
129+
`,
130+
Check: resource.ComposeTestCheckFunc(
131+
isIPPresent(tt, "scaleway_lb_ip.ipv6"),
132+
acctest.CheckResourceAttrIPv6("scaleway_lb_ip.ipv6", "ip_address"),
133+
),
134+
},
135+
},
136+
})
137+
}
138+
116139
func isIPPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
117140
return func(state *terraform.State) error {
118141
rs, ok := state.RootModule().Resources[n]

0 commit comments

Comments
 (0)