Skip to content

tests(rdb): fix gateway network to use ipam mode #2780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2024
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
168 changes: 96 additions & 72 deletions internal/services/rdb/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ func TestAccInstance_PrivateNetworkUpdate(t *testing.T) {
})
}

// TODO: Refactor this test when rdb is ipam-compatible
func TestAccInstance_PrivateNetwork_DHCP(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
Expand All @@ -708,63 +709,77 @@ func TestAccInstance_PrivateNetwork_DHCP(t *testing.T) {
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource scaleway_vpc_private_network pn02 {
name = "my_private_network"
region= "nl-ams"
}

resource scaleway_vpc_public_gateway_dhcp main {
resource "scaleway_vpc" "vpc01" {
name = "my vpc"
region = "nl-ams"
}

resource "scaleway_vpc_private_network" "pn01" {
name = "my_private_network"
vpc_id = scaleway_vpc.vpc01.id
ipv4_subnet {
subnet = "192.168.1.0/24"
zone = "nl-ams-1"
}

resource scaleway_vpc_public_gateway_ip main {
zone = "nl-ams-1"
}

resource scaleway_vpc_public_gateway main {
name = "foobar"
type = "VPC-GW-S"
zone = "nl-ams-1"
ip_id = scaleway_vpc_public_gateway_ip.main.id
}

resource scaleway_vpc_public_gateway_pat_rule main {
gateway_id = scaleway_vpc_public_gateway.main.id
private_ip = scaleway_vpc_public_gateway_dhcp.main.address
private_port = scaleway_rdb_instance.main.private_network.0.port
public_port = 42
protocol = "both"
zone = "nl-ams-1"
depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.pn02]
}

resource scaleway_vpc_gateway_network main {
gateway_id = scaleway_vpc_public_gateway.main.id
private_network_id = scaleway_vpc_private_network.pn02.id
dhcp_id = scaleway_vpc_public_gateway_dhcp.main.id
cleanup_dhcp = true
enable_masquerade = true
zone = "nl-ams-1"
depends_on = [scaleway_vpc_public_gateway_ip.main, scaleway_vpc_private_network.pn02]
}
region = "nl-ams"
}

resource scaleway_rdb_instance main {
name = "test-rdb-private-network-dhcp"
node_type = "db-dev-s"
engine = %q
is_ha_cluster = false
disable_backup = true
user_name = "my_initial_user"
password = "thiZ_is_v&ry_s3cret"
region= "nl-ams"
tags = [ "terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn" ]
volume_type = "bssd"
volume_size_in_gb = 10
private_network {
ip_net = "192.168.1.254/24" #pool high
pn_id = "${scaleway_vpc_private_network.pn02.id}"
}

data "scaleway_ipam_ip" "ip01" {
resource {
id = scaleway_vpc_gateway_network.main.id
type = "vpc_gateway_network"
}
type = "ipv4"
region = "nl-ams"
}

resource "scaleway_vpc_public_gateway_ip" "main" {
zone = "nl-ams-1"
}

resource "scaleway_vpc_public_gateway" "main" {
name = "foobar"
type = "VPC-GW-S"
zone = "nl-ams-1"
ip_id = scaleway_vpc_public_gateway_ip.main.id
}

resource "scaleway_vpc_public_gateway_pat_rule" "main" {
gateway_id = scaleway_vpc_public_gateway.main.id
private_ip = data.scaleway_ipam_ip.ip01.address
private_port = scaleway_rdb_instance.main.private_network.0.port
public_port = 42
protocol = "both"
zone = "nl-ams-1"
depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.pn01]
}

resource "scaleway_vpc_gateway_network" "main" {
gateway_id = scaleway_vpc_public_gateway.main.id
private_network_id = scaleway_vpc_private_network.pn01.id
ipam_config {
push_default_route = true
}
enable_masquerade = true
zone = "nl-ams-1"
depends_on = [scaleway_vpc_public_gateway_ip.main, scaleway_vpc_private_network.pn01]
}

resource "scaleway_rdb_instance" "main" {
name = "test-rdb-private-network-dhcp"
node_type = "db-dev-s"
engine = %q
is_ha_cluster = false
disable_backup = true
user_name = "my_initial_user"
password = "thiZ_is_v&ry_s3cret"
region = "nl-ams"
tags = ["terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn"]
volume_type = "bssd"
volume_size_in_gb = 10
private_network {
ip_net = "192.168.1.254/24" #pool high
pn_id = scaleway_vpc_private_network.pn01.id
}
}
`, latestEngineVersion),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -774,23 +789,32 @@ func TestAccInstance_PrivateNetwork_DHCP(t *testing.T) {
},
{
Config: fmt.Sprintf(`
resource scaleway_vpc_private_network pn02 {
name = "my_private_network"
region= "nl-ams"
}

resource scaleway_rdb_instance main {
name = "test-rdb-private-network-dhcp"
node_type = "db-dev-s"
engine = %q
is_ha_cluster = false
disable_backup = true
user_name = "my_initial_user"
password = "thiZ_is_v&ry_s3cret"
region= "nl-ams"
tags = [ "terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn" ]
volume_type = "bssd"
volume_size_in_gb = 10
resource "scaleway_vpc" "vpc01" {
name = "my vpc"
region = "nl-ams"
}

resource "scaleway_vpc_private_network" "pn01" {
name = "my_private_network"
vpc_id = scaleway_vpc.vpc01.id
ipv4_subnet {
subnet = "192.168.1.0/24"
}
region = "nl-ams"
}

resource "scaleway_rdb_instance" "main" {
name = "test-rdb-private-network-dhcp"
node_type = "db-dev-s"
engine = %q
is_ha_cluster = false
disable_backup = true
user_name = "my_initial_user"
password = "thiZ_is_v&ry_s3cret"
region = "nl-ams"
tags = ["terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn"]
volume_type = "bssd"
volume_size_in_gb = 10
}
`, latestEngineVersion),
},
Expand Down
1,807 changes: 977 additions & 830 deletions internal/services/rdb/testdata/instance-private-network-dhcp.cassette.yaml

Large diffs are not rendered by default.

Loading