Skip to content

Commit 1b42618

Browse files
authored
feat(vpcgw): add support for triggering ssh keys refresh (scaleway#2567)
* feat(vpcgw): add support for triggering ssh keys refresh * update cassettes * improve example * fix
1 parent 3cb22e7 commit 1b42618

File tree

5 files changed

+3982
-2249
lines changed

5 files changed

+3982
-2249
lines changed

docs/resources/vpc_public_gateway.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ For more information, see [the documentation](https://www.scaleway.com/en/develo
1010

1111
## Example Usage
1212

13+
### Basic
14+
1315
```terraform
1416
resource "scaleway_vpc_public_gateway" "main" {
1517
name = "public_gateway_demo"
@@ -18,6 +20,36 @@ resource "scaleway_vpc_public_gateway" "main" {
1820
}
1921
```
2022

23+
### With bastion
24+
25+
```terraform
26+
resource "scaleway_iam_ssh_key" "key1" {
27+
name = "key1"
28+
public_key = file("~/.ssh/id_rsa.pub")
29+
}
30+
31+
resource "scaleway_iam_ssh_key" "key2" {
32+
name = "key2"
33+
public_key = file("~/.ssh/another_key.pub")}
34+
35+
# Use a local variable to compute a hash of the SSH keys
36+
locals {
37+
ssh_keys_hash = sha256(join(",", [
38+
scaleway_iam_ssh_key.key1.public_key,
39+
scaleway_iam_ssh_key.key2.public_key,
40+
]))
41+
}
42+
43+
resource "scaleway_vpc_public_gateway" "main" {
44+
name = "public_gateway_demo"
45+
type = "VPC-GW-S"
46+
tags = ["demo", "terraform"]
47+
bastion_enabled = true
48+
bastion_port = 61000
49+
refresh_ssh_keys = local.ssh_keys_hash
50+
}
51+
```
52+
2153
## Argument Reference
2254

2355
The following arguments are supported:
@@ -28,10 +60,11 @@ The following arguments are supported:
2860
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the public gateway should be created.
2961
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the public gateway is associated with.
3062
- `upstream_dns_servers` - (Optional) override the gateway's default recursive DNS servers, if DNS features are enabled.
31-
- `ip_id` - (Optional) attach an existing flexible IP to the gateway
32-
- `bastion_enabled` - (Optional) Enable SSH bastion on the gateway
63+
- `ip_id` - (Optional) attach an existing flexible IP to the gateway.
64+
- `bastion_enabled` - (Optional) Enable SSH bastion on the gateway.
3365
- `bastion_port` - (Optional) The port on which the SSH bastion will listen.
34-
- `enable_smtp` - (Optional) Enable SMTP on the gateway
66+
- `enable_smtp` - (Optional) Enable SMTP on the gateway.
67+
- `refresh_ssh_keys` - (Optional) Trigger a refresh of the SSH keys on the public gateway by changing this field's value.
3568

3669
## Attributes Reference
3770

internal/services/vpcgw/public_gateway.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ func ResourcePublicGateway() *schema.Resource {
8787
Optional: true,
8888
Computed: true,
8989
},
90+
"refresh_ssh_keys": {
91+
Type: schema.TypeString,
92+
Optional: true,
93+
Description: "Trigger a refresh of the SSH keys for a given Public Gateway by changing this field's value",
94+
},
9095
"project_id": account.ProjectIDSchema(),
9196
"zone": zonal.Schema(),
9297
// Computed elements
@@ -224,6 +229,21 @@ func ResourceVPCPublicGatewayUpdate(ctx context.Context, d *schema.ResourceData,
224229
updateRequest.UpstreamDNSServers = types.ExpandUpdatedStringsPtr(d.Get("upstream_dns_servers"))
225230
}
226231

232+
if d.HasChange("refresh_ssh_keys") {
233+
_, err := api.RefreshSSHKeys(&vpcgw.RefreshSSHKeysRequest{
234+
Zone: gateway.Zone,
235+
GatewayID: gateway.ID,
236+
}, scw.WithContext(ctx))
237+
if err != nil {
238+
return diag.FromErr(err)
239+
}
240+
}
241+
242+
_, err = waitForVPCPublicGateway(ctx, api, zone, id, d.Timeout(schema.TimeoutUpdate))
243+
if err != nil {
244+
return diag.FromErr(err)
245+
}
246+
227247
_, err = api.UpdateGateway(updateRequest, scw.WithContext(ctx))
228248
if err != nil {
229249
return diag.FromErr(err)

0 commit comments

Comments
 (0)