Skip to content

Commit

Permalink
fix(instance_server): detach pn on server deletion (#2179)
Browse files Browse the repository at this point in the history
* fix(instance_server): detach pn on server deletion

* update cassettes

* update cassette

* update cassette
  • Loading branch information
Codelax authored Oct 23, 2023
1 parent 6e092c9 commit 71e160c
Show file tree
Hide file tree
Showing 9 changed files with 5,647 additions and 5,648 deletions.
23 changes: 20 additions & 3 deletions scaleway/resource_instance_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,11 +966,11 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc

err = ph.detach(ctx, o, d.Timeout(schema.TimeoutUpdate))
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
err = ph.attach(ctx, n, d.Timeout(schema.TimeoutUpdate))
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
}
}
Expand All @@ -988,7 +988,7 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc

err = ph.detach(ctx, pn["pn_id"], d.Timeout(schema.TimeoutUpdate))
if err != nil {
diag.FromErr(err)
return diag.FromErr(err)
}
}
}
Expand Down Expand Up @@ -1073,6 +1073,23 @@ func resourceScalewayInstanceServerDelete(ctx context.Context, d *schema.Resourc
return diag.FromErr(err)
}

// Delete private-nic if managed by instance_server resource
if raw, ok := d.GetOk("private_network"); ok {
ph, err := newPrivateNICHandler(instanceAPI, id, zone)
if err != nil {
return diag.FromErr(err)
}

for index := range raw.([]interface{}) {
pnKey := fmt.Sprintf("private_network.%d.pn_id", index)
pn := d.Get(pnKey)
err := ph.detach(ctx, pn, d.Timeout(schema.TimeoutDelete))
if err != nil {
return diag.FromErr(err)
}
}
}

_, err = waitForInstanceServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutDelete))
if err != nil && !is404Error(err) {
return diag.FromErr(err)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2,052 changes: 1,073 additions & 979 deletions scaleway/testdata/instance-server-private-network.cassette.yaml

Large diffs are not rendered by default.

92 changes: 46 additions & 46 deletions scaleway/testdata/lblb-different-locality-ipid.cassette.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
version: 1
interactions:
- request:
body: '{"project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","reverse":null}'
body: '{"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","reverse":null}'
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips
method: POST
response:
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"}'
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"}'
headers:
Content-Length:
- "278"
- "285"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:05 GMT
- Fri, 20 Oct 2023 14:18:26 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -32,7 +32,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- b20f0007-eb10-4864-b531-fec1b1612aeb
- 77db48be-d307-475a-913b-def7900eda96
status: 200 OK
code: 200
duration: ""
Expand All @@ -41,21 +41,21 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
method: GET
response:
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"}'
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"}'
headers:
Content-Length:
- "278"
- "285"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:05 GMT
- Fri, 20 Oct 2023 14:18:26 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -65,7 +65,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- c27d102e-cfd9-4ca9-b73e-5ae19bd7023a
- 9087a291-d91e-460a-b58f-3320eb136965
status: 200 OK
code: 200
duration: ""
Expand All @@ -74,21 +74,21 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
method: GET
response:
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"}'
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"}'
headers:
Content-Length:
- "278"
- "285"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:05 GMT
- Fri, 20 Oct 2023 14:18:26 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -98,7 +98,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- ee055e6d-e687-4178-a171-5605157e9e92
- 5346f00c-934a-4a13-bc47-e92b66441aeb
status: 200 OK
code: 200
duration: ""
Expand All @@ -107,21 +107,21 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
method: GET
response:
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"}'
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"}'
headers:
Content-Length:
- "278"
- "285"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:05 GMT
- Fri, 20 Oct 2023 14:18:27 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -131,7 +131,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- 54de9cc7-3d51-4307-a973-dfbcb961ecee
- 84815af8-9990-4677-879f-798ac45336fd
status: 200 OK
code: 200
duration: ""
Expand All @@ -140,21 +140,21 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
method: GET
response:
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"}'
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"}'
headers:
Content-Length:
- "278"
- "285"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:06 GMT
- Fri, 20 Oct 2023 14:18:27 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -164,7 +164,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- f9413a3f-bbea-4177-a976-9ef9a3220259
- 4283b6cc-21bb-4eed-aee3-8058127dc57c
status: 200 OK
code: 200
duration: ""
Expand All @@ -173,21 +173,21 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
method: GET
response:
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"}'
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"}'
headers:
Content-Length:
- "278"
- "285"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:06 GMT
- Fri, 20 Oct 2023 14:18:27 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -197,7 +197,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- ead5186a-e104-4eeb-9d6d-c799ac6c8ff1
- 3b06ea74-45c1-4d34-b29b-5699ef1124d6
status: 200 OK
code: 200
duration: ""
Expand All @@ -206,21 +206,21 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
method: GET
response:
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"}'
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"}'
headers:
Content-Length:
- "278"
- "285"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:06 GMT
- Fri, 20 Oct 2023 14:18:28 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -230,7 +230,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- 5a121c1e-b491-41ba-8d08-b22c334f2466
- c58549aa-d5bd-4598-9203-92dfd0deb59c
status: 200 OK
code: 200
duration: ""
Expand All @@ -239,9 +239,9 @@ interactions:
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.1; linux; amd64) terraform-provider/develop
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.1; linux; amd64) terraform-provider/develop
terraform/terraform-tests
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/219a5e42-9bc6-4d1e-a33a-9c59de54e758
url: https://api.scaleway.com/lb/v1/zones/fr-par-2/ips/58ab4591-6e1c-4177-90c5-e6e26fc60904
method: DELETE
response:
body: ""
Expand All @@ -251,7 +251,7 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 03 Jan 2023 10:05:07 GMT
- Fri, 20 Oct 2023 14:18:28 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -261,7 +261,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- 75122b98-dd5c-42bd-b38a-34c252a8454e
- 4120043c-64f7-4937-9cdb-c286436d9d81
status: 204 No Content
code: 204
duration: ""
Loading

0 comments on commit 71e160c

Please sign in to comment.