Skip to content

Commit 1812917

Browse files
authored
Merge branch 'master' into feat/cockpit-preconfigured-alerts
2 parents f25b251 + 8dcb144 commit 1812917

File tree

4 files changed

+757
-213
lines changed

4 files changed

+757
-213
lines changed

internal/services/vpcgw/public_gateway.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package vpcgw
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/hashicorp/terraform-plugin-log/tflog"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -80,6 +81,14 @@ func ResourcePublicGateway() *schema.Resource {
8081
Description: "Port of the SSH bastion",
8182
Optional: true,
8283
Computed: true,
84+
ValidateFunc: func(val any, key string) ([]string, []error) {
85+
v := val.(int)
86+
if (v >= 1024 && v <= 59999) || v == 61000 {
87+
return nil, nil
88+
}
89+
90+
return nil, []error{fmt.Errorf("expected bastion_port to be in the range (1024 - 59999) or default 61000, got %d", v)}
91+
},
8392
},
8493
"enable_smtp": {
8594
Type: schema.TypeBool,

internal/services/vpcgw/public_gateway_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package vpcgw_test
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -116,6 +117,7 @@ func TestAccVPCPublicGateway_Bastion(t *testing.T) {
116117
publicGatewayName,
117118
),
118119
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_enabled", "true"),
120+
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_port", "61000"),
119121
),
120122
},
121123
{
@@ -132,6 +134,44 @@ func TestAccVPCPublicGateway_Bastion(t *testing.T) {
132134
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_enabled", "false"),
133135
),
134136
},
137+
{
138+
Config: fmt.Sprintf(`
139+
resource scaleway_vpc_public_gateway main {
140+
name = "%s"
141+
type = "VPC-GW-S"
142+
bastion_enabled = true
143+
bastion_port = 59999
144+
}
145+
`, publicGatewayName),
146+
Check: resource.ComposeTestCheckFunc(
147+
testAccCheckVPCPublicGatewayExists(tt, "scaleway_vpc_public_gateway.main"),
148+
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "name", publicGatewayName),
149+
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_enabled", "true"),
150+
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_port", "59999"),
151+
),
152+
},
153+
},
154+
})
155+
}
156+
157+
func TestAccVPCPublicGateway_BastionInvalidPort(t *testing.T) {
158+
tt := acctest.NewTestTools(t)
159+
defer tt.Cleanup()
160+
161+
resource.ParallelTest(t, resource.TestCase{
162+
ProtoV6ProviderFactories: tt.ProviderFactories,
163+
Steps: []resource.TestStep{
164+
{
165+
Config: `
166+
resource "scaleway_vpc_public_gateway" "main" {
167+
name = "public-gateway-bastion-invalid"
168+
type = "VPC-GW-S"
169+
bastion_enabled = true
170+
bastion_port = 61001
171+
}
172+
`,
173+
ExpectError: regexp.MustCompile(`expected bastion_port to be in the range \(1024 - 59999\) or default 61000, got 61001`),
174+
},
135175
},
136176
})
137177
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
version: 2
3+
interactions: []

0 commit comments

Comments
 (0)