@@ -1296,6 +1296,88 @@ func TestAccInstance_CompleteWorkflow(t *testing.T) {
12961296 })
12971297}
12981298
1299+ func TestAccInstance_FromSnapshotWithPrivateNetwork (t * testing.T ) {
1300+ tt := acctest .NewTestTools (t )
1301+ defer tt .Cleanup ()
1302+
1303+ latestEngineVersion := rdbchecks .GetLatestEngineVersion (tt , postgreSQLEngineName )
1304+
1305+ resource .ParallelTest (t , resource.TestCase {
1306+ PreCheck : func () { acctest .PreCheck (t ) },
1307+ ProviderFactories : tt .ProviderFactories ,
1308+ CheckDestroy : IsSnapshotDestroyed (tt ),
1309+ Steps : []resource.TestStep {
1310+ // Step 1: Create an instance, private network, and a snapshot
1311+ {
1312+ Config : fmt .Sprintf (`
1313+ resource "scaleway_vpc" "vpc" {
1314+ name = "test-vpc"
1315+ }
1316+
1317+ resource "scaleway_vpc_private_network" "pn" {
1318+ vpc_id = scaleway_vpc.vpc.id
1319+ ipv4_subnet {
1320+ subnet = "192.168.0.0/24"
1321+ }
1322+ depends_on = [scaleway_vpc.vpc]
1323+ }
1324+
1325+ resource "scaleway_rdb_instance" "main" {
1326+ name = "test-rdb-instance"
1327+ node_type = "db-dev-s"
1328+ engine = %q
1329+ is_ha_cluster = false
1330+ disable_backup = true
1331+ user_name = "my_initial_user"
1332+ password = "thiZ_is_v&ry_s3cret"
1333+ tags = ["terraform-test", "scaleway_rdb_instance"]
1334+ volume_type = "sbs_5k"
1335+ volume_size_in_gb = 10
1336+
1337+ private_network {
1338+ pn_id = scaleway_vpc_private_network.pn.id
1339+ enable_ipam = true
1340+ }
1341+
1342+ depends_on = [scaleway_vpc_private_network.pn]
1343+ }
1344+
1345+ resource "scaleway_rdb_snapshot" "test" {
1346+ name = "test-snapshot"
1347+ instance_id = scaleway_rdb_instance.main.id
1348+ depends_on = [scaleway_rdb_instance.main]
1349+ }
1350+
1351+ resource "scaleway_rdb_instance" "from_snapshot" {
1352+ name = "test-instance-from-snapshot"
1353+ node_type = "db-dev-s"
1354+ is_ha_cluster = false
1355+ disable_backup = true
1356+ snapshot_id = scaleway_rdb_snapshot.test.id
1357+ volume_type = "sbs_5k"
1358+ tags = ["terraform-test", "restored_instance"]
1359+
1360+ private_network {
1361+ pn_id = scaleway_vpc_private_network.pn.id
1362+ enable_ipam = true
1363+ }
1364+
1365+ depends_on = [scaleway_rdb_snapshot.test]
1366+ }
1367+ ` , latestEngineVersion ),
1368+ Check : resource .ComposeTestCheckFunc (
1369+ resource .TestCheckResourceAttr ("scaleway_rdb_instance.from_snapshot" , "name" , "test-instance-from-snapshot" ),
1370+ resource .TestCheckResourceAttr ("scaleway_rdb_instance.from_snapshot" , "user_name" , "my_initial_user" ),
1371+ resource .TestCheckResourceAttr ("scaleway_rdb_instance.from_snapshot" , "tags.0" , "terraform-test" ),
1372+ resource .TestCheckResourceAttr ("scaleway_rdb_instance.from_snapshot" , "tags.1" , "restored_instance" ),
1373+ resource .TestCheckResourceAttrSet ("scaleway_rdb_instance.from_snapshot" , "private_network.0.pn_id" ),
1374+ resource .TestCheckResourceAttr ("scaleway_rdb_instance.from_snapshot" , "private_network.0.enable_ipam" , "true" ),
1375+ ),
1376+ },
1377+ },
1378+ })
1379+ }
1380+
12991381func isInstancePresent (tt * acctest.TestTools , n string ) resource.TestCheckFunc {
13001382 return func (s * terraform.State ) error {
13011383 rs , ok := s .RootModule ().Resources [n ]
0 commit comments