|
6 | 6 | "os"
|
7 | 7 | "testing"
|
8 | 8 |
|
| 9 | + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
10 | 11 | )
|
11 | 12 |
|
@@ -104,3 +105,62 @@ func TestAccCloudProjectInstance_basic(t *testing.T) {
|
104 | 105 | },
|
105 | 106 | })
|
106 | 107 | }
|
| 108 | + |
| 109 | +func TestAccCloudProjectInstance_withSSHKeyCreate(t *testing.T) { |
| 110 | + serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST") |
| 111 | + region := os.Getenv("OVH_CLOUD_PROJECT_REGION_TEST") |
| 112 | + flavor, image, err := getFlavorAndImage(serviceName, region) |
| 113 | + if err != nil { |
| 114 | + t.Fatalf("failed to retrieve a flavor and an image: %s", err) |
| 115 | + } |
| 116 | + |
| 117 | + sshKeyName := acctest.RandomWithPrefix(test_prefix) |
| 118 | + |
| 119 | + var testCreateInstance = fmt.Sprintf(` |
| 120 | + resource "ovh_cloud_project_instance" "instance" { |
| 121 | + service_name = "%s" |
| 122 | + region = "%s" |
| 123 | + billing_period = "hourly" |
| 124 | + boot_from { |
| 125 | + image_id = "%s" |
| 126 | + } |
| 127 | + flavor { |
| 128 | + flavor_id = "%s" |
| 129 | + } |
| 130 | + name = "TestInstance" |
| 131 | + ssh_key_create { |
| 132 | + name = "%s" |
| 133 | + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9xPpdqP3sx2H+gcBm65tJEaUbuifQ1uGkgrWtNY0PRKNNPdy+3yoVOtxk6Vjo4YZ0EU/JhmQfnrK7X7Q5vhqYxmozi0LiTRt0BxgqHJ+4hWTWMIOgr+C2jLx7ZsCReRk+fy5AHr6h0PHQEuXVLXeUy/TDyuY2JPtUZ5jcqvLYgQ== my-key" |
| 134 | + } |
| 135 | + network { |
| 136 | + public = true |
| 137 | + } |
| 138 | + } |
| 139 | + `, |
| 140 | + serviceName, |
| 141 | + region, |
| 142 | + image, |
| 143 | + flavor, |
| 144 | + sshKeyName) |
| 145 | + |
| 146 | + resource.Test(t, resource.TestCase{ |
| 147 | + PreCheck: func() { |
| 148 | + testAccPreCheckCloud(t) |
| 149 | + testAccCheckCloudProjectExists(t) |
| 150 | + }, |
| 151 | + Providers: testAccProviders, |
| 152 | + Steps: []resource.TestStep{ |
| 153 | + { |
| 154 | + Config: testCreateInstance, |
| 155 | + Check: resource.ComposeTestCheckFunc( |
| 156 | + resource.TestCheckResourceAttrSet("ovh_cloud_project_instance.instance", "id"), |
| 157 | + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "flavor_name", "b2-7"), |
| 158 | + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "flavor_id", flavor), |
| 159 | + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "image_id", image), |
| 160 | + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "region", region), |
| 161 | + resource.TestCheckResourceAttr("ovh_cloud_project_instance.instance", "name", "TestInstance"), |
| 162 | + ), |
| 163 | + }, |
| 164 | + }, |
| 165 | + }) |
| 166 | +} |
0 commit comments