@@ -188,7 +188,7 @@ func TestAccLibvirtVolume_BackingStoreTestByName(t *testing.T) {
188188 name = "%s"
189189 base_volume_name = "${libvirt_volume.backing-%s.name}"
190190 pool = "${libvirt_pool.%s.name}"
191- }
191+ }
192192 ` , random , random , randomPoolPath , random , random , random , random , random , random , random ),
193193 Check : resource .ComposeTestCheckFunc (
194194 testAccCheckLibvirtVolumeExists ("libvirt_volume.backing-" + random , & volume ),
@@ -489,6 +489,134 @@ func TestAccLibvirtVolume_Import(t *testing.T) {
489489 })
490490}
491491
492+ func TestAccLibvirtVolume_ResizeShrink (t * testing.T ) {
493+ var volume libvirt.StorageVol
494+ randomVolumeResource := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
495+ randomVolumeName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
496+ randomPoolName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
497+ randomPoolPath := "/tmp/terraform-provider-libvirt-pool-" + randomPoolName
498+
499+ resource .Test (t , resource.TestCase {
500+ PreCheck : func () { testAccPreCheck (t ) },
501+ Providers : testAccProviders ,
502+ CheckDestroy : testAccCheckLibvirtVolumeDestroy ,
503+ Steps : []resource.TestStep {
504+ {
505+ Config : fmt .Sprintf (`
506+ resource "libvirt_pool" "%s" {
507+ name = "%s"
508+ type = "dir"
509+ path = "%s"
510+ }
511+
512+ resource "libvirt_volume" "%s" {
513+ name = "%s"
514+ format = "raw"
515+ size = 1024 * 1024
516+ pool = "${libvirt_pool.%s.name}"
517+ }` , randomPoolName , randomPoolName , randomPoolPath , randomVolumeResource , randomVolumeName , randomPoolName ,
518+ ),
519+ ResourceName : "libvirt_volume." + randomVolumeResource ,
520+ Check : resource .ComposeTestCheckFunc (
521+ testAccCheckLibvirtVolumeExists ("libvirt_volume." + randomVolumeResource , & volume ),
522+ resource .TestCheckResourceAttr (
523+ "libvirt_volume." + randomVolumeResource , "name" , randomVolumeName ),
524+ resource .TestCheckResourceAttr (
525+ "libvirt_volume." + randomVolumeResource , "size" , "1048576" ),
526+ ),
527+ },
528+ {
529+ Config : fmt .Sprintf (`
530+ resource "libvirt_pool" "%s" {
531+ name = "%s"
532+ type = "dir"
533+ path = "%s"
534+ }
535+
536+ resource "libvirt_volume" "%s" {
537+ name = "%s"
538+ format = "raw"
539+ size = 1024
540+ pool = "${libvirt_pool.%s.name}"
541+ }` , randomPoolName , randomPoolName , randomPoolPath , randomVolumeResource , randomVolumeName , randomPoolName ,
542+ ),
543+ ResourceName : "libvirt_volume." + randomVolumeResource ,
544+ Check : resource .ComposeTestCheckFunc (
545+ testAccCheckLibvirtVolumeExists ("libvirt_volume." + randomVolumeResource , & volume ),
546+ resource .TestCheckResourceAttr (
547+ "libvirt_volume." + randomVolumeResource , "name" , randomVolumeName ),
548+ resource .TestCheckResourceAttr (
549+ "libvirt_volume." + randomVolumeResource , "size" , "1024" ),
550+ ),
551+ },
552+ },
553+ })
554+ }
555+
556+ func TestAccLibvirtVolume_ResizeExpand (t * testing.T ) {
557+ var volume libvirt.StorageVol
558+ randomVolumeResource := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
559+ randomVolumeName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
560+ randomPoolName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
561+ randomPoolPath := "/tmp/terraform-provider-libvirt-pool-" + randomPoolName
562+
563+ resource .Test (t , resource.TestCase {
564+ PreCheck : func () { testAccPreCheck (t ) },
565+ Providers : testAccProviders ,
566+ CheckDestroy : testAccCheckLibvirtVolumeDestroy ,
567+ Steps : []resource.TestStep {
568+ {
569+ Config : fmt .Sprintf (`
570+ resource "libvirt_pool" "%s" {
571+ name = "%s"
572+ type = "dir"
573+ path = "%s"
574+ }
575+
576+ resource "libvirt_volume" "%s" {
577+ name = "%s"
578+ format = "raw"
579+ size = 1024 * 1024
580+ pool = "${libvirt_pool.%s.name}"
581+ }` , randomPoolName , randomPoolName , randomPoolPath , randomVolumeResource , randomVolumeName , randomPoolName ,
582+ ),
583+ ResourceName : "libvirt_volume." + randomVolumeResource ,
584+ Check : resource .ComposeTestCheckFunc (
585+ testAccCheckLibvirtVolumeExists ("libvirt_volume." + randomVolumeResource , & volume ),
586+ resource .TestCheckResourceAttr (
587+ "libvirt_volume." + randomVolumeResource , "name" , randomVolumeName ),
588+ resource .TestCheckResourceAttr (
589+ "libvirt_volume." + randomVolumeResource , "size" , "1048576" ),
590+ ),
591+ },
592+ {
593+ Config : fmt .Sprintf (`
594+ resource "libvirt_pool" "%s" {
595+ name = "%s"
596+ type = "dir"
597+ path = "%s"
598+ }
599+
600+ resource "libvirt_volume" "%s" {
601+ name = "%s"
602+ format = "raw"
603+ size = 1024 * 1024 * 10
604+ pool = "${libvirt_pool.%s.name}"
605+ }` , randomPoolName , randomPoolName , randomPoolPath , randomVolumeResource , randomVolumeName , randomPoolName ,
606+ ),
607+ ResourceName : "libvirt_volume." + randomVolumeResource ,
608+ Check : resource .ComposeTestCheckFunc (
609+ testAccCheckLibvirtVolumeExists ("libvirt_volume." + randomVolumeResource , & volume ),
610+ resource .TestCheckResourceAttr (
611+ "libvirt_volume." + randomVolumeResource , "name" , randomVolumeName ),
612+ resource .TestCheckResourceAttr (
613+ "libvirt_volume." + randomVolumeResource , "size" , "10485760" ),
614+ ),
615+ },
616+ },
617+ })
618+ }
619+
492620func testAccCheckLibvirtVolumeDestroy (state * terraform.State ) error {
493621 virConn := testAccProvider .Meta ().(* Client ).libvirt
494622 for _ , rs := range state .RootModule ().Resources {
0 commit comments