Skip to content

Commit 71e160c

Browse files
authored
fix(instance_server): detach pn on server deletion (#2179)
* fix(instance_server): detach pn on server deletion * update cassettes * update cassette * update cassette
1 parent 6e092c9 commit 71e160c

9 files changed

+5647
-5648
lines changed

scaleway/resource_instance_server.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,11 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
966966

967967
err = ph.detach(ctx, o, d.Timeout(schema.TimeoutUpdate))
968968
if err != nil {
969-
diag.FromErr(err)
969+
return diag.FromErr(err)
970970
}
971971
err = ph.attach(ctx, n, d.Timeout(schema.TimeoutUpdate))
972972
if err != nil {
973-
diag.FromErr(err)
973+
return diag.FromErr(err)
974974
}
975975
}
976976
}
@@ -988,7 +988,7 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
988988

989989
err = ph.detach(ctx, pn["pn_id"], d.Timeout(schema.TimeoutUpdate))
990990
if err != nil {
991-
diag.FromErr(err)
991+
return diag.FromErr(err)
992992
}
993993
}
994994
}
@@ -1073,6 +1073,23 @@ func resourceScalewayInstanceServerDelete(ctx context.Context, d *schema.Resourc
10731073
return diag.FromErr(err)
10741074
}
10751075

1076+
// Delete private-nic if managed by instance_server resource
1077+
if raw, ok := d.GetOk("private_network"); ok {
1078+
ph, err := newPrivateNICHandler(instanceAPI, id, zone)
1079+
if err != nil {
1080+
return diag.FromErr(err)
1081+
}
1082+
1083+
for index := range raw.([]interface{}) {
1084+
pnKey := fmt.Sprintf("private_network.%d.pn_id", index)
1085+
pn := d.Get(pnKey)
1086+
err := ph.detach(ctx, pn, d.Timeout(schema.TimeoutDelete))
1087+
if err != nil {
1088+
return diag.FromErr(err)
1089+
}
1090+
}
1091+
}
1092+
10761093
_, err = waitForInstanceServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutDelete))
10771094
if err != nil && !is404Error(err) {
10781095
return diag.FromErr(err)

scaleway/testdata/data-source-vpc-public-gateway-dhcp-reservation-basic.cassette.yaml

Lines changed: 856 additions & 1308 deletions
Large diffs are not rendered by default.

scaleway/testdata/data-source-vpc-public-gateway-dhcp-reservation-static.cassette.yaml

Lines changed: 820 additions & 768 deletions
Large diffs are not rendered by default.

scaleway/testdata/instance-server-private-network.cassette.yaml

Lines changed: 1073 additions & 979 deletions
Large diffs are not rendered by default.

scaleway/testdata/lblb-different-locality-ipid.cassette.yaml

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
version: 1
33
interactions:
44
- request:
5-
body: '{"project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","reverse":null}'
5+
body: '{"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","reverse":null}'
66
form: {}
77
headers:
88
Content-Type:
99
- application/json
1010
User-Agent:
11-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
11+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
1212
terraform/terraform-tests
1313
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips
1414
method: POST
1515
response:
16-
body: '{"id":"219a5e42-9bc6-4d1e-a33a-9c59de54e758","ip_address":"51.159.87.170","lb_id":null,"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","region":"fr-par","reverse":"51-159-87-170.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
16+
body: '{"id":"58ab4591-6e1c-4177-90c5-e6e26fc60904","ip_address":"51.159.86.186","lb_id":null,"organization_id":"105bdce1-64c0-48ab-899d-868455867ecf","project_id":"105bdce1-64c0-48ab-899d-868455867ecf","region":"fr-par","reverse":"51-159-86-186.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
1717
headers:
1818
Content-Length:
19-
- "278"
19+
- "285"
2020
Content-Security-Policy:
2121
- default-src 'none'; frame-ancestors 'none'
2222
Content-Type:
2323
- application/json
2424
Date:
25-
- Tue, 03 Jan 2023 10:05:05 GMT
25+
- Fri, 20 Oct 2023 14:18:26 GMT
2626
Server:
2727
- Scaleway API-Gateway
2828
Strict-Transport-Security:
@@ -32,7 +32,7 @@ interactions:
3232
X-Frame-Options:
3333
- DENY
3434
X-Request-Id:
35-
- b20f0007-eb10-4864-b531-fec1b1612aeb
35+
- 77db48be-d307-475a-913b-def7900eda96
3636
status: 200 OK
3737
code: 200
3838
duration: ""
@@ -41,21 +41,21 @@ interactions:
4141
form: {}
4242
headers:
4343
User-Agent:
44-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
44+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
4545
terraform/terraform-tests
46-
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
46+
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
4747
method: GET
4848
response:
49-
body: '{"id":"219a5e42-9bc6-4d1e-a33a-9c59de54e758","ip_address":"51.159.87.170","lb_id":null,"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","region":"fr-par","reverse":"51-159-87-170.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
49+
body: '{"id":"58ab4591-6e1c-4177-90c5-e6e26fc60904","ip_address":"51.159.86.186","lb_id":null,"organization_id":"105bdce1-64c0-48ab-899d-868455867ecf","project_id":"105bdce1-64c0-48ab-899d-868455867ecf","region":"fr-par","reverse":"51-159-86-186.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
5050
headers:
5151
Content-Length:
52-
- "278"
52+
- "285"
5353
Content-Security-Policy:
5454
- default-src 'none'; frame-ancestors 'none'
5555
Content-Type:
5656
- application/json
5757
Date:
58-
- Tue, 03 Jan 2023 10:05:05 GMT
58+
- Fri, 20 Oct 2023 14:18:26 GMT
5959
Server:
6060
- Scaleway API-Gateway
6161
Strict-Transport-Security:
@@ -65,7 +65,7 @@ interactions:
6565
X-Frame-Options:
6666
- DENY
6767
X-Request-Id:
68-
- c27d102e-cfd9-4ca9-b73e-5ae19bd7023a
68+
- 9087a291-d91e-460a-b58f-3320eb136965
6969
status: 200 OK
7070
code: 200
7171
duration: ""
@@ -74,21 +74,21 @@ interactions:
7474
form: {}
7575
headers:
7676
User-Agent:
77-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
77+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
7878
terraform/terraform-tests
79-
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
79+
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
8080
method: GET
8181
response:
82-
body: '{"id":"219a5e42-9bc6-4d1e-a33a-9c59de54e758","ip_address":"51.159.87.170","lb_id":null,"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","region":"fr-par","reverse":"51-159-87-170.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
82+
body: '{"id":"58ab4591-6e1c-4177-90c5-e6e26fc60904","ip_address":"51.159.86.186","lb_id":null,"organization_id":"105bdce1-64c0-48ab-899d-868455867ecf","project_id":"105bdce1-64c0-48ab-899d-868455867ecf","region":"fr-par","reverse":"51-159-86-186.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
8383
headers:
8484
Content-Length:
85-
- "278"
85+
- "285"
8686
Content-Security-Policy:
8787
- default-src 'none'; frame-ancestors 'none'
8888
Content-Type:
8989
- application/json
9090
Date:
91-
- Tue, 03 Jan 2023 10:05:05 GMT
91+
- Fri, 20 Oct 2023 14:18:26 GMT
9292
Server:
9393
- Scaleway API-Gateway
9494
Strict-Transport-Security:
@@ -98,7 +98,7 @@ interactions:
9898
X-Frame-Options:
9999
- DENY
100100
X-Request-Id:
101-
- ee055e6d-e687-4178-a171-5605157e9e92
101+
- 5346f00c-934a-4a13-bc47-e92b66441aeb
102102
status: 200 OK
103103
code: 200
104104
duration: ""
@@ -107,21 +107,21 @@ interactions:
107107
form: {}
108108
headers:
109109
User-Agent:
110-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
110+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
111111
terraform/terraform-tests
112-
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
112+
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
113113
method: GET
114114
response:
115-
body: '{"id":"219a5e42-9bc6-4d1e-a33a-9c59de54e758","ip_address":"51.159.87.170","lb_id":null,"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","region":"fr-par","reverse":"51-159-87-170.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
115+
body: '{"id":"58ab4591-6e1c-4177-90c5-e6e26fc60904","ip_address":"51.159.86.186","lb_id":null,"organization_id":"105bdce1-64c0-48ab-899d-868455867ecf","project_id":"105bdce1-64c0-48ab-899d-868455867ecf","region":"fr-par","reverse":"51-159-86-186.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
116116
headers:
117117
Content-Length:
118-
- "278"
118+
- "285"
119119
Content-Security-Policy:
120120
- default-src 'none'; frame-ancestors 'none'
121121
Content-Type:
122122
- application/json
123123
Date:
124-
- Tue, 03 Jan 2023 10:05:05 GMT
124+
- Fri, 20 Oct 2023 14:18:27 GMT
125125
Server:
126126
- Scaleway API-Gateway
127127
Strict-Transport-Security:
@@ -131,7 +131,7 @@ interactions:
131131
X-Frame-Options:
132132
- DENY
133133
X-Request-Id:
134-
- 54de9cc7-3d51-4307-a973-dfbcb961ecee
134+
- 84815af8-9990-4677-879f-798ac45336fd
135135
status: 200 OK
136136
code: 200
137137
duration: ""
@@ -140,21 +140,21 @@ interactions:
140140
form: {}
141141
headers:
142142
User-Agent:
143-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
143+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
144144
terraform/terraform-tests
145-
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
145+
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
146146
method: GET
147147
response:
148-
body: '{"id":"219a5e42-9bc6-4d1e-a33a-9c59de54e758","ip_address":"51.159.87.170","lb_id":null,"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","region":"fr-par","reverse":"51-159-87-170.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
148+
body: '{"id":"58ab4591-6e1c-4177-90c5-e6e26fc60904","ip_address":"51.159.86.186","lb_id":null,"organization_id":"105bdce1-64c0-48ab-899d-868455867ecf","project_id":"105bdce1-64c0-48ab-899d-868455867ecf","region":"fr-par","reverse":"51-159-86-186.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
149149
headers:
150150
Content-Length:
151-
- "278"
151+
- "285"
152152
Content-Security-Policy:
153153
- default-src 'none'; frame-ancestors 'none'
154154
Content-Type:
155155
- application/json
156156
Date:
157-
- Tue, 03 Jan 2023 10:05:06 GMT
157+
- Fri, 20 Oct 2023 14:18:27 GMT
158158
Server:
159159
- Scaleway API-Gateway
160160
Strict-Transport-Security:
@@ -164,7 +164,7 @@ interactions:
164164
X-Frame-Options:
165165
- DENY
166166
X-Request-Id:
167-
- f9413a3f-bbea-4177-a976-9ef9a3220259
167+
- 4283b6cc-21bb-4eed-aee3-8058127dc57c
168168
status: 200 OK
169169
code: 200
170170
duration: ""
@@ -173,21 +173,21 @@ interactions:
173173
form: {}
174174
headers:
175175
User-Agent:
176-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
176+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
177177
terraform/terraform-tests
178-
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
178+
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
179179
method: GET
180180
response:
181-
body: '{"id":"219a5e42-9bc6-4d1e-a33a-9c59de54e758","ip_address":"51.159.87.170","lb_id":null,"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","region":"fr-par","reverse":"51-159-87-170.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
181+
body: '{"id":"58ab4591-6e1c-4177-90c5-e6e26fc60904","ip_address":"51.159.86.186","lb_id":null,"organization_id":"105bdce1-64c0-48ab-899d-868455867ecf","project_id":"105bdce1-64c0-48ab-899d-868455867ecf","region":"fr-par","reverse":"51-159-86-186.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
182182
headers:
183183
Content-Length:
184-
- "278"
184+
- "285"
185185
Content-Security-Policy:
186186
- default-src 'none'; frame-ancestors 'none'
187187
Content-Type:
188188
- application/json
189189
Date:
190-
- Tue, 03 Jan 2023 10:05:06 GMT
190+
- Fri, 20 Oct 2023 14:18:27 GMT
191191
Server:
192192
- Scaleway API-Gateway
193193
Strict-Transport-Security:
@@ -197,7 +197,7 @@ interactions:
197197
X-Frame-Options:
198198
- DENY
199199
X-Request-Id:
200-
- ead5186a-e104-4eeb-9d6d-c799ac6c8ff1
200+
- 3b06ea74-45c1-4d34-b29b-5699ef1124d6
201201
status: 200 OK
202202
code: 200
203203
duration: ""
@@ -206,21 +206,21 @@ interactions:
206206
form: {}
207207
headers:
208208
User-Agent:
209-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
209+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
210210
terraform/terraform-tests
211-
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
211+
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
212212
method: GET
213213
response:
214-
body: '{"id":"219a5e42-9bc6-4d1e-a33a-9c59de54e758","ip_address":"51.159.87.170","lb_id":null,"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","region":"fr-par","reverse":"51-159-87-170.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
214+
body: '{"id":"58ab4591-6e1c-4177-90c5-e6e26fc60904","ip_address":"51.159.86.186","lb_id":null,"organization_id":"105bdce1-64c0-48ab-899d-868455867ecf","project_id":"105bdce1-64c0-48ab-899d-868455867ecf","region":"fr-par","reverse":"51-159-86-186.lb.fr-par.scw.cloud","zone":"fr-par-2"}'
215215
headers:
216216
Content-Length:
217-
- "278"
217+
- "285"
218218
Content-Security-Policy:
219219
- default-src 'none'; frame-ancestors 'none'
220220
Content-Type:
221221
- application/json
222222
Date:
223-
- Tue, 03 Jan 2023 10:05:06 GMT
223+
- Fri, 20 Oct 2023 14:18:28 GMT
224224
Server:
225225
- Scaleway API-Gateway
226226
Strict-Transport-Security:
@@ -230,7 +230,7 @@ interactions:
230230
X-Frame-Options:
231231
- DENY
232232
X-Request-Id:
233-
- 5a121c1e-b491-41ba-8d08-b22c334f2466
233+
- c58549aa-d5bd-4598-9203-92dfd0deb59c
234234
status: 200 OK
235235
code: 200
236236
duration: ""
@@ -239,9 +239,9 @@ interactions:
239239
form: {}
240240
headers:
241241
User-Agent:
242-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
242+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
243243
terraform/terraform-tests
244-
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
244+
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
245245
method: DELETE
246246
response:
247247
body: ""
@@ -251,7 +251,7 @@ interactions:
251251
Content-Type:
252252
- application/json
253253
Date:
254-
- Tue, 03 Jan 2023 10:05:07 GMT
254+
- Fri, 20 Oct 2023 14:18:28 GMT
255255
Server:
256256
- Scaleway API-Gateway
257257
Strict-Transport-Security:
@@ -261,7 +261,7 @@ interactions:
261261
X-Frame-Options:
262262
- DENY
263263
X-Request-Id:
264-
- 75122b98-dd5c-42bd-b38a-34c252a8454e
264+
- 4120043c-64f7-4937-9cdb-c286436d9d81
265265
status: 204 No Content
266266
code: 204
267267
duration: ""

0 commit comments

Comments
 (0)