mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-09 23:54:17 -06:00
9081cabd6e
* Add scaleway provider this PR allows the entire scaleway stack to be managed with terraform example usage looks like this: ``` provider "scaleway" { api_key = "snap" organization = "snip" } resource "scaleway_ip" "base" { server = "${scaleway_server.base.id}" } resource "scaleway_server" "base" { name = "test" # ubuntu 14.04 image = "aecaed73-51a5-4439-a127-6d8229847145" type = "C2S" } resource "scaleway_volume" "test" { name = "test" size_in_gb = 20 type = "l_ssd" } resource "scaleway_volume_attachment" "test" { server = "${scaleway_server.base.id}" volume = "${scaleway_volume.test.id}" } resource "scaleway_security_group" "base" { name = "public" description = "public gateway" } resource "scaleway_security_group_rule" "http-ingress" { security_group = "${scaleway_security_group.base.id}" action = "accept" direction = "inbound" ip_range = "0.0.0.0/0" protocol = "TCP" port = 80 } resource "scaleway_security_group_rule" "http-egress" { security_group = "${scaleway_security_group.base.id}" action = "accept" direction = "outbound" ip_range = "0.0.0.0/0" protocol = "TCP" port = 80 } ``` Note that volume attachments require the server to be stopped, which can lead to downtimes of you attach new volumes to already used servers * Update IP read to handle 404 gracefully * Read back resource on update * Ensure IP detachment works as expected Sadly this is not part of the official scaleway api just yet * Adjust detachIP helper based on feedback from @QuentinPerez in https://github.com/scaleway/scaleway-cli/pull/378 * Cleanup documentation * Rename api_key to access_key following @stack72 suggestion and rename the provider api_key for more clarity * Make tests less chatty by using custom logger
94 lines
2.2 KiB
Go
94 lines
2.2 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 x86_64ImageIdentifier = "aecaed73-51a5-4439-a127-6d8229847145"
|
|
|
|
var testAccCheckScalewayVolumeAttachmentConfig = fmt.Sprintf(`
|
|
resource "scaleway_server" "base" {
|
|
name = "test"
|
|
# ubuntu 14.04
|
|
image = "%s"
|
|
type = "C2S"
|
|
# state = "stopped"
|
|
}
|
|
|
|
resource "scaleway_volume" "test" {
|
|
name = "test"
|
|
size_in_gb = 20
|
|
type = "l_ssd"
|
|
}
|
|
|
|
resource "scaleway_volume_attachment" "test" {
|
|
server = "${scaleway_server.base.id}"
|
|
volume = "${scaleway_volume.test.id}"
|
|
}`, x86_64ImageIdentifier)
|