From 1626b9bf7a55b0274d7e83ed76405966d884312a Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Sun, 5 Mar 2023 20:11:49 +0000 Subject: [PATCH] Run TestAcc on new region --- .github/workflows/acceptance_test.yml | 3 +- outscale/data_source_outscale_ca_test.go | 10 ++-- outscale/data_source_outscale_cas_test.go | 22 ++++--- .../data_source_outscale_flexible_gpu_test.go | 15 +++-- ...data_source_outscale_flexible_gpus_test.go | 11 ++-- ..._source_outscale_image_export_task_test.go | 4 +- ...source_outscale_image_export_tasks_test.go | 4 +- outscale/data_source_outscale_image_test.go | 7 +-- outscale/data_source_outscale_images_test.go | 4 +- ...source_outscale_load_balancer_tags_test.go | 8 +-- ...data_source_outscale_load_balancer_test.go | 5 +- ...ata_source_outscale_load_balancers_test.go | 12 ++-- ...outscale_net_access_point_services_test.go | 14 ++--- ...a_source_outscale_net_access_point_test.go | 14 ++--- ..._source_outscale_net_access_points_test.go | 14 ++--- outscale/data_source_outscale_nic_test.go | 41 ++++++------- outscale/data_source_outscale_nics_test.go | 15 +++-- .../data_source_outscale_public_ip_test.go | 9 +-- ...urce_outscale_snapshot_export_task_test.go | 7 ++- ...rce_outscale_snapshot_export_tasks_test.go | 16 ++--- .../data_source_outscale_snapshot_test.go | 14 ++--- .../data_source_outscale_snapshots_test.go | 12 ++-- outscale/data_source_outscale_subnet_test.go | 60 ++++++++++--------- outscale/data_source_outscale_subnets_test.go | 24 ++++---- .../data_source_outscale_subregions_test.go | 4 +- outscale/data_source_outscale_vm_test.go | 21 +++---- outscale/data_source_outscale_volume_test.go | 10 ++-- outscale/data_source_outscale_volumes_test.go | 10 ++-- .../resource_outscale_dhcp_option_test.go | 6 +- ...esource_outscale_flexible_gpu_link_test.go | 8 ++- .../resource_outscale_flexible_gpu_test.go | 7 +-- ...esource_outscale_image_export_task_test.go | 3 +- ...e_outscale_image_launch_permission_test.go | 4 +- outscale/resource_outscale_image_test.go | 2 +- ..._outscale_load_balancer_attributes_test.go | 10 ++-- ...urce_outscale_load_balancer_policy_test.go | 7 +-- .../resource_outscale_load_balancer_test.go | 6 +- ...esource_outscale_load_balancer_vms_test.go | 4 +- ...resource_outscale_net_access_point_test.go | 4 +- outscale/resource_outscale_nic_link_test.go | 4 +- .../resource_outscale_nic_private_ip_test.go | 8 +-- outscale/resource_outscale_nic_test.go | 23 ++++--- .../resource_outscale_public_ip_link_test.go | 3 +- outscale/resource_outscale_public_ip_test.go | 5 +- .../resource_outscale_route_table_test.go | 3 +- ...ource_outscale_snapshot_attributes_test.go | 13 ++-- ...urce_outscale_snapshot_export_task_test.go | 11 ++-- outscale/resource_outscale_snapshot_test.go | 15 ++--- outscale/resource_outscale_subnet_test.go | 12 ++-- outscale/resource_outscale_tags_test.go | 9 ++- outscale/resource_outscale_vm_test.go | 57 +++++++++--------- outscale/resource_outscale_volume_test.go | 9 +-- .../resource_outscale_volumes_link_test.go | 7 +-- utils/utils.go | 9 +++ 54 files changed, 315 insertions(+), 324 deletions(-) diff --git a/.github/workflows/acceptance_test.yml b/.github/workflows/acceptance_test.yml index fc23db634..554aede58 100644 --- a/.github/workflows/acceptance_test.yml +++ b/.github/workflows/acceptance_test.yml @@ -13,8 +13,9 @@ on: jobs: Acceptances_tests: + environment: RUNNER_ACCESS concurrency: terraform-acceptance-test - runs-on: [self-hosted, linux] + runs-on: [self-hosted, linux, us-east-2] steps: - uses: actions/checkout@v3 with: diff --git a/outscale/data_source_outscale_ca_test.go b/outscale/data_source_outscale_ca_test.go index 96b39a53c..ee3bbaa39 100644 --- a/outscale/data_source_outscale_ca_test.go +++ b/outscale/data_source_outscale_ca_test.go @@ -72,16 +72,16 @@ func testAccDataCheckOutscaleCaDestroy(s *terraform.State) error { func testAccDataOutscaleOAPICaConfig(ca_pem string) string { return fmt.Sprintf(` -resource "outscale_ca" "ca_test" { +resource "outscale_ca" "ca_test" { ca_pem = %[1]q description = "Ca testacc create" } data "outscale_ca" "ca_data" { - filter { - name = "ca_ids" - values = ["${outscale_ca.ca_test.id}"] - } + filter { + name = "ca_ids" + values = [outscale_ca.ca_test.id] + } } `, ca_pem) } diff --git a/outscale/data_source_outscale_cas_test.go b/outscale/data_source_outscale_cas_test.go index 316f7f987..0a361cbc5 100644 --- a/outscale/data_source_outscale_cas_test.go +++ b/outscale/data_source_outscale_cas_test.go @@ -72,17 +72,25 @@ func testAccDataCheckOutscaleCasDestroy(s *terraform.State) error { func testAccDataOutscaleOAPICasConfig(ca_pem string) string { return fmt.Sprintf(` -resource "outscale_ca" "ca_test" { +resource "outscale_ca" "ca_test" { ca_pem = %[1]q description = "Ca testacc create" } -data "outscale_cas" "cas_data" { - filter { - name = "ca_ids" - values = ["${outscale_ca.ca_test.id}"] - } +resource "outscale_ca" "ca_test2" { + ca_pem = %[1]q + description = "Ca testacc create2" +} + +data "outscale_cas" "cas_data" { + filter { + name = "ca_ids" + values = [outscale_ca.ca_test.id] + } + filter { + name = "description" + values = ["Ca testacc create2"] + } } -data "outscale_cas" "all_cas" {} `, ca_pem) } diff --git a/outscale/data_source_outscale_flexible_gpu_test.go b/outscale/data_source_outscale_flexible_gpu_test.go index 9ed6ee97d..0cae0b64d 100644 --- a/outscale/data_source_outscale_flexible_gpu_test.go +++ b/outscale/data_source_outscale_flexible_gpu_test.go @@ -2,15 +2,14 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccDataSourceOutscaleOAPIFlexibleGpu_basic(t *testing.T) { t.Parallel() - region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,18 +18,18 @@ func TestAccDataSourceOutscaleOAPIFlexibleGpu_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIFlexibleGpuConfig(region, region), + Config: testAccDataSourceOutscaleOAPIFlexibleGpuConfig(utils.GetRegion()), }, }, }) } -func testAccDataSourceOutscaleOAPIFlexibleGpuConfig(region, region1 string) string { +func testAccDataSourceOutscaleOAPIFlexibleGpuConfig(region string) string { return fmt.Sprintf(` - resource "outscale_flexible_gpu" "fGPU-data1" { + resource "outscale_flexible_gpu" "fGPU-1" { model_name = "nvidia-p6" generation = "v5" - subregion_name = "%s" + subregion_name = "%sa" delete_on_vm_deletion = true } @@ -57,8 +56,8 @@ func testAccDataSourceOutscaleOAPIFlexibleGpuConfig(region, region1 string) stri } filter { name = "subregion_names" - values = ["%s"] + values = ["%[1]s"] } } - `, region, region) + `, region) } diff --git a/outscale/data_source_outscale_flexible_gpus_test.go b/outscale/data_source_outscale_flexible_gpus_test.go index 9cd09dcc6..37b2abea0 100644 --- a/outscale/data_source_outscale_flexible_gpus_test.go +++ b/outscale/data_source_outscale_flexible_gpus_test.go @@ -2,15 +2,14 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccDataSourceOutscaleOAPIFlexibleGpus_basic(t *testing.T) { t.Parallel() - region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,18 +18,18 @@ func TestAccDataSourceOutscaleOAPIFlexibleGpus_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIFlexibleGpusConfig(region, region), + Config: testAccDataSourceOutscaleOAPIFlexibleGpusConfig(utils.GetRegion()), }, }, }) } -func testAccDataSourceOutscaleOAPIFlexibleGpusConfig(region, region1 string) string { +func testAccDataSourceOutscaleOAPIFlexibleGpusConfig(region string) string { return fmt.Sprintf(` resource "outscale_flexible_gpu" "fGPUS-1" { model_name = "nvidia-p6" generation = "v5" - subregion_name = "%s" + subregion_name = "%sb" delete_on_vm_deletion = true } @@ -57,7 +56,7 @@ func testAccDataSourceOutscaleOAPIFlexibleGpusConfig(region, region1 string) str } filter { name = "subregion_names" - values = ["%s"] + values = ["%[1]s"] } } `, region, region) diff --git a/outscale/data_source_outscale_image_export_task_test.go b/outscale/data_source_outscale_image_export_task_test.go index 2c56b61fc..185f349bc 100644 --- a/outscale/data_source_outscale_image_export_task_test.go +++ b/outscale/data_source_outscale_image_export_task_test.go @@ -7,13 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccOutscaleOAPIImageExportTaskDataSource_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") imageName := acctest.RandomWithPrefix("test-image-name") if os.Getenv("TEST_QUOTA") == "true" { @@ -24,7 +24,7 @@ func TestAccOutscaleOAPIImageExportTaskDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIImageExportTaskDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccOutscaleOAPIImageExportTaskDataSourceConfig(omi, "tinav4.c2r2p2", utils.GetRegion(), imageName), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleImageExportTaskDataSourceID("data.outscale_image_export_task.test"), ), diff --git a/outscale/data_source_outscale_image_export_tasks_test.go b/outscale/data_source_outscale_image_export_tasks_test.go index baee706e0..57dbb22e8 100644 --- a/outscale/data_source_outscale_image_export_tasks_test.go +++ b/outscale/data_source_outscale_image_export_tasks_test.go @@ -6,13 +6,13 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccOutscaleOAPIImageExportTasksDataSource_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") imageName := acctest.RandomWithPrefix("test-image-name") if os.Getenv("TEST_QUOTA") == "true" { @@ -23,7 +23,7 @@ func TestAccOutscaleOAPIImageExportTasksDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIImageExportTasksDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccOutscaleOAPIImageExportTasksDataSourceConfig(omi, "tinav4.c2r2p2", utils.GetRegion(), imageName), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleImageExportTaskDataSourceID("outscale_image_export_task.outscale_image_export_task"), ), diff --git a/outscale/data_source_outscale_image_test.go b/outscale/data_source_outscale_image_test.go index 6d14b2437..c9a3a7c05 100644 --- a/outscale/data_source_outscale_image_test.go +++ b/outscale/data_source_outscale_image_test.go @@ -8,12 +8,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIImageDataSource_Instance(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") imageName := fmt.Sprintf("image-test-%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ @@ -23,7 +23,7 @@ func TestAccOutscaleOAPIImageDataSource_Instance(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIImageConfigBasic(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccCheckOutscaleOAPIImageConfigBasic(omi, "tinav4.c2r2p2", utils.GetRegion(), imageName), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIImageDataSourceID("data.outscale_image.nat_ami"), resource.TestCheckResourceAttr("data.outscale_image.nat_ami", "architecture", "x86_64"), @@ -36,7 +36,6 @@ func TestAccOutscaleOAPIImageDataSource_Instance(t *testing.T) { func TestAccOutscaleOAPIImageDataSource_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") imageName := fmt.Sprintf("image-test-%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ @@ -46,7 +45,7 @@ func TestAccOutscaleOAPIImageDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIImageDataSourceBasicConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccCheckOutscaleOAPIImageDataSourceBasicConfig(omi, "tinav4.c2r2p2", utils.GetRegion(), imageName), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIImageDataSourceID("data.outscale_image.omi"), ), diff --git a/outscale/data_source_outscale_images_test.go b/outscale/data_source_outscale_images_test.go index ef9fb081f..bf74ab817 100644 --- a/outscale/data_source_outscale_images_test.go +++ b/outscale/data_source_outscale_images_test.go @@ -8,12 +8,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIImagesDataSource_Instance(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") imageName := fmt.Sprintf("image-test-%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ @@ -23,7 +23,7 @@ func TestAccOutscaleOAPIImagesDataSource_Instance(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIImagesDataSourceConfig(omi, "tinav4.c2r2p2", region, imageName), + Config: testAccCheckOutscaleOAPIImagesDataSourceConfig(omi, "tinav4.c2r2p2", utils.GetRegion(), imageName), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIImagesDataSourceID("data.outscale_images.nat_ami"), ), diff --git a/outscale/data_source_outscale_load_balancer_tags_test.go b/outscale/data_source_outscale_load_balancer_tags_test.go index a80544afb..7b44ef61a 100644 --- a/outscale/data_source_outscale_load_balancer_tags_test.go +++ b/outscale/data_source_outscale_load_balancer_tags_test.go @@ -2,19 +2,17 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIDSLoadBalancerTags_basic(t *testing.T) { t.Parallel() r := acctest.RandString(4) - region := os.Getenv("OUTSCALE_REGION") - zone := fmt.Sprintf("%sa", region) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -23,7 +21,7 @@ func TestAccOutscaleOAPIDSLoadBalancerTags_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: getTestAccDSODSutscaleOAPILBUDSTagsConfig(r, zone), + Config: getTestAccDSODSutscaleOAPILBUDSTagsConfig(r, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckODSutscaleOAPILBUDSTagsExists("data.outscale_load_balancer_tags.testds"), resource.TestCheckResourceAttr( @@ -51,7 +49,7 @@ func testAccCheckODSutscaleOAPILBUDSTagsExists(n string) resource.TestCheckFunc func getTestAccDSODSutscaleOAPILBUDSTagsConfig(r string, zone string) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { - subregion_names = ["%s"] + subregion_names = ["%sa"] load_balancer_name = "foobar-terraform-elb-%s" listeners { diff --git a/outscale/data_source_outscale_load_balancer_test.go b/outscale/data_source_outscale_load_balancer_test.go index 73b5c7d9c..66349b730 100644 --- a/outscale/data_source_outscale_load_balancer_test.go +++ b/outscale/data_source_outscale_load_balancer_test.go @@ -2,10 +2,10 @@ package outscale import ( "fmt" - "os" "testing" oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) @@ -14,8 +14,7 @@ func TestAccOutscaleOAPIDSLBU_basic(t *testing.T) { t.Parallel() var conf oscgo.LoadBalancer - region := os.Getenv("OUTSCALE_REGION") - zone := fmt.Sprintf("%sa", region) + zone := fmt.Sprintf("%sa", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) diff --git a/outscale/data_source_outscale_load_balancers_test.go b/outscale/data_source_outscale_load_balancers_test.go index 958eeafdc..31519e866 100644 --- a/outscale/data_source_outscale_load_balancers_test.go +++ b/outscale/data_source_outscale_load_balancers_test.go @@ -2,7 +2,6 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -11,8 +10,7 @@ import ( func TestAccOutscaleOAPIDSLBSU_basic(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") - zone := fmt.Sprintf("%sa", region) + region := fmt.Sprintf("%sa", utils.GetRegion()) numLbu := utils.RandIntRange(0, 50) resource.Test(t, resource.TestCase{ @@ -24,7 +22,7 @@ func TestAccOutscaleOAPIDSLBSU_basic(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPILBUDestroy, Steps: []resource.TestStep{ { - Config: testAccDSOutscaleOAPILBsUConfig(zone, numLbu), + Config: testAccDSOutscaleOAPILBsUConfig(region, numLbu), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_load_balancers.test", "load_balancer.#", "1"), )}, @@ -32,10 +30,10 @@ func TestAccOutscaleOAPIDSLBSU_basic(t *testing.T) { }) } -func testAccDSOutscaleOAPILBsUConfig(zone string, numLbu int) string { +func testAccDSOutscaleOAPILBsUConfig(region string, numLbu int) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { - subregion_names = ["%s"] + subregion_names = ["%sa"] load_balancer_name = "foobar-terraform-elb%d" listeners { @@ -56,5 +54,5 @@ func testAccDSOutscaleOAPILBsUConfig(zone string, numLbu int) string { data "outscale_load_balancers" "test" { load_balancer_name = [outscale_load_balancer.bar.id] } -`, zone, numLbu) +`, region, numLbu) } diff --git a/outscale/data_source_outscale_net_access_point_services_test.go b/outscale/data_source_outscale_net_access_point_services_test.go index a98790727..b1b624dc9 100644 --- a/outscale/data_source_outscale_net_access_point_services_test.go +++ b/outscale/data_source_outscale_net_access_point_services_test.go @@ -2,15 +2,15 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccDataSourceOutscaleOAPINetAccessPointServices_basic(t *testing.T) { t.Parallel() - serviceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) + serviceName := fmt.Sprintf("com.outscale.%s.api", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPINetAccessPointServices_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(serviceName, serviceName), + Config: testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(serviceName), }, }, }) } -func testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(sName, sName2 string) string { +func testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(sName string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -38,7 +38,7 @@ func testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(sName, sName2 str resource "outscale_net_access_point" "net_access_point_1" { net_id = outscale_net.outscale_net.net_id route_table_ids = [outscale_route_table.route_table-1.route_table_id] - service_name = "%s" + service_name = "%[1]s" tags { key = "name" value = "terraform-Net-Access-Point" @@ -49,11 +49,11 @@ func testAccDataSourceOutscaleOAPINetAccessPointServicesConfig(sName, sName2 str data "outscale_net_access_point_services" "all-services" { filter { name = "service_names" - values = [ "%s"] + values = [ "%[1]s"] } } data "outscale_net_access_point_services" "all-services2" { } - `, sName, sName2) + `, sName) } diff --git a/outscale/data_source_outscale_net_access_point_test.go b/outscale/data_source_outscale_net_access_point_test.go index 94e64510d..20c167603 100644 --- a/outscale/data_source_outscale_net_access_point_test.go +++ b/outscale/data_source_outscale_net_access_point_test.go @@ -2,15 +2,15 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccDataSourceOutscaleOAPINetAccessPoint_basic(t *testing.T) { t.Parallel() - serviceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) + serviceName := fmt.Sprintf("com.outscale.%s.api", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPINetAccessPoint_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPINetAccessPointConfig(serviceName, serviceName), + Config: testAccDataSourceOutscaleOAPINetAccessPointConfig(serviceName), }, }, }) } -func testAccDataSourceOutscaleOAPINetAccessPointConfig(sName, sName2 string) string { +func testAccDataSourceOutscaleOAPINetAccessPointConfig(sName string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -38,7 +38,7 @@ func testAccDataSourceOutscaleOAPINetAccessPointConfig(sName, sName2 string) str resource "outscale_net_access_point" "net_access_point_1" { net_id = outscale_net.outscale_net.net_id route_table_ids = [outscale_route_table.route_table-1.route_table_id] - service_name = "%s" + service_name = "%[1]s" tags { key = "name" value = "terraform-Net-Access-Point" @@ -57,7 +57,7 @@ func testAccDataSourceOutscaleOAPINetAccessPointConfig(sName, sName2 string) str } filter { name = "service_names" - values = [ "%s"] + values = [ "%[1]s"] } filter { name = "states" @@ -73,5 +73,5 @@ func testAccDataSourceOutscaleOAPINetAccessPointConfig(sName, sName2 string) str } } - `, sName, sName2) + `, sName) } diff --git a/outscale/data_source_outscale_net_access_points_test.go b/outscale/data_source_outscale_net_access_points_test.go index 71e166f3c..808bf4025 100644 --- a/outscale/data_source_outscale_net_access_points_test.go +++ b/outscale/data_source_outscale_net_access_points_test.go @@ -2,15 +2,15 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccDataSourceOutscaleOAPINetAccessPoints_basic(t *testing.T) { t.Parallel() - serviceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) + serviceName := fmt.Sprintf("com.outscale.%s.api", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,13 +19,13 @@ func TestAccDataSourceOutscaleOAPINetAccessPoints_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPINetAccessPointsConfig(serviceName, serviceName), + Config: testAccDataSourceOutscaleOAPINetAccessPointsConfig(serviceName), }, }, }) } -func testAccDataSourceOutscaleOAPINetAccessPointsConfig(sName, sName2 string) string { +func testAccDataSourceOutscaleOAPINetAccessPointsConfig(sName string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -38,7 +38,7 @@ func testAccDataSourceOutscaleOAPINetAccessPointsConfig(sName, sName2 string) st resource "outscale_net_access_point" "net_access_point_1" { net_id = outscale_net.outscale_net.net_id route_table_ids = [outscale_route_table.route_table-1.route_table_id] - service_name = "%s" + service_name = "%[1]s" tags { key = "name" value = "terraform-Net-Access-Point" @@ -57,7 +57,7 @@ func testAccDataSourceOutscaleOAPINetAccessPointsConfig(sName, sName2 string) st } filter { name = "service_names" - values = [ "%s"] + values = [ "%[1]s"] } filter { name = "states" @@ -73,5 +73,5 @@ func testAccDataSourceOutscaleOAPINetAccessPointsConfig(sName, sName2 string) st } } - `, sName, sName2) + `, sName) } diff --git a/outscale/data_source_outscale_nic_test.go b/outscale/data_source_outscale_nic_test.go index 541d815e9..eac261391 100644 --- a/outscale/data_source_outscale_nic_test.go +++ b/outscale/data_source_outscale_nic_test.go @@ -3,7 +3,6 @@ package outscale import ( "context" "fmt" - "os" "strings" oscgo "github.com/outscale/osc-sdk-go/v2" @@ -19,7 +18,6 @@ import ( func TestAccOutscaleOAPIENIDataSource_basic(t *testing.T) { t.Parallel() var conf oscgo.Nic - subregion := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -28,10 +26,10 @@ func TestAccOutscaleOAPIENIDataSource_basic(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIENIDataSourceConfig(subregion), + Config: testAccOutscaleOAPIENIDataSourceConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), - testAccCheckOutscaleOAPIENIAttributes(&conf, subregion), + testAccCheckOutscaleOAPIENIAttributes(&conf, utils.GetRegion()), ), }, }, @@ -42,11 +40,6 @@ func TestAccOutscaleOAPIENIDataSource_basicFilter(t *testing.T) { t.Parallel() var conf oscgo.Nic - subregion := os.Getenv("OUTSCALE_REGION") - if subregion == "" { - subregion = "in-west-2" - } - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "outscale_nic.outscale_nic", @@ -54,10 +47,10 @@ func TestAccOutscaleOAPIENIDataSource_basicFilter(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIENIDataSourceConfigFilter, + Config: testAccOutscaleOAPIENIDataSourceConfigFilter(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), - testAccCheckOutscaleOAPIENIAttributes(&conf, subregion), + testAccCheckOutscaleOAPIENIAttributes(&conf, utils.GetRegion()), ), }, }, @@ -149,12 +142,12 @@ func testAccOutscaleOAPIENIDataSourceConfig(subregion string) string { resource "outscale_subnet" "outscale_subnet" { subregion_name = "%sa" - ip_range = "10.0.0.0/16" - net_id = "${outscale_net.outscale_net.id}" + ip_range = "10.0.0.0/24" + net_id = outscale_net.outscale_net.id } resource "outscale_nic" "outscale_nic" { - subnet_id = "${outscale_subnet.outscale_subnet.id}" + subnet_id = outscale_subnet.outscale_subnet.id tags { value = "tf-value" key = "tf-key" @@ -162,12 +155,13 @@ func testAccOutscaleOAPIENIDataSourceConfig(subregion string) string { } data "outscale_nic" "outscale_nic" { - nic_id = "${outscale_nic.outscale_nic.id}" + nic_id = outscale_nic.outscale_nic.id } `, subregion) } -const testAccOutscaleOAPIENIDataSourceConfigFilter = ` +func testAccOutscaleOAPIENIDataSourceConfigFilter(subregion string) string { + return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -178,13 +172,13 @@ const testAccOutscaleOAPIENIDataSourceConfigFilter = ` } resource "outscale_subnet" "outscale_subnet" { - subregion_name = "eu-west-2a" - ip_range = "10.0.0.0/16" - net_id = "${outscale_net.outscale_net.id}" + subregion_name = "%sb" + ip_range = "10.0.0.0/24" + net_id = outscale_net.outscale_net.id } resource "outscale_nic" "outscale_nic" { - subnet_id = "${outscale_subnet.outscale_subnet.id}" + subnet_id = outscale_subnet.outscale_subnet.id tags { value = "tf-value" key = "tf-key" @@ -194,7 +188,8 @@ const testAccOutscaleOAPIENIDataSourceConfigFilter = ` data "outscale_nic" "outscale_nic" { filter { name = "nic_ids" - values = ["${outscale_nic.outscale_nic.nic_id}"] - } + values = [outscale_nic.outscale_nic.nic_id] + } } -` +`, subregion) +} diff --git a/outscale/data_source_outscale_nics_test.go b/outscale/data_source_outscale_nics_test.go index cf9ba01a5..014697c88 100644 --- a/outscale/data_source_outscale_nics_test.go +++ b/outscale/data_source_outscale_nics_test.go @@ -2,21 +2,20 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPINicsDataSource(t *testing.T) { - subregion := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPINicsDataSourceConfig(subregion), + Config: testAccCheckOutscaleOAPINicsDataSourceConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_nics.outscale_nics", "nics.#", "1"), ), @@ -37,19 +36,19 @@ func testAccCheckOutscaleOAPINicsDataSourceConfig(subregion string) string { } resource "outscale_subnet" "outscale_subnet" { - subregion_name = "%sa" - ip_range = "10.0.0.0/16" - net_id = "${outscale_net.outscale_net.net_id}" + subregion_name = "%sb" + ip_range = "10.0.0.0/24" + net_id = outscale_net.outscale_net.net_id } resource "outscale_nic" "outscale_nic" { - subnet_id = "${outscale_subnet.outscale_subnet.subnet_id}" + subnet_id = outscale_subnet.outscale_subnet.subnet_id } data "outscale_nics" "outscale_nics" { filter { name = "nic_ids" - values = ["${outscale_nic.outscale_nic.id}"] + values = [outscale_nic.outscale_nic.id] } } `, subregion) diff --git a/outscale/data_source_outscale_public_ip_test.go b/outscale/data_source_outscale_public_ip_test.go index b25290137..d3c707930 100644 --- a/outscale/data_source_outscale_public_ip_test.go +++ b/outscale/data_source_outscale_public_ip_test.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccDataSourceOutscaleOAPIPublicIP(t *testing.T) { @@ -35,7 +36,7 @@ func TestAccDataSourceOutscaleOAPIPublicIPWithVM(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi), + Config: testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi, utils.GetRegion()), }, }, }) @@ -125,7 +126,7 @@ const testAccDataSourceOutscaleOAPIPublicIPConfigWithTags = ` } ` -func testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi string) string { +func testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi, region string) string { return fmt.Sprintf(` resource "outscale_vm" "outscale_vm" { image_id = "%s" @@ -140,7 +141,7 @@ func testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi string) string { } tags { key = "platform" - value = "eu-west-2" + value = "%[2]s" } tags { key = "project" @@ -159,5 +160,5 @@ func testAccDataSourceOutscaleOAPIPublicIPConfigwithVM(omi string) string { values = [outscale_public_ip_link.outscale_public_ip_link.link_public_ip_id] } } - `, omi) + `, omi, region) } diff --git a/outscale/data_source_outscale_snapshot_export_task_test.go b/outscale/data_source_outscale_snapshot_export_task_test.go index d1bfcd7ff..7ea430d4c 100644 --- a/outscale/data_source_outscale_snapshot_export_task_test.go +++ b/outscale/data_source_outscale_snapshot_export_task_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -20,7 +21,7 @@ func TestAccOutscaleOAPISnapshotExportTaskDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotExportTaskDataSourceConfig(imageName), + Config: testAccOutscaleOAPISnapshotExportTaskDataSourceConfig(imageName, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleSnapshotExportTaskDataSourceID("data.outscale_snapshot_export_task.export_task"), ), @@ -44,10 +45,10 @@ func testAccCheckOutscaleSnapshotExportTaskDataSourceID(n string) resource.TestC } } -func testAccOutscaleOAPISnapshotExportTaskDataSourceConfig(testName string) string { +func testAccOutscaleOAPISnapshotExportTaskDataSourceConfig(testName, region string) string { var stringTemplate = ` resource "outscale_volume" "outscale_volume_snap" { - subregion_name = "eu-west-2a" + subregion_name = "%[2]sa" size = 10 } diff --git a/outscale/data_source_outscale_snapshot_export_tasks_test.go b/outscale/data_source_outscale_snapshot_export_tasks_test.go index 10e2553b5..92277819c 100644 --- a/outscale/data_source_outscale_snapshot_export_tasks_test.go +++ b/outscale/data_source_outscale_snapshot_export_tasks_test.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPISnapshotExportTasksDataSource_basic(t *testing.T) { @@ -17,7 +18,7 @@ func TestAccOutscaleOAPISnapshotExportTasksDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(imageName), + Config: testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(imageName, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleSnapshotExportTaskDataSourceID("data.outscale_snapshot_export_tasks.export_tasks"), ), @@ -26,14 +27,14 @@ func TestAccOutscaleOAPISnapshotExportTasksDataSource_basic(t *testing.T) { }) } -func testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(testName string) string { - var stringTemplate = ` +func testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(testName, region string) string { + return fmt.Sprintf(` resource "outscale_volume" "outscale_volume_snap" { - subregion_name = "eu-west-2a" + subregion_name = "%[2]sa" size = 10 } - resource "outscale_snapshot" "outscale_snapshot" { + resource "outscale_snapshot" "outscale_snapshot" { volume_id = outscale_volume.outscale_volume_snap.volume_id } @@ -41,7 +42,7 @@ func testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(testName string) str snapshot_id = outscale_snapshot.outscale_snapshot.snapshot_id osu_export { disk_image_format = "qcow2" - osu_bucket = "%s" + osu_bucket = "%[1]s" osu_prefix = "new-export" } } @@ -52,6 +53,5 @@ func testAccOutscaleOAPISnapshotExportTasksDataSourceConfig(testName string) str values = [outscale_snapshot_export_task.outscale_snapshot_export_task.id] } } - ` - return fmt.Sprintf(stringTemplate, testName) +`, testName, region) } diff --git a/outscale/data_source_outscale_snapshot_test.go b/outscale/data_source_outscale_snapshot_test.go index e00e1f673..551325e3f 100644 --- a/outscale/data_source_outscale_snapshot_test.go +++ b/outscale/data_source_outscale_snapshot_test.go @@ -2,23 +2,22 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPISnapshotDataSource_basic(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISnapshotDataSourceConfig(region), + Config: testAccCheckOutscaleOAPISnapshotDataSourceConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPISnapshotDataSourceID("data.outscale_snapshot.snapshot"), resource.TestCheckResourceAttr("data.outscale_snapshot.snapshot", "volume_size", "1"), @@ -30,14 +29,13 @@ func TestAccOutscaleOAPISnapshotDataSource_basic(t *testing.T) { func TestAccOutscaleOAPISnapshotDataSource_multipleFilters(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISnapshotDataSourceConfigWithMultipleFilters(region), + Config: testAccCheckOutscaleOAPISnapshotDataSourceConfigWithMultipleFilters(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPISnapshotDataSourceID("data.outscale_snapshot.snapshot"), resource.TestCheckResourceAttr("data.outscale_snapshot.snapshot", "volume_size", "10"), @@ -73,7 +71,7 @@ func testAccCheckOutscaleOAPISnapshotDataSourceConfig(region string) string { } data "outscale_snapshot" "snapshot" { - snapshot_id = "${outscale_snapshot.snapshot.id}" + snapshot_id = outscale_snapshot.snapshot.id } `, region) } @@ -86,11 +84,11 @@ func testAccCheckOutscaleOAPISnapshotDataSourceConfigWithMultipleFilters(region } resource "outscale_snapshot" "snapshot" { - volume_id = "${outscale_volume.external1.id}" + volume_id = outscale_volume.external1.id } data "outscale_snapshot" "snapshot" { - snapshot_id = "${outscale_snapshot.snapshot.id}" + snapshot_id = outscale_snapshot.snapshot.id filter { name = "volume_sizes" diff --git a/outscale/data_source_outscale_snapshots_test.go b/outscale/data_source_outscale_snapshots_test.go index 43c968107..04fc3bf5d 100644 --- a/outscale/data_source_outscale_snapshots_test.go +++ b/outscale/data_source_outscale_snapshots_test.go @@ -1,9 +1,11 @@ package outscale import ( + "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPISnapshotsDataSource_basic(t *testing.T) { @@ -12,7 +14,7 @@ func TestAccOutscaleOAPISnapshotsDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISnapshotsDataSourceConfig, + Config: testAccCheckOutscaleOAPISnapshotsDataSourceConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_snapshots.outscale_snapshots", "snapshots.#", "1"), ), @@ -21,9 +23,10 @@ func TestAccOutscaleOAPISnapshotsDataSource_basic(t *testing.T) { }) } -const testAccCheckOutscaleOAPISnapshotsDataSourceConfig = ` +func testAccCheckOutscaleOAPISnapshotsDataSourceConfig(region string) string { + return fmt.Sprintf(` resource "outscale_volume" "example" { - subregion_name = "eu-west-2a" + subregion_name = "%sa" size = 1 } @@ -34,4 +37,5 @@ const testAccCheckOutscaleOAPISnapshotsDataSourceConfig = ` data "outscale_snapshots" "outscale_snapshots" { snapshot_id = ["${outscale_snapshot.snapshot.id}"] } -` +`, region) +} diff --git a/outscale/data_source_outscale_subnet_test.go b/outscale/data_source_outscale_subnet_test.go index c75165d77..2c155b6ec 100644 --- a/outscale/data_source_outscale_subnet_test.go +++ b/outscale/data_source_outscale_subnet_test.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccDataSourceOutscaleOAPISubnet(t *testing.T) { @@ -15,7 +16,7 @@ func TestAccDataSourceOutscaleOAPISubnet(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetConfig, + Config: testAccDataSourceOutscaleOAPISubnetConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccDataSourceOutscaleOAPISubnetCheck("data.outscale_subnet.by_id"), testAccDataSourceOutscaleOAPISubnetCheck("data.outscale_subnet.by_filter"), @@ -32,7 +33,7 @@ func TestAccDataSourceOutscaleOAPISubnet_withAvailableIpsCountsFilter(t *testing Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter(), + Config: testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccDataSourceOutscaleOAPISubnetCheck("data.outscale_subnet.by_filter"), ), @@ -66,7 +67,7 @@ func testAccDataSourceOutscaleOAPISubnetCheck(name string) resource.TestCheckFun if attr["ip_range"] != "10.0.0.0/16" { return fmt.Errorf("bad ip_range %s", attr["ip_range"]) } - if attr["subregion_name"] != "eu-west-2a" { + if attr["subregion_name"] != utils.GetRegion() { return fmt.Errorf("bad subregion_name %s", attr["subregion_name"]) } @@ -74,35 +75,36 @@ func testAccDataSourceOutscaleOAPISubnetCheck(name string) resource.TestCheckFun } } -const testAccDataSourceOutscaleOAPISubnetConfig = ` - resource "outscale_net" "outscale_net" { - ip_range = "10.0.0.0/16" - tags { - key = "Name" - value = "testacc-subet-ds" +func testAccDataSourceOutscaleOAPISubnetConfig(region string) string { + return fmt.Sprintf(` + resource "outscale_net" "outscale_net" { + ip_range = "10.0.0.0/16" + tags { + key = "Name" + value = "testacc-subet-ds" + } } - } - resource "outscale_subnet" "outscale_subnet" { - net_id = outscale_net.outscale_net.net_id - ip_range = "10.0.0.0/16" - subregion_name = "eu-west-2a" - } + resource "outscale_subnet" "outscale_subnet" { + net_id = outscale_net.outscale_net.net_id + ip_range = "10.0.0.0/24" + subregion_name = "%sa" + } - data "outscale_subnet" "by_id" { - subnet_id = outscale_subnet.outscale_subnet.id - } + data "outscale_subnet" "by_id" { + subnet_id = outscale_subnet.outscale_subnet.id + } - data "outscale_subnet" "by_filter" { - filter { - name = "subnet_ids" - values = [outscale_subnet.outscale_subnet.id] + data "outscale_subnet" "by_filter" { + filter { + name = "subnet_ids" + values = [outscale_subnet.outscale_subnet.id] } - } -` + `, region) +} -func testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter() string { - return ` +func testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter(region string) string { + return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" tags { @@ -112,8 +114,8 @@ func testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter() string { } resource "outscale_subnet" "outscale_subnet" { - subregion_name = "eu-west-2a" - ip_range = "10.0.0.0/16" + subregion_name = "%sb" + ip_range = "10.0.0.0/24" net_id = outscale_net.outscale_net.net_id } @@ -123,5 +125,5 @@ func testAccDataSourceOutscaleOAPISubnetWithAvailableIpsCountsFilter() string { values = [outscale_subnet.outscale_subnet.available_ips_count] } } - ` + `, region) } diff --git a/outscale/data_source_outscale_subnets_test.go b/outscale/data_source_outscale_subnets_test.go index 6b686d957..27039b9d6 100644 --- a/outscale/data_source_outscale_subnets_test.go +++ b/outscale/data_source_outscale_subnets_test.go @@ -17,7 +17,7 @@ func TestAccDataSourceOutscaleOAPISubnets(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetsConfig(rInt), + Config: testAccDataSourceOutscaleOAPISubnetsConfig(rInt, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.outscale_subnets.by_filter", "subnets.#", "1"), ), @@ -33,16 +33,16 @@ func TestAccDataSourceOutscaleOAPISubnets_withAvailableIpsCountsFilter(t *testin Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter(), + Config: testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter(utils.GetRegion()), }, }, }) } -func testAccDataSourceOutscaleOAPISubnetsConfig(rInt int) string { +func testAccDataSourceOutscaleOAPISubnetsConfig(rInt int, region string) string { return fmt.Sprintf(` resource "outscale_net" "net" { - ip_range = "172.%[1]d.123.0/24" + ip_range = "10.%[1]d.123.0/24" tags { key = "Name" @@ -51,8 +51,8 @@ func testAccDataSourceOutscaleOAPISubnetsConfig(rInt int) string { } resource "outscale_subnet" "subnet" { - ip_range = "172.%[1]d.123.0/24" - subregion_name = "eu-west-2a" + ip_range = "10.%[1]d.123.0/24" + subregion_name = "%[2]sa" net_id = "${outscale_net.net.id}" tags { @@ -67,11 +67,11 @@ func testAccDataSourceOutscaleOAPISubnetsConfig(rInt int) string { values = ["${outscale_subnet.subnet.id}"] } } - `, rInt) + `, rInt, region) } -func testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter() string { - return ` +func testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter(region string) string { + return fmt.Sprintf(` resource "outscale_net" "outscale_net1" { ip_range = "10.0.0.0/16" tags { @@ -89,13 +89,13 @@ func testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter() string { } resource "outscale_subnet" "sub1" { - subregion_name = "eu-west-2a" + subregion_name = "%[1]sa" ip_range = "10.0.0.0/16" net_id = outscale_net.outscale_net1.net_id } resource "outscale_subnet" "sub2" { - subregion_name = "eu-west-2a" + subregion_name = "%[1]sa" ip_range = "10.0.0.0/16" net_id = outscale_net.outscale_net2.net_id } @@ -107,5 +107,5 @@ func testAccDataSourceOutscaleOAPISubnetsWithAvailableIpsCountsFilter() string { values = ["${outscale_subnet.sub1.available_ips_count}", "${outscale_subnet.sub2.available_ips_count}"] } } - ` + `, region) } diff --git a/outscale/data_source_outscale_subregions_test.go b/outscale/data_source_outscale_subregions_test.go index 53f22e455..406dfea18 100644 --- a/outscale/data_source_outscale_subregions_test.go +++ b/outscale/data_source_outscale_subregions_test.go @@ -6,11 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPISubregionsDataSource_Basic(t *testing.T) { t.Parallel() - subregionName := "eu-west-2b" resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,7 +19,7 @@ func TestAccOutscaleOAPISubregionsDataSource_Basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPISubregionsDataSourceConfig(subregionName), + Config: testAccCheckOutscaleOAPISubregionsDataSourceConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPISubregionsDataSourceID("data.outscale_subregions.test"), ), diff --git a/outscale/data_source_outscale_vm_test.go b/outscale/data_source_outscale_vm_test.go index 1486409bf..27066a388 100644 --- a/outscale/data_source_outscale_vm_test.go +++ b/outscale/data_source_outscale_vm_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIVMDataSource_basic(t *testing.T) { @@ -18,7 +19,7 @@ func TestAccOutscaleOAPIVMDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOAPIVMDataSourceConfig(omi, "tinav4.c2r2p2"), + Config: testAccOAPIVMDataSourceConfig(omi, "tinav4.c2r2p2", utils.GetRegion()), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(datasourcceName, "image_id", omi), resource.TestCheckResourceAttr(datasourcceName, "vm_type", "tinav4.c2r2p2"), @@ -29,7 +30,7 @@ func TestAccOutscaleOAPIVMDataSource_basic(t *testing.T) { }) } -func testAccOAPIVMDataSourceConfig(omi, vmType string) string { +func testAccOAPIVMDataSourceConfig(omi, vmType, region string) string { return fmt.Sprintf(` resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" @@ -43,12 +44,12 @@ func testAccOAPIVMDataSourceConfig(omi, vmType string) string { resource "outscale_subnet" "outscale_subnet" { net_id = outscale_net.outscale_net.net_id ip_range = "10.0.0.0/24" - subregion_name = "eu-west-2a" + subregion_name = "%[3]sa" } - resource "outscale_vm" "outscale_vm" { - image_id = "%s" - vm_type = "%s" + resource "outscale_vm" "outscale_vm" { + image_id = "%[1]s" + vm_type = "%[2]s" keypair_name = "terraform-basic" subnet_id = outscale_subnet.outscale_subnet.subnet_id @@ -58,11 +59,11 @@ func testAccOAPIVMDataSourceConfig(omi, vmType string) string { } } - data "outscale_vm" "basic_web" { - filter { + data "outscale_vm" "basic_web" { + filter { name = "vm_ids" values = [outscale_vm.outscale_vm.vm_id] - } + } } - `, omi, vmType) + `, omi, vmType, region) } diff --git a/outscale/data_source_outscale_volume_test.go b/outscale/data_source_outscale_volume_test.go index 316d2e1a1..61e538e1b 100644 --- a/outscale/data_source_outscale_volume_test.go +++ b/outscale/data_source_outscale_volume_test.go @@ -2,23 +2,22 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIVolumeDataSource_basic(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumeDataSourceConfig(region), + Config: testAccCheckOutscaleOAPIVolumeDataSourceConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volume.ebs_volume"), resource.TestCheckResourceAttr("data.outscale_volume.ebs_volume", "size", "10"), @@ -31,14 +30,13 @@ func TestAccOutscaleOAPIVolumeDataSource_basic(t *testing.T) { func TestAccOutscaleOAPIVolumeDataSource_filterByTags(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumeDataSourceConfigFilterByTags(region), + Config: testAccCheckOutscaleOAPIVolumeDataSourceConfigFilterByTags(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volume.ebs_volume"), resource.TestCheckResourceAttr("data.outscale_volume.ebs_volume", "size", "10"), @@ -106,7 +104,7 @@ func testAccCheckOutscaleOAPIVolumeDataSourceConfigFilterByTags(region string) s filter { name = "volume_ids" - values = ["${outscale_volume.example.id}"] + values = ["outscale_volume.example.id"] } } diff --git a/outscale/data_source_outscale_volumes_test.go b/outscale/data_source_outscale_volumes_test.go index e0dd64975..e37e3cee9 100644 --- a/outscale/data_source_outscale_volumes_test.go +++ b/outscale/data_source_outscale_volumes_test.go @@ -6,18 +6,18 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIVolumesDataSource_multipleFilters(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumeDataSourceConfigWithMultipleFilters(region), + Config: testAccCheckOutscaleOAPIVolumeDataSourceConfigWithMultipleFilters(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volumes.ebs_volume"), resource.TestCheckResourceAttr("data.outscale_volumes.ebs_volume", "volumes.0.size", "1"), @@ -30,14 +30,13 @@ func TestAccOutscaleOAPIVolumesDataSource_multipleFilters(t *testing.T) { func TestAccOutscaleOAPIVolumeDataSource_multipleVIdsFilters(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumesDataSourceConfigWithMultipleVolumeIDsFilter(region), + Config: testAccCheckOutscaleOAPIVolumesDataSourceConfigWithMultipleVolumeIDsFilter(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volumes.outscale_volumes"), resource.TestCheckResourceAttr("data.outscale_volumes.outscale_volumes", "volumes.0.size", "40"), @@ -49,7 +48,6 @@ func TestAccOutscaleOAPIVolumeDataSource_multipleVIdsFilters(t *testing.T) { func TestAccOutscaleOAPIVolumesDataSource_withVM(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") omi := os.Getenv("OUTSCALE_IMAGEID") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -59,7 +57,7 @@ func TestAccOutscaleOAPIVolumesDataSource_withVM(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVolumesDataSourceConfigWithVM(region, omi, keypair, sgId), + Config: testAccCheckOutscaleOAPIVolumesDataSourceConfigWithVM(utils.GetRegion(), omi, keypair, sgId), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVolumeDataSourceID("data.outscale_volumes.outscale_volumes"), // resource.TestCheckResourceAttr("data.outscale_volumes.outscale_volumes", "volumes.0.size", "1"), diff --git a/outscale/resource_outscale_dhcp_option_test.go b/outscale/resource_outscale_dhcp_option_test.go index 74f70dd53..9480b76e7 100644 --- a/outscale/resource_outscale_dhcp_option_test.go +++ b/outscale/resource_outscale_dhcp_option_test.go @@ -119,15 +119,15 @@ func TestAccOutscaleOAPIDhcpOptional_withEmptyAttrs(t *testing.T) { func TestAccOutscaleOAPIDhcpOptional_withNet(t *testing.T) { t.Parallel() resourceName := "outscale_dhcp_option.outscale_dhcp_option" - - domainName := fmt.Sprintf("eu-west-2.compute%s.internal", acctest.RandString(3)) + domainName := fmt.Sprintf("%s.compute%s.internal", utils.GetRegion(), acctest.RandString(3)) domainServers := []string{"192.168.12.12", "192.168.12.132"} + tags := &oscgo.Tag{ Key: pointy.String(acctest.RandomWithPrefix("name")), Value: pointy.String(acctest.RandomWithPrefix("test-MZI")), } - domainNameUpdated := fmt.Sprintf("eu-west-2.compute%s.internal", acctest.RandString(3)) + domainNameUpdated := fmt.Sprintf("%s.compute%s.internal", utils.GetRegion(), acctest.RandString(3)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/outscale/resource_outscale_flexible_gpu_link_test.go b/outscale/resource_outscale_flexible_gpu_link_test.go index 03a572baf..b220ba409 100644 --- a/outscale/resource_outscale_flexible_gpu_link_test.go +++ b/outscale/resource_outscale_flexible_gpu_link_test.go @@ -6,11 +6,11 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIFlexibleGpuLink_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,7 +19,7 @@ func TestAccOutscaleOAPIFlexibleGpuLink_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIFlexibleGpuLinkConfig(omi, "tinav5.c2r2p1", region), + Config: testAccOutscaleOAPIFlexibleGpuLinkConfig(omi, "tinav5.c2r2p2", utils.GetRegion()), }, }, }) @@ -31,12 +31,14 @@ func testAccOutscaleOAPIFlexibleGpuLinkConfig(omi, vmType, region string) string image_id = "%s" vm_type = "%s" keypair_name = "terraform-basic" + placement_subregion_name = "%[3]sb" + } resource "outscale_flexible_gpu" "fGPU-1" { model_name = "nvidia-p6" generation = "v5" - subregion_name = "%s" + subregion_name = "%[3]sb" delete_on_vm_deletion = true } diff --git a/outscale/resource_outscale_flexible_gpu_test.go b/outscale/resource_outscale_flexible_gpu_test.go index 97fc01382..e252c4ccc 100644 --- a/outscale/resource_outscale_flexible_gpu_test.go +++ b/outscale/resource_outscale_flexible_gpu_test.go @@ -2,15 +2,14 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPIFlexibleGpu_basic(t *testing.T) { t.Parallel() - region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -19,7 +18,7 @@ func TestAccOutscaleOAPIFlexibleGpu_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIFlexibleGpuConfig(region), + Config: testAccOutscaleOAPIFlexibleGpuConfig(utils.GetRegion()), }, }, }) @@ -30,7 +29,7 @@ func testAccOutscaleOAPIFlexibleGpuConfig(region string) string { resource "outscale_flexible_gpu" "fGPU-1" { model_name = "nvidia-p6" generation = "v5" - subregion_name = "%s" + subregion_name = "%sb" delete_on_vm_deletion = true } diff --git a/outscale/resource_outscale_image_export_task_test.go b/outscale/resource_outscale_image_export_task_test.go index 3a6dd48cf..accd19dbe 100644 --- a/outscale/resource_outscale_image_export_task_test.go +++ b/outscale/resource_outscale_image_export_task_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/hashicorp/terraform/helper/acctest" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -13,7 +14,7 @@ import ( func TestAccOutscaleOAPIImageExportTask_basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() imageName := acctest.RandomWithPrefix("test-image-name") tags := `tags { key = "test" diff --git a/outscale/resource_outscale_image_launch_permission_test.go b/outscale/resource_outscale_image_launch_permission_test.go index a87e65c2f..94829c4a9 100644 --- a/outscale/resource_outscale_image_launch_permission_test.go +++ b/outscale/resource_outscale_image_launch_permission_test.go @@ -19,7 +19,7 @@ import ( func TestAccOutscaleOAPIImageLaunchPermission_Basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() accountID := os.Getenv("OUTSCALE_ACCOUNT") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -68,7 +68,7 @@ func TestAccOutscaleOAPIImageLaunchPermission_Basic(t *testing.T) { func TestAccOutscaleOAPIImageLaunchPermissionDestruction_Basic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() accountID := os.Getenv("OUTSCALE_ACCOUNT") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") diff --git a/outscale/resource_outscale_image_test.go b/outscale/resource_outscale_image_test.go index a34f45ccd..5eeaaa5c5 100644 --- a/outscale/resource_outscale_image_test.go +++ b/outscale/resource_outscale_image_test.go @@ -18,7 +18,7 @@ import ( func TestAccOutscaleOAPIImage_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() var ami oscgo.Image rInt := acctest.RandInt() diff --git a/outscale/resource_outscale_load_balancer_attributes_test.go b/outscale/resource_outscale_load_balancer_attributes_test.go index d9e30292e..36d32f664 100644 --- a/outscale/resource_outscale_load_balancer_attributes_test.go +++ b/outscale/resource_outscale_load_balancer_attributes_test.go @@ -5,10 +5,10 @@ import ( "testing" oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPILBUAttr_basic(t *testing.T) { @@ -25,7 +25,7 @@ func TestAccOutscaleOAPILBUAttr_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILBUAttrConfig(r), + Config: testAccOutscaleOAPILBUAttrConfig(utils.GetRegion(), r), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPILBUAttrExists("outscale_load_balancer_attributes.bar2", &conf), )}, @@ -48,10 +48,10 @@ func testAccCheckOutscaleOAPILBUAttrExists(n string, res *oscgo.AccessLog) resou } } -func testAccOutscaleOAPILBUAttrConfig(r int) string { +func testAccOutscaleOAPILBUAttrConfig(region string, r int) string { return fmt.Sprintf(` resource "outscale_load_balancer" "bar" { - subregion_names = ["eu-west-2a"] + subregion_names = ["%sa"] load_balancer_name = "foobar-terraform-elb-%d" listeners { backend_port = 8000 @@ -74,5 +74,5 @@ resource "outscale_load_balancer_attributes" "bar2" { } load_balancer_name = outscale_load_balancer.bar.id } -`, r) +`, region, r) } diff --git a/outscale/resource_outscale_load_balancer_policy_test.go b/outscale/resource_outscale_load_balancer_policy_test.go index c283bfd3a..9b9da09b4 100644 --- a/outscale/resource_outscale_load_balancer_policy_test.go +++ b/outscale/resource_outscale_load_balancer_policy_test.go @@ -2,19 +2,18 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleCookieStickinessPolicy_basic(t *testing.T) { t.Parallel() - lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5)) - region := os.Getenv("OUTSCALE_REGION") - zone := fmt.Sprintf("%sa", region) + lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(10)) + zone := fmt.Sprintf("%sa", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/outscale/resource_outscale_load_balancer_test.go b/outscale/resource_outscale_load_balancer_test.go index 64819b27c..b5d772a26 100644 --- a/outscale/resource_outscale_load_balancer_test.go +++ b/outscale/resource_outscale_load_balancer_test.go @@ -20,10 +20,8 @@ func TestAccOutscaleOAPILBUBasic(t *testing.T) { var conf oscgo.LoadBalancer resourceName := "outscale_load_balancer.bar" - r := utils.RandIntRange(0, 10) - region := os.Getenv("OUTSCALE_REGION") - zone := fmt.Sprintf("%sa", region) + zone := fmt.Sprintf("%sa", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -200,7 +198,7 @@ resource "outscale_load_balancer" "bar" { } } -`, os.Getenv("OUTSCALE_REGION"), r) +`, utils.GetRegion(), r) } func testAccOutscaleOAPILBUPublicIpConfig(r int) string { diff --git a/outscale/resource_outscale_load_balancer_vms_test.go b/outscale/resource_outscale_load_balancer_vms_test.go index d6c406f78..c996d5477 100644 --- a/outscale/resource_outscale_load_balancer_vms_test.go +++ b/outscale/resource_outscale_load_balancer_vms_test.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-outscale/utils" oscgo "github.com/outscale/osc-sdk-go/v2" ) @@ -15,7 +16,6 @@ func TestAccOutscaleOAPILBUAttachment_basic(t *testing.T) { t.Parallel() var conf oscgo.LoadBalancer omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") testCheckInstanceAttached := func(count int) resource.TestCheckFunc { return func(*terraform.State) error { @@ -36,7 +36,7 @@ func TestAccOutscaleOAPILBUAttachment_basic(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPILBUDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPILBUAttachmentConfig1(omi, region), + Config: testAccOutscaleOAPILBUAttachmentConfig1(omi, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPILBUExists("outscale_load_balancer.bar", &conf), testCheckInstanceAttached(1), diff --git a/outscale/resource_outscale_net_access_point_test.go b/outscale/resource_outscale_net_access_point_test.go index 1853117a9..82b08845e 100644 --- a/outscale/resource_outscale_net_access_point_test.go +++ b/outscale/resource_outscale_net_access_point_test.go @@ -2,14 +2,14 @@ package outscale import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPINetAccessPoint_basic(t *testing.T) { - ServiceName := fmt.Sprintf("com.outscale.%s.api", os.Getenv("OUTSCALE_REGION")) + ServiceName := fmt.Sprintf("com.outscale.%s.api", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { diff --git a/outscale/resource_outscale_nic_link_test.go b/outscale/resource_outscale_nic_link_test.go index 216f80cb4..baf5e1044 100644 --- a/outscale/resource_outscale_nic_link_test.go +++ b/outscale/resource_outscale_nic_link_test.go @@ -21,7 +21,7 @@ import ( func TestAccOutscaleNicLink_Basic(t *testing.T) { var conf oscgo.Nic omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ @@ -49,7 +49,7 @@ func TestAccOutscaleNicLink_Basic(t *testing.T) { func TestAccOutscaleNicLink_importBasic(t *testing.T) { resourceName := "outscale_nic_link.outscale_nic_link" omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() rInt := acctest.RandInt() resource.ParallelTest(t, resource.TestCase{ diff --git a/outscale/resource_outscale_nic_private_ip_test.go b/outscale/resource_outscale_nic_private_ip_test.go index 42f25abf7..14be02c59 100644 --- a/outscale/resource_outscale_nic_private_ip_test.go +++ b/outscale/resource_outscale_nic_private_ip_test.go @@ -2,16 +2,15 @@ package outscale import ( "fmt" - "os" "testing" oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccOutscaleOAPINetworkInterfacePrivateIPBasic(t *testing.T) { - region := os.Getenv("OUTSCALE_REGION") var conf oscgo.Nic resource.Test(t, resource.TestCase{ @@ -21,7 +20,7 @@ func TestAccOutscaleOAPINetworkInterfacePrivateIPBasic(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(region), + Config: testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIENIExists("outscale_nic.outscale_nic", &conf), resource.TestCheckResourceAttr("outscale_nic_private_ip.outscale_nic_private_ip", "private_ips.#", "1"), @@ -33,7 +32,6 @@ func TestAccOutscaleOAPINetworkInterfacePrivateIPBasic(t *testing.T) { } func TestAccOutscaleOAPINetworkInterfacePrivateIP_importBasic(t *testing.T) { - region := os.Getenv("OUTSCALE_REGION") resourceName := "outscale_nic_private_ip.outscale_nic_private_ip" resource.Test(t, resource.TestCase{ @@ -43,7 +41,7 @@ func TestAccOutscaleOAPINetworkInterfacePrivateIP_importBasic(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIENIDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(region), + Config: testAccOutscaleOAPINetworkInterfacePrivateIPConfigBasic(utils.GetRegion()), }, { ResourceName: resourceName, diff --git a/outscale/resource_outscale_nic_test.go b/outscale/resource_outscale_nic_test.go index 468e75a39..5ae5f109f 100644 --- a/outscale/resource_outscale_nic_test.go +++ b/outscale/resource_outscale_nic_test.go @@ -3,7 +3,6 @@ package outscale import ( "context" "fmt" - "os" "reflect" "testing" "time" @@ -18,7 +17,7 @@ import ( func TestAccOutscaleOAPIENI_basic(t *testing.T) { t.Parallel() var conf oscgo.Nic - subregion := os.Getenv("OUTSCALE_REGION") + subregion := utils.GetRegion() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -118,18 +117,18 @@ func testAccOutscaleOAPIENIConfig(subregion string) string { resource "outscale_subnet" "outscale_subnet" { subregion_name = "%sa" ip_range = "10.0.0.0/16" - net_id = "${outscale_net.outscale_net.net_id}" + net_id = outscale_net.outscale_net.net_id } resource "outscale_security_group" "outscale_sg" { description = "sg for terraform tests" security_group_name = "terraform-sg" - net_id = "${outscale_net.outscale_net.net_id}" + net_id = outscale_net.outscale_net.net_id } resource "outscale_nic" "outscale_nic" { - subnet_id = "${outscale_subnet.outscale_subnet.subnet_id}" - security_group_ids = ["${outscale_security_group.outscale_sg.security_group_id}"] + subnet_id = outscale_subnet.outscale_subnet.subnet_id + security_group_ids = [outscale_security_group.outscale_sg.security_group_id] private_ips { is_primary = true @@ -155,20 +154,20 @@ func testAccOutscaleOAPIENIConfigUpdate(subregion string) string { } resource "outscale_subnet" "outscale_subnet" { - subregion_name = "%sa" - ip_range = "10.0.0.0/16" - net_id = "${outscale_net.outscale_net.net_id}" + subregion_name = "%sb" + ip_range = "10.0.0.0/24" + net_id = outscale_net.outscale_net.net_id } resource "outscale_security_group" "outscale_sg" { description = "sg for terraform tests" security_group_name = "terraform-sg" - net_id = "${outscale_net.outscale_net.net_id}" + net_id = outscale_net.outscale_net.net_id } resource "outscale_nic" "outscale_nic" { - subnet_id = "${outscale_subnet.outscale_subnet.subnet_id}" - security_group_ids = ["${outscale_security_group.outscale_sg.security_group_id}"] + subnet_id = outscale_subnet.outscale_subnet.subnet_id + security_group_ids = [outscale_security_group.outscale_sg.security_group_id] private_ips { is_primary = true diff --git a/outscale/resource_outscale_public_ip_link_test.go b/outscale/resource_outscale_public_ip_link_test.go index 6d450c3e7..a16b189a0 100644 --- a/outscale/resource_outscale_public_ip_link_test.go +++ b/outscale/resource_outscale_public_ip_link_test.go @@ -20,7 +20,6 @@ import ( func TestAccOutscaleOAPIPublicIPLink_basic(t *testing.T) { var a oscgo.PublicIp omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -30,7 +29,7 @@ func TestAccOutscaleOAPIPublicIPLink_basic(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIPublicIPLinkDestroy, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIPublicIPLinkConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccOutscaleOAPIPublicIPLinkConfig(omi, "tinav4.c2r2p2", utils.GetRegion(), keypair, sgId), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIPublicIPLExists( "outscale_public_ip.ip", &a), diff --git a/outscale/resource_outscale_public_ip_test.go b/outscale/resource_outscale_public_ip_test.go index 86d36aa6b..ae7fd36a0 100644 --- a/outscale/resource_outscale_public_ip_test.go +++ b/outscale/resource_outscale_public_ip_test.go @@ -9,6 +9,7 @@ import ( "time" oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -39,7 +40,7 @@ func TestAccOutscaleOAPIPublicIP_instance(t *testing.T) { t.Parallel() var conf oscgo.PublicIp omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -74,7 +75,7 @@ func TestAccOutscaleOAPIPublicIP_instance(t *testing.T) { func TestAccOutscaleOAPIPublicIP_associated_user_private_ip(t *testing.T) { var one oscgo.PublicIp omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") diff --git a/outscale/resource_outscale_route_table_test.go b/outscale/resource_outscale_route_table_test.go index 1fd4ccdd7..24c054171 100644 --- a/outscale/resource_outscale_route_table_test.go +++ b/outscale/resource_outscale_route_table_test.go @@ -78,7 +78,6 @@ func TestAccOutscaleOAPIRouteTable_basic(t *testing.T) { func TestAccOutscaleOAPIRouteTable_instance(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") var v oscgo.RouteTable @@ -105,7 +104,7 @@ func TestAccOutscaleOAPIRouteTable_instance(t *testing.T) { CheckDestroy: testAccCheckOAPIRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIRouteTableConfigInstance(omi, "tinav4.c2r2p2", region), + Config: testAccOAPIRouteTableConfigInstance(omi, "tinav4.c2r2p2", utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOAPIRouteTableExists( "outscale_route_table.foo", &v, nil), diff --git a/outscale/resource_outscale_snapshot_attributes_test.go b/outscale/resource_outscale_snapshot_attributes_test.go index 51cbcfa3b..1ce168180 100644 --- a/outscale/resource_outscale_snapshot_attributes_test.go +++ b/outscale/resource_outscale_snapshot_attributes_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPISnapshotAttributes_Basic(t *testing.T) { @@ -18,13 +19,13 @@ func TestAccOutscaleOAPISnapshotAttributes_Basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotAttributesConfig(true, false, accountID), + Config: testAccOutscaleOAPISnapshotAttributesConfig(true, false, accountID, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testCheckResourceGetAttr("outscale_snapshot.test", "id", &snapshotID), ), }, { - Config: testAccOutscaleOAPISnapshotAttributesConfig(true, true, accountID), + Config: testAccOutscaleOAPISnapshotAttributesConfig(true, true, accountID, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testCheckResourceGetAttr("outscale_snapshot.test", "id", &snapshotID), ), @@ -33,10 +34,10 @@ func TestAccOutscaleOAPISnapshotAttributes_Basic(t *testing.T) { }) } -func testAccOutscaleOAPISnapshotAttributesConfig(includeAddition, includeRemoval bool, aid string) string { +func testAccOutscaleOAPISnapshotAttributesConfig(includeAddition, includeRemoval bool, aid, region string) string { base := fmt.Sprintf(` resource "outscale_volume" "description_test" { - subregion_name = "eu-west-2a" + subregion_name = "%[2]sa" size = 1 } @@ -49,10 +50,10 @@ func testAccOutscaleOAPISnapshotAttributesConfig(includeAddition, includeRemoval snapshot_id = "${outscale_snapshot.test.id}" permissions_to_create_volume_removals { - account_ids = ["%s"] + account_ids = ["%[1]s"] } } - `, aid) + `, aid, region) if includeAddition { return base + fmt.Sprintf(` diff --git a/outscale/resource_outscale_snapshot_export_task_test.go b/outscale/resource_outscale_snapshot_export_task_test.go index 30b712557..3d477d563 100644 --- a/outscale/resource_outscale_snapshot_export_task_test.go +++ b/outscale/resource_outscale_snapshot_export_task_test.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/hashicorp/terraform/helper/acctest" + "github.com/terraform-providers/terraform-provider-outscale/utils" ) func TestAccOutscaleOAPISnapshotExportTask_basic(t *testing.T) { @@ -29,13 +30,13 @@ func TestAccOutscaleOAPISnapshotExportTask_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotExportTaskConfig("", osuBucketNames[0]), + Config: testAccOutscaleOAPISnapshotExportTaskConfig("", osuBucketNames[0], utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPISnapshotExportTaskExists("outscale_snapshot_export_task.outscale_snapshot_export_task"), ), }, { - Config: testAccOutscaleOAPISnapshotExportTaskConfig(tags, osuBucketNames[1]), + Config: testAccOutscaleOAPISnapshotExportTaskConfig(tags, osuBucketNames[1], utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPISnapshotExportTaskExists("outscale_snapshot_export_task.outscale_snapshot_export_task"), ), @@ -59,10 +60,10 @@ func testAccCheckOutscaleOAPISnapshotExportTaskExists(n string) resource.TestChe } } -func testAccOutscaleOAPISnapshotExportTaskConfig(tags, osuBucketName string) string { +func testAccOutscaleOAPISnapshotExportTaskConfig(tags, osuBucketName, region string) string { return fmt.Sprintf(` resource "outscale_volume" "outscale_volume_snap" { - subregion_name = "eu-west-2a" + subregion_name = "%[3]sa" size = 10 } resource "outscale_snapshot" "outscale_snapshot" { @@ -77,5 +78,5 @@ resource "outscale_snapshot_export_task" "outscale_snapshot_export_task" { } %[1]s } - `, tags, osuBucketName) + `, tags, osuBucketName, region) } diff --git a/outscale/resource_outscale_snapshot_test.go b/outscale/resource_outscale_snapshot_test.go index 585930aa0..81c22e6ce 100644 --- a/outscale/resource_outscale_snapshot_test.go +++ b/outscale/resource_outscale_snapshot_test.go @@ -3,7 +3,6 @@ package outscale import ( "context" "fmt" - "os" "testing" "time" @@ -16,7 +15,6 @@ import ( func TestAccOutscaleOAPISnapshot_basic(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") var v oscgo.Snapshot resource.Test(t, resource.TestCase{ @@ -24,7 +22,7 @@ func TestAccOutscaleOAPISnapshot_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfig(region), + Config: testAccOutscaleOAPISnapshotConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOAPISnapshotExists("outscale_snapshot.outscale_snapshot", &v), ), @@ -35,7 +33,6 @@ func TestAccOutscaleOAPISnapshot_basic(t *testing.T) { func TestAccOutscaleOAPISnapshot_withDescription(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") var v oscgo.Snapshot resource.Test(t, resource.TestCase{ @@ -43,7 +40,7 @@ func TestAccOutscaleOAPISnapshot_withDescription(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfigWithDescription(region), + Config: testAccOutscaleOAPISnapshotConfigWithDescription(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOAPISnapshotExists("outscale_snapshot.test", &v), resource.TestCheckResourceAttr("outscale_snapshot.test", "description", "Snapshot Acceptance Test"), @@ -55,7 +52,6 @@ func TestAccOutscaleOAPISnapshot_withDescription(t *testing.T) { func TestAccOutscaleOAPISnapshot_CopySnapshot(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") var v oscgo.Snapshot resource.Test(t, resource.TestCase{ @@ -63,7 +59,7 @@ func TestAccOutscaleOAPISnapshot_CopySnapshot(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfigCopySnapshot(region), + Config: testAccOutscaleOAPISnapshotConfigCopySnapshot(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOAPISnapshotExists("outscale_snapshot.test", &v), resource.TestCheckResourceAttr("outscale_snapshot.test", "description", "Target Snapshot Acceptance Test"), @@ -74,7 +70,7 @@ func TestAccOutscaleOAPISnapshot_CopySnapshot(t *testing.T) { } func TestAccOutscaleOAPISnapshot_UpdateTags(t *testing.T) { - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() //var v oscgo.Snapshot resource.Test(t, resource.TestCase{ @@ -94,7 +90,6 @@ func TestAccOutscaleOAPISnapshot_UpdateTags(t *testing.T) { } func TestAccOutscaleOAPISnapshot_importBasic(t *testing.T) { - region := os.Getenv("OUTSCALE_REGION") var v oscgo.Snapshot resource.Test(t, resource.TestCase{ @@ -102,7 +97,7 @@ func TestAccOutscaleOAPISnapshot_importBasic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISnapshotConfig(region), + Config: testAccOutscaleOAPISnapshotConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOAPISnapshotExists("outscale_snapshot.outscale_snapshot", &v), ), diff --git a/outscale/resource_outscale_subnet_test.go b/outscale/resource_outscale_subnet_test.go index e25d90250..c1f2c9feb 100644 --- a/outscale/resource_outscale_subnet_test.go +++ b/outscale/resource_outscale_subnet_test.go @@ -3,7 +3,6 @@ package outscale import ( "context" "fmt" - "os" "strings" "testing" "time" @@ -17,7 +16,6 @@ import ( func TestAccOutscaleOAPISubNet_basic(t *testing.T) { t.Parallel() var conf oscgo.Subnet - region := os.Getenv("OUTSCALE_REGION") resourceName := "outscale_subnet.subnet" @@ -27,14 +25,14 @@ func TestAccOutscaleOAPISubNet_basic(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPISubNetDestroyed, // we need to create the destroyed test case Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPISubnetConfig(region, false), + Config: testAccOutscaleOAPISubnetConfig(utils.GetRegion(), false), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPISubNetExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "map_public_ip_on_launch", "false"), ), }, { - Config: testAccOutscaleOAPISubnetConfig(region, true), + Config: testAccOutscaleOAPISubnetConfig(utils.GetRegion(), true), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPISubNetExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "map_public_ip_on_launch", "true"), @@ -136,9 +134,9 @@ func testAccOutscaleOAPISubnetConfig(region string, mapPublicIpOnLaunch bool) st } resource "outscale_subnet" "subnet" { - ip_range = "10.0.0.0/16" - subregion_name = "%sa" - net_id = "${outscale_net.net.id}" + ip_range = "10.0.0.0/24" + subregion_name = "%sb" + net_id = outscale_net.net.id map_public_ip_on_launch = %v tags { key = "name" diff --git a/outscale/resource_outscale_tags_test.go b/outscale/resource_outscale_tags_test.go index 38fa71ada..a5cfeaa49 100644 --- a/outscale/resource_outscale_tags_test.go +++ b/outscale/resource_outscale_tags_test.go @@ -21,7 +21,6 @@ import ( func TestAccOutscaleOAPIVM_tags(t *testing.T) { v := &oscgo.Vm{} omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") if os.Getenv("TEST_QUOTA") == "true" { resource.Test(t, resource.TestCase{ @@ -30,7 +29,7 @@ func TestAccOutscaleOAPIVM_tags(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOAPIInstanceConfigTags(omi, "tinav4.c2r2p2", region, "keyOriginal", "valueOriginal"), + Config: testAccCheckOAPIInstanceConfigTags(omi, "tinav4.c2r2p2", utils.GetRegion(), "keyOriginal", "valueOriginal"), Check: resource.ComposeTestCheckFunc( oapiTestAccCheckOutscaleVMExists("outscale_vm.vm", v), testAccCheckOAPIVMTags(v, "keyOriginal", "valueOriginal"), @@ -40,7 +39,7 @@ func TestAccOutscaleOAPIVM_tags(t *testing.T) { ), }, { - Config: testAccCheckOAPIInstanceConfigTags(omi, "tinav4.c2r2p2", region, "keyUpdated", "valueUpdated"), + Config: testAccCheckOAPIInstanceConfigTags(omi, "tinav4.c2r2p2", utils.GetRegion(), "keyUpdated", "valueUpdated"), Check: resource.ComposeTestCheckFunc( oapiTestAccCheckOutscaleVMExists("outscale_vm.vm", v), testAccCheckOAPIVMTags(v, "keyUpdated", "valueUpdated"), @@ -161,13 +160,13 @@ func testAccCheckOAPIInstanceConfigTags(omi, vmType, region, key, value string) resource "outscale_subnet" "outscale_subnet" { net_id = outscale_net.outscale_net.net_id ip_range = "10.0.0.0/24" - subregion_name = "eu-west-2a" + subregion_name = "%[3]sa" } resource "outscale_vm" "vm" { image_id = "%s" vm_type = "%s" keypair_name = "terraform-basic" - placement_subregion_name = "%sa" + placement_subregion_name = "%[3]sa" subnet_id = outscale_subnet.outscale_subnet.subnet_id private_ips = ["10.0.0.12"] } diff --git a/outscale/resource_outscale_vm_test.go b/outscale/resource_outscale_vm_test.go index 7308bafd6..4af91c938 100644 --- a/outscale/resource_outscale_vm_test.go +++ b/outscale/resource_outscale_vm_test.go @@ -23,8 +23,8 @@ func TestAccOutscaleOAPIVM_Basic(t *testing.T) { resourceName := "outscale_vm.basic" omi := os.Getenv("OUTSCALE_IMAGEID") - region := fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) keypair := os.Getenv("OUTSCALE_KEYPAIR") + region := fmt.Sprintf("%sa", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -50,8 +50,8 @@ func TestAccOutscaleOAPIVMBehavior_Basic(t *testing.T) { t.Parallel() var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") + region := fmt.Sprintf("%sb", utils.GetRegion()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -89,8 +89,8 @@ func TestAccOutscaleOAPIVM_importBasic(t *testing.T) { server oscgo.Vm resourceName = "outscale_vm.basic" omi = os.Getenv("OUTSCALE_IMAGEID") - region = fmt.Sprintf("%sa", os.Getenv("OUTSCALE_REGION")) keypair = os.Getenv("OUTSCALE_KEYPAIR") + region = fmt.Sprintf("%sb", utils.GetRegion()) ) resource.ParallelTest(t, resource.TestCase{ @@ -106,6 +106,7 @@ func TestAccOutscaleOAPIVM_importBasic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "vm_type", "tinav4.c2r2p2"), resource.TestCheckResourceAttr(resourceName, "keypair_name", keypair), resource.TestCheckResourceAttr(resourceName, "placement_subregion_name", region), + resource.TestCheckResourceAttr(resourceName, "private_ips.#", "1"), resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), ), }, @@ -133,7 +134,6 @@ func testAccCheckOutscaleVMImportStateIDFunc(resourceName string) resource.Impor func TestAccOutscaleOAPIVM_withNicAttached(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") resourceName := "outscale_vm.basic" @@ -143,7 +143,7 @@ func TestAccOutscaleOAPIVM_withNicAttached(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigBasicWithNicAttached(omi, "tinav4.c2r2p2", region, keypair), + Config: testAccCheckOutscaleOAPIVMConfigBasicWithNicAttached(omi, "tinav4.c2r2p2", utils.GetRegion(), keypair), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVMExists(resourceName, &server), testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), @@ -158,7 +158,6 @@ func TestAccOutscaleOAPIVM_withNicAttached(t *testing.T) { func TestAccOutscaleOAPIVM_withTags(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -168,7 +167,7 @@ func TestAccOutscaleOAPIVM_withTags(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM", keypair, sgId), + Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", utils.GetRegion(), "Terraform-VM", keypair, sgId), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), @@ -193,7 +192,7 @@ func TestAccOutscaleOAPIVM_withNics(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, "tinav4.c2r2p2", keypair), + Config: testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, "tinav4.c2r2p2", keypair, utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), @@ -208,10 +207,10 @@ func TestAccOutscaleOAPIVM_withNics(t *testing.T) { } func TestAccOutscaleOAPIVM_Update(t *testing.T) { - region := os.Getenv("OUTSCALE_REGION") omi := os.Getenv("OUTSCALE_IMAGEID") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") + region := utils.GetRegion() var before oscgo.Vm var after oscgo.Vm @@ -245,7 +244,6 @@ func TestAccOutscaleOAPIVM_Update(t *testing.T) { func TestAccOutscaleOAPIVM_WithSubnet(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") resource.Test(t, resource.TestCase{ @@ -254,7 +252,7 @@ func TestAccOutscaleOAPIVM_WithSubnet(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigWithSubnet(omi, "tinav4.c2r2p2", region, keypair), + Config: testAccCheckOutscaleOAPIVMConfigWithSubnet(omi, "tinav4.c2r2p2", utils.GetRegion(), keypair), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), @@ -271,7 +269,6 @@ func TestAccOutscaleOAPIVM_WithSubnet(t *testing.T) { func TestAccOutscaleOAPIVM_WithBlockDeviceMappings(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") vmType := "tinav4.c2r2p2" @@ -281,7 +278,7 @@ func TestAccOutscaleOAPIVM_WithBlockDeviceMappings(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigWithBlockDeviceMappings(omi, vmType, region, keypair), + Config: testAccCheckOutscaleOAPIVMConfigWithBlockDeviceMappings(omi, vmType, utils.GetRegion(), keypair), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVMExists("outscale_vm.basic", &server), testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), @@ -322,7 +319,6 @@ func TestAccOutscaleOAPIVM_DeletionProtectionUpdate(t *testing.T) { func TestAccOutscaleOAPIVMTags_Update(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -333,11 +329,11 @@ func TestAccOutscaleOAPIVMTags_Update(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM", keypair, sgId), + Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", utils.GetRegion(), "Terraform-VM", keypair, sgId), //Check: resource.ComposeTestCheckFunc(), }, { - Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", region, "Terraform-VM2", keypair, sgId), + Config: testAccVmsConfigUpdateOAPIVMTags(omi, "tinav4.c2r2p2", utils.GetRegion(), "Terraform-VM2", keypair, sgId), //Check: resource.ComposeTestCheckFunc(), }, }, @@ -347,7 +343,6 @@ func TestAccOutscaleOAPIVMTags_Update(t *testing.T) { func TestAccOutscaleOAPIVM_WithNet(t *testing.T) { var server oscgo.Vm omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") vmType := "tinav4.c2r2p2" @@ -357,7 +352,7 @@ func TestAccOutscaleOAPIVM_WithNet(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleOAPIVMConfigWithNet(omi, vmType, region, keypair), + Config: testAccCheckOutscaleOAPIVMConfigWithNet(omi, vmType, utils.GetRegion(), keypair), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVMExists("outscale_vm.outscale_vmnet", &server), testAccCheckOutscaleOAPIVMAttributes(t, &server, omi), @@ -373,7 +368,6 @@ func TestAccOutscaleOAPIVM_WithNet(t *testing.T) { func TestAccOutscaleOAPIVM_multiBlockDeviceMapping(t *testing.T) { var server oscgo.Vm - region := os.Getenv("OUTSCALE_REGION") omi := os.Getenv("OUTSCALE_IMAGEID") keypair := os.Getenv("OUTSCALE_KEYPAIR") @@ -383,7 +377,7 @@ func TestAccOutscaleOAPIVM_multiBlockDeviceMapping(t *testing.T) { CheckDestroy: testAccCheckOutscaleOAPIVMDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckOutscaleVMWithMultiBlockDeviceMapping(region, omi, keypair), + Config: testAccCheckOutscaleVMWithMultiBlockDeviceMapping(utils.GetRegion(), omi, keypair), Check: resource.ComposeTestCheckFunc( testAccCheckOutscaleOAPIVMExists("outscale_vm.outscale_vm", &server), resource.TestCheckResourceAttr("outscale_vm.outscale_vm", "image_id", omi), @@ -671,8 +665,9 @@ func testAccCheckOutscaleOAPIVMConfigImport(omi, vmType, region, keypair string) resource "outscale_vm" "basic" { image_id = "%[1]s" vm_type = "%[2]s" - keypair_name = "%[4]s" + keypair_name = "%[4]s" placement_subregion_name = "%[3]s" + tags { key = "name" value = "Terraform-VM-import" @@ -730,7 +725,7 @@ func testAccCheckOutscaleOAPIVMConfigBasicWithNicAttached(omi, vmType, region, k }`, omi, vmType, region, keypair) } -func testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, vmType, keypair string) string { +func testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, vmType, keypair, region string) string { return fmt.Sprintf(`resource "outscale_net" "outscale_net" { ip_range = "10.0.0.0/16" } @@ -738,8 +733,8 @@ func testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, vmType, keypair string) resource "outscale_subnet" "outscale_subnet" { net_id = outscale_net.outscale_net.net_id ip_range = "10.0.0.0/24" - subregion_name = "eu-west-2a" - } + subregion_name = "%[4]sb" + resource "outscale_nic" "outscale_nic" { subnet_id = outscale_subnet.outscale_subnet.subnet_id @@ -752,13 +747,17 @@ func testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, vmType, keypair string) } resource "outscale_vm" "basic" { - image_id = "%s" - vm_type = "%s" - keypair_name = "%s" + image_id = "%[1]s" + vm_type = "%[2]s" + keypair_name = "%[3]s" nics { device_number = 0 subnet_id = outscale_subnet.outscale_subnet.subnet_id + + # nic_id = outscale_nic.outscale_nic.nic_id + # secondary_private_ip_count = 1 + security_group_ids = [outscale_security_group.outscale_security_group.security_group_id] private_ips { @@ -771,7 +770,7 @@ func testAccCheckOutscaleOAPIVMConfigBasicWithNics(omi, vmType, keypair string) is_primary = false } } - }`, omi, vmType, keypair) + }`, omi, vmType, keypair, region) } func testAccVmsConfigUpdateOAPIVMKey(omi, vmType, region, keypair, sgId string) string { @@ -978,7 +977,7 @@ func testAccCheckOutscaleOAPIVMConfigWithNet(omi, vmType, region, keypair string resource "outscale_internet_service_link" "outscale_internet_service_link" { internet_service_id = outscale_internet_service.outscale_internet_service.internet_service_id - net_id = "${outscale_net.outscale_net.net_id}" + net_id = outscale_net.outscale_net.net_id } resource "outscale_route" "outscale_route" { diff --git a/outscale/resource_outscale_volume_test.go b/outscale/resource_outscale_volume_test.go index 3064e0f1d..28e950880 100644 --- a/outscale/resource_outscale_volume_test.go +++ b/outscale/resource_outscale_volume_test.go @@ -3,7 +3,6 @@ package outscale import ( "context" "fmt" - "os" "testing" "time" @@ -16,7 +15,6 @@ import ( func TestAccOutscaleOAPIVolume_basic(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") var v oscgo.Volume resource.Test(t, resource.TestCase{ @@ -25,7 +23,7 @@ func TestAccOutscaleOAPIVolume_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccOutscaleOAPIVolumeConfig(region), + Config: testAccOutscaleOAPIVolumeConfig(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOAPIVolumeExists("outscale_volume.test", &v), ), @@ -41,7 +39,7 @@ func TestAccOutscaleOAPIVolume_basic(t *testing.T) { func TestAccOutscaleOAPIVolume_updateSize(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") + region := utils.GetRegion() var v oscgo.Volume resource.Test(t, resource.TestCase{ @@ -72,7 +70,6 @@ func TestAccOutscaleOAPIVolume_updateSize(t *testing.T) { func TestAccOutscaleOAPIVolume_io1Type(t *testing.T) { t.Parallel() - region := os.Getenv("OUTSCALE_REGION") var v oscgo.Volume resource.Test(t, resource.TestCase{ @@ -84,7 +81,7 @@ func TestAccOutscaleOAPIVolume_io1Type(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testOutscaleOAPIVolumeConfigIO1Type(region), + Config: testOutscaleOAPIVolumeConfigIO1Type(utils.GetRegion()), Check: resource.ComposeTestCheckFunc( testAccCheckOAPIVolumeExists("outscale_volume.test-io", &v), ), diff --git a/outscale/resource_outscale_volumes_link_test.go b/outscale/resource_outscale_volumes_link_test.go index 05903c2ab..65eb0cec2 100644 --- a/outscale/resource_outscale_volumes_link_test.go +++ b/outscale/resource_outscale_volumes_link_test.go @@ -6,6 +6,7 @@ import ( "testing" oscgo "github.com/outscale/osc-sdk-go/v2" + "github.com/terraform-providers/terraform-provider-outscale/utils" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -14,7 +15,6 @@ import ( func TestAccOutscaleOAPIVolumeAttachment_basic(t *testing.T) { t.Parallel() omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -30,7 +30,7 @@ func TestAccOutscaleOAPIVolumeAttachment_basic(t *testing.T) { CheckDestroy: testAccCheckOAPIVolumeAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVolumeAttachmentConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccOAPIVolumeAttachmentConfig(omi, "tinav4.c2r2p2", utils.GetRegion(), keypair, sgId), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "outscale_volumes_link.ebs_att", "device_name", "/dev/sdh"), @@ -45,7 +45,6 @@ func TestAccOutscaleOAPIVolumeAttachment_basic(t *testing.T) { func TestAccOutscaleOAPIVolumeAttachment_importBasic(t *testing.T) { omi := os.Getenv("OUTSCALE_IMAGEID") - region := os.Getenv("OUTSCALE_REGION") keypair := os.Getenv("OUTSCALE_KEYPAIR") sgId := os.Getenv("OUTSCALE_SECURITYGROUPID") @@ -57,7 +56,7 @@ func TestAccOutscaleOAPIVolumeAttachment_importBasic(t *testing.T) { CheckDestroy: testAccCheckOAPIVolumeAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccOAPIVolumeAttachmentConfig(omi, "tinav4.c2r2p2", region, keypair, sgId), + Config: testAccOAPIVolumeAttachmentConfig(omi, "tinav4.c2r2p2", utils.GetRegion(), keypair, sgId), }, { ResourceName: resourceName, diff --git a/utils/utils.go b/utils/utils.go index e2524f58d..5fec7432d 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -6,6 +6,7 @@ import ( "log" "math/rand" "net/http" + "os" "strconv" "time" @@ -233,3 +234,11 @@ func StringSlicePtrToInterfaceSlice(list *[]string) []interface{} { func I32toa(i int32) string { return strconv.FormatInt(int64(i), 10) } + +func GetRegion() string { + region := fmt.Sprintf("%s", os.Getenv("TESTACC_REGION")) + if region == "" { + region = "eu-west-2" + } + return region +}