Skip to content
Draft
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
18 changes: 13 additions & 5 deletions internal/service/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ const (

func ResourceGateway() *schema.Resource {
return &schema.Resource{
Description: "Network gateways connect SDN Private Networks to external IP networks.",
CreateContext: resourceGatewayCreate,
ReadContext: resourceGatewayRead,
UpdateContext: resourceGatewayUpdate,
DeleteContext: resourceGatewayDelete,
EnableLegacyTypeSystemApplyErrors: true,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to remove the commit that adds these EnableLegacyTypeSystem*Errors for now and look into re-implementing this resource with plugin framework 🤔

EnableLegacyTypeSystemPlanErrors: true,
Description: "Network gateways connect SDN Private Networks to external IP networks.",
CreateContext: resourceGatewayCreate,
ReadContext: resourceGatewayRead,
UpdateContext: resourceGatewayUpdate,
DeleteContext: resourceGatewayDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down Expand Up @@ -73,6 +75,8 @@ func ResourceGateway() *schema.Resource {
MaxItems: 1,
MinItems: 1,
Elem: &schema.Resource{
EnableLegacyTypeSystemApplyErrors: true,
EnableLegacyTypeSystemPlanErrors: true,
Schema: map[string]*schema.Schema{
"id": {
Description: routerIDDescription,
Expand Down Expand Up @@ -108,6 +112,8 @@ func ResourceGateway() *schema.Resource {
Type: schema.TypeSet,
MaxItems: 1,
Elem: &schema.Resource{
EnableLegacyTypeSystemApplyErrors: true,
EnableLegacyTypeSystemPlanErrors: true,
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Expand Down Expand Up @@ -140,6 +146,8 @@ func ResourceGateway() *schema.Resource {
Computed: true,
Type: schema.TypeSet,
Elem: &schema.Resource{
EnableLegacyTypeSystemApplyErrors: true,
EnableLegacyTypeSystemPlanErrors: true,
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Expand Down
30 changes: 30 additions & 0 deletions upcloud/resource_upcloud_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,36 @@ func TestAccUpcloudGateway(t *testing.T) {
})
}

func TestAccUpcloudGateway_Minimal(t *testing.T) {
testData := utils.ReadTestDataFile(t, "testdata/upcloud_gateway/gateway_minimal.tf")
name := "upcloud_gateway.this"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testData,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "name", "tf-acc-test-net-gateway-gw"),
resource.TestCheckResourceAttr(name, "zone", "pl-waw1"),
),
},
{
Config: testData,
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
{
Config: testData,
ResourceName: name,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccUpcloudGateway_LabelsValidation(t *testing.T) {
testDataE := utils.ReadTestDataFile(t, "testdata/upcloud_gateway/gateway_e.tf")

Expand Down
40 changes: 40 additions & 0 deletions upcloud/testdata/upcloud_gateway/gateway_minimal.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "prefix" {
default = "tf-acc-test-net-gateway-"
type = string
}

variable "zone" {
default = "pl-waw1"
type = string
}

resource "upcloud_router" "this" {
name = "${var.prefix}router"

lifecycle {
ignore_changes = [static_route]
}
}

resource "upcloud_network" "this" {
name = "${var.prefix}net"
zone = var.zone

ip_network {
address = "172.16.125.0/24"
dhcp = true
family = "IPv4"
}

router = upcloud_router.this.id
}

resource "upcloud_gateway" "this" {
name = "${var.prefix}gw"
zone = var.zone
features = ["nat"]

router {
id = upcloud_router.this.id
}
}