|
4 | 4 | "fmt"
|
5 | 5 | "testing"
|
6 | 6 |
|
| 7 | + sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" |
7 | 8 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
|
9 | 10 | lbSDK "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
|
@@ -188,6 +189,102 @@ func TestAccScalewayLbBackend_HealthCheck(t *testing.T) {
|
188 | 189 | })
|
189 | 190 | }
|
190 | 191 |
|
| 192 | +func TestAccScalewayLbBackend_WithFailoverHost(t *testing.T) { |
| 193 | + rName := sdkacctest.RandomWithPrefix("tf-acc-test") |
| 194 | + resourceName := "scaleway_object_bucket_website_configuration.test" |
| 195 | + |
| 196 | + tt := NewTestTools(t) |
| 197 | + defer tt.Cleanup() |
| 198 | + resource.ParallelTest(t, resource.TestCase{ |
| 199 | + PreCheck: func() { testAccPreCheck(t) }, |
| 200 | + ProviderFactories: tt.ProviderFactories, |
| 201 | + CheckDestroy: resource.ComposeTestCheckFunc( |
| 202 | + testAccCheckScalewayLbBackendDestroy(tt), |
| 203 | + testAccCheckScalewayObjectDestroy(tt), |
| 204 | + testAccCheckScalewayObjectBucketDestroy(tt), |
| 205 | + testAccCheckBucketWebsiteConfigurationDestroy(tt), |
| 206 | + ), |
| 207 | + Steps: []resource.TestStep{ |
| 208 | + { |
| 209 | + Config: ` |
| 210 | + resource scaleway_lb_ip ip01 {} |
| 211 | + resource scaleway_lb lb01 { |
| 212 | + ip_id = scaleway_lb_ip.ip01.id |
| 213 | + name = "test-lb" |
| 214 | + type = "lb-s" |
| 215 | + } |
| 216 | +
|
| 217 | + resource scaleway_instance_ip ip01 {} |
| 218 | +
|
| 219 | + resource scaleway_lb_backend bkd01 { |
| 220 | + lb_id = scaleway_lb.lb01.id |
| 221 | + name = "bkd01" |
| 222 | + forward_protocol = "http" |
| 223 | + forward_port = 80 |
| 224 | + proxy_protocol = "none" |
| 225 | + server_ips = [ scaleway_instance_ip.ip01.address ] |
| 226 | + } |
| 227 | + `, |
| 228 | + Check: testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"), |
| 229 | + }, |
| 230 | + { |
| 231 | + Config: fmt.Sprintf(` |
| 232 | + resource "scaleway_object_bucket" "test" { |
| 233 | + name = %[1]q |
| 234 | + acl = "public-read" |
| 235 | + tags = { |
| 236 | + TestName = "TestAccSCW_WebsiteConfig_basic" |
| 237 | + } |
| 238 | + } |
| 239 | +
|
| 240 | + resource scaleway_object "some_file" { |
| 241 | + bucket = scaleway_object_bucket.test.name |
| 242 | + key = "index.html" |
| 243 | + file = "testfixture/index.html" |
| 244 | + visibility = "public-read" |
| 245 | + } |
| 246 | + |
| 247 | + resource "scaleway_object_bucket_website_configuration" "test" { |
| 248 | + bucket = scaleway_object_bucket.test.name |
| 249 | + index_document { |
| 250 | + suffix = "index.html" |
| 251 | + } |
| 252 | + error_document { |
| 253 | + key = "error.html" |
| 254 | + } |
| 255 | + } |
| 256 | +
|
| 257 | + resource scaleway_lb_ip ip01 {} |
| 258 | + resource scaleway_lb lb01 { |
| 259 | + ip_id = scaleway_lb_ip.ip01.id |
| 260 | + name = "test-lb" |
| 261 | + type = "lb-s" |
| 262 | + } |
| 263 | +
|
| 264 | + resource scaleway_instance_ip ip01 {} |
| 265 | +
|
| 266 | + resource scaleway_lb_backend bkd01 { |
| 267 | + lb_id = scaleway_lb.lb01.id |
| 268 | + name = "bkd01" |
| 269 | + forward_protocol = "http" |
| 270 | + forward_port = 80 |
| 271 | + proxy_protocol = "none" |
| 272 | + server_ips = [ scaleway_instance_ip.ip01.address ] |
| 273 | + failover_host = scaleway_object_bucket_website_configuration.test.website_endpoint |
| 274 | + } |
| 275 | + `, rName), |
| 276 | + Check: resource.ComposeTestCheckFunc( |
| 277 | + testAccCheckBucketWebsiteConfigurationExists(tt, resourceName), |
| 278 | + testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"), |
| 279 | + resource.TestCheckResourceAttr(resourceName, "website_endpoint", rName+".s3-website.fr-par.scw.cloud"), |
| 280 | + resource.TestCheckResourceAttrSet("scaleway_lb_backend.bkd01", "failover_host"), |
| 281 | + ), |
| 282 | + ExpectNonEmptyPlan: !*UpdateCassettes, |
| 283 | + }, |
| 284 | + }, |
| 285 | + }) |
| 286 | +} |
| 287 | + |
191 | 288 | func testAccCheckScalewayLbBackendExists(tt *TestTools, n string) resource.TestCheckFunc {
|
192 | 289 | return func(state *terraform.State) error {
|
193 | 290 | rs, ok := state.RootModule().Resources[n]
|
|
0 commit comments