Skip to content

Commit cb300f2

Browse files
authored
feat(vpc-gw): add support for SSH bastion (#1255)
1 parent ad50d20 commit cb300f2

15 files changed

+5633
-5368
lines changed

docs/resources/vpc_public_gateway.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ The following arguments are supported:
3030
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the public gateway is associated with.
3131
- `upstream_dns_servers` - (Optional) override the gateway's default recursive DNS servers, if DNS features are enabled.
3232
- `ip_id` - (Optional) attach an existing flexible IP to the gateway
33+
- `bastion_enabled` - (Optional) Enable SSH bastion on the gateway
34+
- `bastion_port` - (Optional) The port on which the SSH bastion will listen.
3335

3436
## Attributes Reference
3537

scaleway/helpers.go

+7
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ func expandInt32Ptr(data interface{}) *int32 {
494494
return scw.Int32Ptr(int32(data.(int)))
495495
}
496496

497+
func expandUint32Ptr(data interface{}) *uint32 {
498+
if data == nil || data == "" {
499+
return nil
500+
}
501+
return scw.Uint32Ptr(uint32(data.(int)))
502+
}
503+
497504
func expandIPNet(raw string) (scw.IPNet, error) {
498505
if raw == "" {
499506
return scw.IPNet{}, nil

scaleway/resource_vpc_public_gateway.go

+45-12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ func resourceScalewayVPCPublicGateway() *schema.Resource {
5656
Type: schema.TypeString,
5757
},
5858
},
59+
"bastion_enabled": {
60+
Type: schema.TypeBool,
61+
Description: "Enable SSH bastion on the gateway",
62+
Optional: true,
63+
},
64+
"bastion_port": {
65+
Type: schema.TypeInt,
66+
Description: "Port of the SSH bastion",
67+
Optional: true,
68+
Computed: true,
69+
},
5970
"project_id": projectIDSchema(),
6071
"zone": zoneSchema(),
6172
// Computed elements
@@ -86,9 +97,14 @@ func resourceScalewayVPCPublicGatewayCreate(ctx context.Context, d *schema.Resou
8697
Tags: expandStrings(d.Get("tags")),
8798
UpstreamDNSServers: expandStrings(d.Get("upstream_dns_servers")),
8899
ProjectID: d.Get("project_id").(string),
100+
EnableBastion: d.Get("bastion_enabled").(bool),
89101
Zone: zone,
90102
}
91103

104+
if bastionPort, ok := d.GetOk("bastion_port"); ok {
105+
req.BastionPort = expandUint32Ptr(bastionPort.(int))
106+
}
107+
92108
if ipID, ok := d.GetOk("ip_id"); ok {
93109
req.IPID = expandStringPtr(expandZonedID(ipID).ID)
94110
}
@@ -133,6 +149,8 @@ func resourceScalewayVPCPublicGatewayRead(ctx context.Context, d *schema.Resourc
133149
_ = d.Set("tags", gateway.Tags)
134150
_ = d.Set("upstream_dns_servers", gateway.UpstreamDNSServers)
135151
_ = d.Set("ip_id", newZonedID(gateway.Zone, gateway.IP.ID).String())
152+
_ = d.Set("bastion_enabled", gateway.BastionEnabled)
153+
_ = d.Set("bastion_port", int(gateway.BastionPort))
136154

137155
return nil
138156
}
@@ -148,19 +166,34 @@ func resourceScalewayVPCPublicGatewayUpdate(ctx context.Context, d *schema.Resou
148166
return diag.FromErr(err)
149167
}
150168

151-
if d.HasChanges("name", "tags", "upstream_dns_servers") {
152-
updateRequest := &vpcgw.UpdateGatewayRequest{
153-
GatewayID: gateway.ID,
154-
Zone: gateway.Zone,
155-
Name: scw.StringPtr(d.Get("name").(string)),
156-
Tags: scw.StringsPtr(expandStrings(d.Get("tags"))),
157-
UpstreamDNSServers: scw.StringsPtr(expandStrings(d.Get("upstream_dns_servers"))),
158-
}
169+
updateRequest := &vpcgw.UpdateGatewayRequest{
170+
GatewayID: gateway.ID,
171+
Zone: gateway.Zone,
172+
}
159173

160-
_, err = vpcgwAPI.UpdateGateway(updateRequest, scw.WithContext(ctx))
161-
if err != nil {
162-
return diag.FromErr(err)
163-
}
174+
if d.HasChanges("name") {
175+
updateRequest.Name = scw.StringPtr(d.Get("name").(string))
176+
}
177+
178+
if d.HasChange("tags") {
179+
updateRequest.Tags = scw.StringsPtr(expandStrings(d.Get("tags")))
180+
}
181+
182+
if d.HasChange("bastion_port") {
183+
updateRequest.BastionPort = scw.Uint32Ptr(uint32(d.Get("bastion_port").(int)))
184+
}
185+
186+
if d.HasChange("enable_bastion") {
187+
updateRequest.EnableBastion = scw.BoolPtr(d.Get("enable_bastion").(bool))
188+
}
189+
190+
if d.HasChange("upstream_dns_servers") {
191+
updateRequest.UpstreamDNSServers = scw.StringsPtr(expandStrings(d.Get("upstream_dns_servers")))
192+
}
193+
194+
_, err = vpcgwAPI.UpdateGateway(updateRequest, scw.WithContext(ctx))
195+
if err != nil {
196+
return diag.FromErr(err)
164197
}
165198

166199
_, err = waitForVPCPublicGateway(ctx, vpcgwAPI, zone, id, d.Timeout(schema.TimeoutUpdate))

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

+163-163
Large diffs are not rendered by default.

scaleway/testdata/data-source-vpc-public-gateway-pat-rule-basic.cassette.yaml

+318-318
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)