Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/services/vpcgw/public_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vpcgw

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -80,6 +81,14 @@ func ResourcePublicGateway() *schema.Resource {
Description: "Port of the SSH bastion",
Optional: true,
Computed: true,
ValidateFunc: func(val any, key string) ([]string, []error) {
v := val.(int)
if (v >= 1024 && v <= 59999) || v == 61000 {
return nil, nil
}

return nil, []error{fmt.Errorf("expected bastion_port to be in the range (1024 - 59999) or default 61000, got %d", v)}
},
},
"enable_smtp": {
Type: schema.TypeBool,
Expand Down
40 changes: 40 additions & 0 deletions internal/services/vpcgw/public_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vpcgw_test

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -116,6 +117,7 @@ func TestAccVPCPublicGateway_Bastion(t *testing.T) {
publicGatewayName,
),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_enabled", "true"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_port", "61000"),
),
},
{
Expand All @@ -132,6 +134,44 @@ func TestAccVPCPublicGateway_Bastion(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_enabled", "false"),
),
},
{
Config: fmt.Sprintf(`
resource scaleway_vpc_public_gateway main {
name = "%s"
type = "VPC-GW-S"
bastion_enabled = true
bastion_port = 59999
}
`, publicGatewayName),
Check: resource.ComposeTestCheckFunc(
testAccCheckVPCPublicGatewayExists(tt, "scaleway_vpc_public_gateway.main"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "name", publicGatewayName),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_enabled", "true"),
resource.TestCheckResourceAttr("scaleway_vpc_public_gateway.main", "bastion_port", "59999"),
),
},
},
})
}

func TestAccVPCPublicGateway_BastionInvalidPort(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()

resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: tt.ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_vpc_public_gateway" "main" {
name = "public-gateway-bastion-invalid"
type = "VPC-GW-S"
bastion_enabled = true
bastion_port = 61001
}
`,
ExpectError: regexp.MustCompile(`expected bastion_port to be in the range \(1024 - 59999\) or default 61000, got 61001`),
},
},
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
version: 2
interactions: []
Loading
Loading