Skip to content

Commit 43dab7b

Browse files
authored
tests(rdb): fix gateway network to use ipam mode (#2780)
1 parent 109bc8d commit 43dab7b

File tree

2 files changed

+1073
-902
lines changed

2 files changed

+1073
-902
lines changed

internal/services/rdb/instance_test.go

Lines changed: 96 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ func TestAccInstance_PrivateNetworkUpdate(t *testing.T) {
695695
})
696696
}
697697

698+
// TODO: Refactor this test when rdb is ipam-compatible
698699
func TestAccInstance_PrivateNetwork_DHCP(t *testing.T) {
699700
tt := acctest.NewTestTools(t)
700701
defer tt.Cleanup()
@@ -708,63 +709,77 @@ func TestAccInstance_PrivateNetwork_DHCP(t *testing.T) {
708709
Steps: []resource.TestStep{
709710
{
710711
Config: fmt.Sprintf(`
711-
resource scaleway_vpc_private_network pn02 {
712-
name = "my_private_network"
713-
region= "nl-ams"
714-
}
715-
716-
resource scaleway_vpc_public_gateway_dhcp main {
712+
resource "scaleway_vpc" "vpc01" {
713+
name = "my vpc"
714+
region = "nl-ams"
715+
}
716+
717+
resource "scaleway_vpc_private_network" "pn01" {
718+
name = "my_private_network"
719+
vpc_id = scaleway_vpc.vpc01.id
720+
ipv4_subnet {
717721
subnet = "192.168.1.0/24"
718-
zone = "nl-ams-1"
719-
}
720-
721-
resource scaleway_vpc_public_gateway_ip main {
722-
zone = "nl-ams-1"
723-
}
724-
725-
resource scaleway_vpc_public_gateway main {
726-
name = "foobar"
727-
type = "VPC-GW-S"
728-
zone = "nl-ams-1"
729-
ip_id = scaleway_vpc_public_gateway_ip.main.id
730-
}
731-
732-
resource scaleway_vpc_public_gateway_pat_rule main {
733-
gateway_id = scaleway_vpc_public_gateway.main.id
734-
private_ip = scaleway_vpc_public_gateway_dhcp.main.address
735-
private_port = scaleway_rdb_instance.main.private_network.0.port
736-
public_port = 42
737-
protocol = "both"
738-
zone = "nl-ams-1"
739-
depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.pn02]
740-
}
741-
742-
resource scaleway_vpc_gateway_network main {
743-
gateway_id = scaleway_vpc_public_gateway.main.id
744-
private_network_id = scaleway_vpc_private_network.pn02.id
745-
dhcp_id = scaleway_vpc_public_gateway_dhcp.main.id
746-
cleanup_dhcp = true
747-
enable_masquerade = true
748-
zone = "nl-ams-1"
749-
depends_on = [scaleway_vpc_public_gateway_ip.main, scaleway_vpc_private_network.pn02]
722+
}
723+
region = "nl-ams"
750724
}
751-
752-
resource scaleway_rdb_instance main {
753-
name = "test-rdb-private-network-dhcp"
754-
node_type = "db-dev-s"
755-
engine = %q
756-
is_ha_cluster = false
757-
disable_backup = true
758-
user_name = "my_initial_user"
759-
password = "thiZ_is_v&ry_s3cret"
760-
region= "nl-ams"
761-
tags = [ "terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn" ]
762-
volume_type = "bssd"
763-
volume_size_in_gb = 10
764-
private_network {
765-
ip_net = "192.168.1.254/24" #pool high
766-
pn_id = "${scaleway_vpc_private_network.pn02.id}"
767-
}
725+
726+
data "scaleway_ipam_ip" "ip01" {
727+
resource {
728+
id = scaleway_vpc_gateway_network.main.id
729+
type = "vpc_gateway_network"
730+
}
731+
type = "ipv4"
732+
region = "nl-ams"
733+
}
734+
735+
resource "scaleway_vpc_public_gateway_ip" "main" {
736+
zone = "nl-ams-1"
737+
}
738+
739+
resource "scaleway_vpc_public_gateway" "main" {
740+
name = "foobar"
741+
type = "VPC-GW-S"
742+
zone = "nl-ams-1"
743+
ip_id = scaleway_vpc_public_gateway_ip.main.id
744+
}
745+
746+
resource "scaleway_vpc_public_gateway_pat_rule" "main" {
747+
gateway_id = scaleway_vpc_public_gateway.main.id
748+
private_ip = data.scaleway_ipam_ip.ip01.address
749+
private_port = scaleway_rdb_instance.main.private_network.0.port
750+
public_port = 42
751+
protocol = "both"
752+
zone = "nl-ams-1"
753+
depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.pn01]
754+
}
755+
756+
resource "scaleway_vpc_gateway_network" "main" {
757+
gateway_id = scaleway_vpc_public_gateway.main.id
758+
private_network_id = scaleway_vpc_private_network.pn01.id
759+
ipam_config {
760+
push_default_route = true
761+
}
762+
enable_masquerade = true
763+
zone = "nl-ams-1"
764+
depends_on = [scaleway_vpc_public_gateway_ip.main, scaleway_vpc_private_network.pn01]
765+
}
766+
767+
resource "scaleway_rdb_instance" "main" {
768+
name = "test-rdb-private-network-dhcp"
769+
node_type = "db-dev-s"
770+
engine = %q
771+
is_ha_cluster = false
772+
disable_backup = true
773+
user_name = "my_initial_user"
774+
password = "thiZ_is_v&ry_s3cret"
775+
region = "nl-ams"
776+
tags = ["terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn"]
777+
volume_type = "bssd"
778+
volume_size_in_gb = 10
779+
private_network {
780+
ip_net = "192.168.1.254/24" #pool high
781+
pn_id = scaleway_vpc_private_network.pn01.id
782+
}
768783
}
769784
`, latestEngineVersion),
770785
Check: resource.ComposeTestCheckFunc(
@@ -774,23 +789,32 @@ func TestAccInstance_PrivateNetwork_DHCP(t *testing.T) {
774789
},
775790
{
776791
Config: fmt.Sprintf(`
777-
resource scaleway_vpc_private_network pn02 {
778-
name = "my_private_network"
779-
region= "nl-ams"
780-
}
781-
782-
resource scaleway_rdb_instance main {
783-
name = "test-rdb-private-network-dhcp"
784-
node_type = "db-dev-s"
785-
engine = %q
786-
is_ha_cluster = false
787-
disable_backup = true
788-
user_name = "my_initial_user"
789-
password = "thiZ_is_v&ry_s3cret"
790-
region= "nl-ams"
791-
tags = [ "terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn" ]
792-
volume_type = "bssd"
793-
volume_size_in_gb = 10
792+
resource "scaleway_vpc" "vpc01" {
793+
name = "my vpc"
794+
region = "nl-ams"
795+
}
796+
797+
resource "scaleway_vpc_private_network" "pn01" {
798+
name = "my_private_network"
799+
vpc_id = scaleway_vpc.vpc01.id
800+
ipv4_subnet {
801+
subnet = "192.168.1.0/24"
802+
}
803+
region = "nl-ams"
804+
}
805+
806+
resource "scaleway_rdb_instance" "main" {
807+
name = "test-rdb-private-network-dhcp"
808+
node_type = "db-dev-s"
809+
engine = %q
810+
is_ha_cluster = false
811+
disable_backup = true
812+
user_name = "my_initial_user"
813+
password = "thiZ_is_v&ry_s3cret"
814+
region = "nl-ams"
815+
tags = ["terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn"]
816+
volume_type = "bssd"
817+
volume_size_in_gb = 10
794818
}
795819
`, latestEngineVersion),
796820
},

internal/services/rdb/testdata/instance-private-network-dhcp.cassette.yaml

Lines changed: 977 additions & 830 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)