mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-07 22:53:08 -06:00
a422bf02f1
* provider/scaleway: increase wait for server time according to the scaleway community, shutdown/ startup might actually take an hour. since a regular shutdown transfers data this is bound by the size of the actual volumes in use. https://community.online.net/t/solving-the-long-shutdown-boot-when-only-needed-to-attach-detach-a-volume/326 anyhow, 20 minutes seems quite optimistic, and we've seen some timeout errors in the logs, too * provider/scaleway: clear cache on volume attachment the volume attachment errors quite often, and while I have no hard evidence (yet) I guess it might be related to the cache that the official scaleway SDK includes. for now this is just a tiny experiment, clearing the cache when creating/ destroying volume attachments. let's see if this improves anything, really * provider/scaleway: guard against attaching already attached volumes * provider/scaleway: use cheaper instance types for tests Scaleway bills by the hour and C2S costs much more than C1, since in the tests we just spin up instances, to destroy them later on...
92 lines
2.1 KiB
Go
92 lines
2.1 KiB
Go
package scaleway
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccScalewayVolumeAttachment_Basic(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckScalewayVolumeAttachmentDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccCheckScalewayVolumeAttachmentConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckScalewayVolumeAttachmentExists("scaleway_volume_attachment.test"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckScalewayVolumeAttachmentDestroy(s *terraform.State) error {
|
|
client := testAccProvider.Meta().(*Client).scaleway
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "scaleway" {
|
|
continue
|
|
}
|
|
|
|
s, err := client.GetServer(rs.Primary.Attributes["server"])
|
|
if err != nil {
|
|
fmt.Printf("Failed getting server: %q", err)
|
|
return err
|
|
}
|
|
|
|
for _, volume := range s.Volumes {
|
|
if volume.Identifier == rs.Primary.Attributes["volume"] {
|
|
return fmt.Errorf("Attachment still exists")
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCheckScalewayVolumeAttachmentExists(n string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
client := testAccProvider.Meta().(*Client).scaleway
|
|
|
|
rs, _ := s.RootModule().Resources[n]
|
|
|
|
server, err := client.GetServer(rs.Primary.Attributes["server"])
|
|
if err != nil {
|
|
fmt.Printf("Failed getting server: %q", err)
|
|
return err
|
|
}
|
|
|
|
for _, volume := range server.Volumes {
|
|
if volume.Identifier == rs.Primary.Attributes["volume"] {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
return fmt.Errorf("Attachment does not exist")
|
|
}
|
|
}
|
|
|
|
var testAccCheckScalewayVolumeAttachmentConfig = fmt.Sprintf(`
|
|
resource "scaleway_server" "base" {
|
|
name = "test"
|
|
# ubuntu 14.04
|
|
image = "%s"
|
|
type = "C1"
|
|
# state = "stopped"
|
|
}
|
|
|
|
resource "scaleway_volume" "test" {
|
|
name = "test"
|
|
size_in_gb = 5
|
|
type = "l_ssd"
|
|
}
|
|
|
|
resource "scaleway_volume_attachment" "test" {
|
|
server = "${scaleway_server.base.id}"
|
|
volume = "${scaleway_volume.test.id}"
|
|
}`, armImageIdentifier)
|