Skip to content

Commit

Permalink
Merge pull request #175 from yanndegat/renamecloudresources
Browse files Browse the repository at this point in the history
mv ovh_cloud_* -> ovh_cloud_project_*
  • Loading branch information
yanndegat authored Dec 1, 2020
2 parents fc43c99 + a10ede3 commit 8061df5
Show file tree
Hide file tree
Showing 33 changed files with 659 additions and 704 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,21 @@ $ source ~/.ovhrc
In order for all the tests to pass you can run:

```sh
export OVH_IP_TEST="..."
export OVH_IP_BLOCK_TEST="..."
export OVH_IP_REVERSE_TEST="..."
export OVH_IPLB_SERVICE_TEST="..."
export OVH_CLOUD_PROJECT_SERVICE_TEST="..."
export OVH_VRACK_SERVICE_TEST="..."
export OVH_ZONE_TEST="..."

$ make testacc
```

To filter acceptance test, you can run:

```sh
$ make testacc TESTARGS="-run TestAccPublicCloudPrivateNetwork"
$ make testacc TESTARGS="-run TestAccCloudProjectPrivateNetwork"
```

To remove dangling resources, you can run:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode"
)

func dataSourceCloudRegion() *schema.Resource {
func dataSourceCloudProjectRegion() *schema.Resource {
return &schema.Resource{
Read: dataSourceCloudRegionRead,
Read: dataSourceCloudProjectRegionRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -80,7 +80,7 @@ func dataSourceCloudRegion() *schema.Resource {
}
}

func dataSourceCloudRegionRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceCloudProjectRegionRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName, err := helpers.GetCloudProjectServiceName(d)
if err != nil {
Expand All @@ -91,7 +91,7 @@ func dataSourceCloudRegionRead(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] Will read public cloud region %s for project: %s", name, serviceName)

region, err := getCloudRegion(serviceName, name, config.OVHClient)
region, err := getCloudProjectRegion(serviceName, name, config.OVHClient)
if err != nil {
return err
}
Expand Down Expand Up @@ -121,10 +121,10 @@ func dataSourceCloudRegionRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

func getCloudRegion(serviceName, region string, client *ovh.Client) (*CloudRegionResponse, error) {
func getCloudProjectRegion(serviceName, region string, client *ovh.Client) (*CloudProjectRegionResponse, error) {
log.Printf("[DEBUG] Will read public cloud region %s for project: %s", region, serviceName)

response := &CloudRegionResponse{}
response := &CloudProjectRegionResponse{}
endpoint := fmt.Sprintf(
"/cloud/project/%s/region/%s",
url.PathEscape(serviceName),
Expand Down
73 changes: 73 additions & 0 deletions ovh/data_source_ovh_cloud_project_region_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ovh

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccCloudProjectRegionDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCloud(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudProjectRegionDatasourceConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.0", "name"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.0", "services.#"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.1", "name"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.1", "services.#"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.2", "name"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.2", "services.#"),
),
},
},
})
}

func TestAccCloudProjectRegionDataSourceDeprecated_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCloud(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudProjectRegionDatasourceDeprecatedConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.0", "name"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.0", "services.#"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.1", "name"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.1", "services.#"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.2", "name"),
resource.TestCheckResourceAttrSet("data.ovh_cloud_project_region.region_attr.2", "services.#"),
),
},
},
})
}

var testAccCloudProjectRegionDatasourceConfig = fmt.Sprintf(`
data "ovh_cloud_project_regions" "regions" {
service_name = "%s"
}
data "ovh_cloud_project_region" "region_attr" {
count = 3
service_name = data.ovh_cloud_project_regions.regions.service_name
name = element(sort(data.ovh_cloud_project_regions.regions.names), count.index)
}
`, os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"))

var testAccCloudProjectRegionDatasourceDeprecatedConfig = fmt.Sprintf(`
data "ovh_cloud_project_regions" "regions" {
project_id = "%s"
}
data "ovh_cloud_project_region" "region_attr" {
count = 3
project_id = data.ovh_cloud_project_regions.regions.service_name
name = element(sort(data.ovh_cloud_project_regions.regions.names), count.index)
}
`, os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"))
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

func dataSourceCloudRegions() *schema.Resource {
func dataSourceCloudProjectRegions() *schema.Resource {
return &schema.Resource{
Read: dataSourceCloudRegionsRead,
Read: dataSourceCloudProjectRegionsRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -46,7 +46,7 @@ func dataSourceCloudRegions() *schema.Resource {
}
}

func dataSourceCloudRegionsRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceCloudProjectRegionsRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName, err := helpers.GetCloudProjectServiceName(d)
if err != nil {
Expand Down Expand Up @@ -84,7 +84,7 @@ func dataSourceCloudRegionsRead(d *schema.ResourceData, meta interface{}) error

filtered_names := make([]string, 0)
for _, n := range names {
region, err := getCloudRegion(serviceName, n, config.OVHClient)
region, err := getCloudProjectRegion(serviceName, n, config.OVHClient)
if err != nil {
return err
}
Expand Down
67 changes: 67 additions & 0 deletions ovh/data_source_ovh_cloud_project_regions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ovh

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccCloudProjectRegionsDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCloud(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudProjectRegionsDatasourceConfig,
Check: resource.TestCheckResourceAttrSet("data.ovh_cloud_project_regions.regions", "names.#"),
},
},
})
}

func TestAccCloudProjectRegionsDeprecatedDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCloud(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudProjectRegionsDatasourceDeprecatedConfig,
Check: resource.TestCheckResourceAttrSet("data.ovh_cloud_project_regions.regions", "names.#"),
},
},
})
}

func TestAccCloudProjectRegionsDataSource_withNetworkUp(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCloud(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudProjectRegionsDatasourceConfig_withNetwork,
Check: resource.TestCheckResourceAttrSet("data.ovh_cloud_project_regions.regions", "names.#"),
},
},
})
}

var testAccCloudProjectRegionsDatasourceConfig = fmt.Sprintf(`
data "ovh_cloud_project_regions" "regions" {
service_name = "%s"
}
`, os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"))

var testAccCloudProjectRegionsDatasourceDeprecatedConfig = fmt.Sprintf(`
data "ovh_cloud_project_regions" "regions" {
project_id = "%s"
}
`, os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"))

var testAccCloudProjectRegionsDatasourceConfig_withNetwork = fmt.Sprintf(`
data "ovh_cloud_project_regions" "regions" {
service_name = "%s"
has_services_up = ["network"]
}
`, os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"))
73 changes: 0 additions & 73 deletions ovh/data_source_ovh_cloud_region_test.go

This file was deleted.

67 changes: 0 additions & 67 deletions ovh/data_source_ovh_cloud_regions_test.go

This file was deleted.

Loading

0 comments on commit 8061df5

Please sign in to comment.