Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Stop computing URNs in the provider and rely on the API responses #537

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ovh/data_dedicated_ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func dataSourceDedicatedCephRead(d *schema.ResourceData, meta interface{}) error
}
log.Printf("[DEBUG] CEPH is %v", ceph.CephMonitors)
d.SetId(ceph.ServiceName)
d.Set("urn", helpers.ServiceURN(config.Plate, "dedicatedCeph", ceph.ServiceName))
d.Set("urn", ceph.URN)
d.Set("service_name", ceph.ServiceName)
d.Set("ceph_mons", ceph.CephMonitors)
d.Set("ceph_version", ceph.CephVersion)
Expand Down
2 changes: 2 additions & 0 deletions ovh/data_dedicated_ceph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func TestAccDedicatedCephDatasource(t *testing.T) {
"data.ovh_dedicated_ceph.ceph", "service_name", dedicated_ceph),
resource.TestCheckResourceAttr(
"data.ovh_dedicated_ceph.ceph", "status", "INSTALLED"),
resource.TestCheckResourceAttrSet(
"data.ovh_dedicated_ceph.ceph", "urn"),
),
},
},
Expand Down
3 changes: 1 addition & 2 deletions ovh/data_dedicated_nasha.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -92,7 +91,7 @@ func dataSourceDedicatedNashaRead(c context.Context, d *schema.ResourceData, met
}

d.SetId(ds.ServiceName)
d.Set("urn", helpers.ServiceURN(config.Plate, "nasHA", ds.ServiceName))
d.Set("urn", ds.URN)
d.Set("service_name", ds.ServiceName)
d.Set("monitored", ds.Monitored)
d.Set("zpool_size", ds.ZpoolSize)
Expand Down
1 change: 1 addition & 0 deletions ovh/data_dedicated_nasha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccDedicatedNashaData(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.ovh_dedicated_nasha.testacc", "disk_type", "ssd"),
resource.TestCheckResourceAttr("data.ovh_dedicated_nasha.testacc", "service_name", serviceName),
resource.TestCheckResourceAttrSet("data.ovh_dedicated_nasha.testacc", "urn"),
),
},
},
Expand Down
3 changes: 1 addition & 2 deletions ovh/data_dedicated_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

func dataSourceDedicatedServer() *schema.Resource {
Expand Down Expand Up @@ -201,7 +200,7 @@ func dataSourceDedicatedServerRead(d *schema.ResourceData, meta interface{}) err
}

d.SetId(ds.Name)
d.Set("urn", helpers.ServiceURN(config.Plate, "dedicatedServer", ds.Name))
d.Set("urn", ds.URN)
d.Set("boot_id", ds.BootId)
d.Set("commercial_range", ds.CommercialRange)
d.Set("datacenter", ds.Datacenter)
Expand Down
2 changes: 2 additions & 0 deletions ovh/data_dedicated_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestAccDedicatedServerDataSource_basic(t *testing.T) {
"data.ovh_dedicated_server.server", "vnis.#"),
resource.TestCheckResourceAttr(
"data.ovh_dedicated_server.server", "vnis.0.server_name", dedicated_server),
resource.TestCheckResourceAttrSet(
"data.ovh_dedicated_server.server", "urn"),
),
},
},
Expand Down
7 changes: 3 additions & 4 deletions ovh/data_domain_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package ovh

import (
"fmt"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

func dataSourceDomainZone() *schema.Resource {
Expand Down Expand Up @@ -48,7 +48,7 @@ func dataSourceDomainZoneRead(d *schema.ResourceData, meta interface{}) error {
zoneName := d.Get("name").(string)

dz := &DomainZone{}
err := config.OVHClient.Get(fmt.Sprintf("/domain/zone/%s", zoneName), &dz)
err := config.OVHClient.Get(fmt.Sprintf("/domain/zone/%s", url.PathEscape(zoneName)), &dz)

if err != nil {
return fmt.Errorf("Error calling /domain/zone/%s:\n\t %q", zoneName, err)
Expand All @@ -59,8 +59,7 @@ func dataSourceDomainZoneRead(d *schema.ResourceData, meta interface{}) error {
d.Set("dnssec_supported", dz.DnssecSupported)
d.Set("last_update", dz.LastUpdate)
d.Set("name_servers", dz.NameServers)

d.Set("urn", helpers.ServiceURN(config.Plate, "dnsZone", zoneName))
d.Set("urn", dz.URN)

return nil
}
2 changes: 2 additions & 0 deletions ovh/data_domain_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func TestAccDomainZoneDataSource_basic(t *testing.T) {
testAccCheckDomainZoneHasNameServers("data.ovh_domain_zone.rootzone", t),
resource.TestCheckResourceAttr(
"data.ovh_domain_zone.rootzone", "id", zoneName),
resource.TestCheckResourceAttrSet(
"data.ovh_domain_zone.rootzone", "urn"),
),
},
},
Expand Down
2 changes: 0 additions & 2 deletions ovh/data_hosting_privatedatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

func dataSourceHostingPrivateDatabase() *schema.Resource {
Expand Down Expand Up @@ -143,7 +142,6 @@ func dataSourceHostingPrivateDatabaseRead(d *schema.ResourceData, meta interface
}
}
d.SetId(ds.ServiceName)
d.Set("urn", helpers.ServiceURN(config.Plate, "webCloudDatabases", ds.ServiceName))

return nil
}
4 changes: 4 additions & 0 deletions ovh/data_hosting_privatedatabase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func TestAccDataSourceHostingPrivateDatabase_basic(t *testing.T) {
"data.ovh_hosting_privatedatabase.database",
"version_number",
),
resource.TestCheckResourceAttrSet(
"data.ovh_hosting_privatedatabase.database",
"urn",
),
),
},
},
Expand Down
5 changes: 3 additions & 2 deletions ovh/data_iploadbalancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ovh
import (
"fmt"
"log"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
Expand Down Expand Up @@ -164,7 +165,7 @@ func dataSourceIpLoadbalancingRead(d *schema.ResourceData, meta interface{}) err

for _, serviceName := range response {
iplb := &IpLoadbalancing{}
err := config.OVHClient.Get(fmt.Sprintf("/ipLoadbalancing/%s", serviceName), &iplb)
err := config.OVHClient.Get(fmt.Sprintf("/ipLoadbalancing/%s", url.PathEscape(serviceName)), &iplb)

if err != nil {
return fmt.Errorf("Error calling /ipLoadbalancing/%s:\n\t %q", serviceName, err)
Expand Down Expand Up @@ -244,8 +245,8 @@ func dataSourceIpLoadbalancingAttributes(config *Config, d *schema.ResourceData,
}

d.SetId(iplb.ServiceName)
d.Set("urn", helpers.ServiceURN(config.Plate, "loadbalancer", iplb.ServiceName))

d.Set("urn", iplb.URN)
d.Set("ipv6", iplb.IPv6)
d.Set("ipv4", iplb.IPv4)
d.Set("zone", iplb.Zone)
Expand Down
4 changes: 4 additions & 0 deletions ovh/data_iploadbalancing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestAccIpLoadbalancingDataSource_basic(t *testing.T) {
"data.ovh_iploadbalancing.iplb", "service_name", serviceName),
resource.TestCheckResourceAttr(
"data.ovh_iploadbalancing.iplb", "id", serviceName),
resource.TestCheckResourceAttrSet(
"data.ovh_iploadbalancing.iplb", "urn"),
),
},
},
Expand All @@ -48,6 +50,8 @@ func TestAccIpLoadbalancingDataSource_statevrack(t *testing.T) {
"data.ovh_iploadbalancing.iplb", "state", "ok"),
resource.TestCheckResourceAttr(
"data.ovh_iploadbalancing.iplb", "vrack_eligibility", "true"),
resource.TestCheckResourceAttrSet(
"data.ovh_iploadbalancing.iplb", "urn"),
),
},
},
Expand Down
8 changes: 3 additions & 5 deletions ovh/data_vps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

func dataSourceVPS() *schema.Resource {
Expand Down Expand Up @@ -113,8 +112,7 @@ func dataSourceVPSRead(d *schema.ResourceData, meta interface{}) error {

d.SetId(vps.Name)

d.Set("urn", helpers.ServiceURN(config.Plate, helpers.VPSkind, serviceName))

d.Set("urn", vps.URN)
d.Set("name", vps.Name)
d.Set("zone", vps.Zone)
d.Set("state", vps.State)
Expand All @@ -135,7 +133,7 @@ func dataSourceVPSRead(d *schema.ResourceData, meta interface{}) error {

ips := []string{}
err = config.OVHClient.Get(
fmt.Sprintf("/vps/%s/ips", d.Id()),
fmt.Sprintf("/vps/%s/ips", url.PathEscape(d.Id())),
&ips,
)
if err != nil {
Expand All @@ -146,7 +144,7 @@ func dataSourceVPSRead(d *schema.ResourceData, meta interface{}) error {

vpsDatacenter := VPSDatacenter{}
err = config.OVHClient.Get(
fmt.Sprintf("/vps/%s/datacenter", d.Id()),
fmt.Sprintf("/vps/%s/datacenter", url.PathEscape(d.Id())),
&vpsDatacenter,
)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions ovh/data_vps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestAccVPSDataSource_basic(t *testing.T) {
"data.ovh_vps.server", "name", vps),
resource.TestCheckResourceAttr(
"data.ovh_vps.server", "service_name", vps),
resource.TestCheckResourceAttrSet(
"data.ovh_vps.server", "urn"),
),
},
},
Expand Down
6 changes: 2 additions & 4 deletions ovh/resource_cloud_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func resourceCloudProjectUpdate(d *schema.ResourceData, meta interface{}) error

log.Printf("[DEBUG] Will update cloudProject: %s", serviceName)
opts := (&CloudProjectUpdateOpts{}).FromResource(d)
endpoint := fmt.Sprintf("/cloud/project/%s", serviceName)
endpoint := fmt.Sprintf("/cloud/project/%s", url.PathEscape(serviceName))
if err := config.OVHClient.Put(endpoint, opts, nil); err != nil {
return fmt.Errorf("calling Put %s: %q", endpoint, err)
}
Expand Down Expand Up @@ -142,13 +142,11 @@ func resourceCloudProjectRead(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] Will read cloudProject: %s", serviceName)
r := &CloudProject{}
endpoint := fmt.Sprintf("/cloud/project/%s", serviceName)
endpoint := fmt.Sprintf("/cloud/project/%s", url.PathEscape(serviceName))
if err := config.OVHClient.Get(endpoint, &r); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}

d.Set("urn", helpers.ServiceURN(config.Plate, "publicCloudProject", serviceName))

// set resource attributes
for k, v := range r.ToMap() {
d.Set(k, v)
Expand Down
2 changes: 2 additions & 0 deletions ovh/resource_cloud_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func TestAccResourceCloudProject_basic(t *testing.T) {
"ovh_cloud_project.cloud", "project_id"),
resource.TestCheckResourceAttrSet(
"ovh_cloud_project.cloud", "project_name"),
resource.TestCheckResourceAttrSet(
"ovh_cloud_project.cloud", "urn"),
),
},
},
Expand Down
4 changes: 1 addition & 3 deletions ovh/resource_domain_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func resourceDomainZoneRead(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] Will read domainZone: %s", zoneName)
r := &DomainZone{}
endpoint := fmt.Sprintf("/domain/zone/%s", zoneName)
endpoint := fmt.Sprintf("/domain/zone/%s", url.PathEscape(zoneName))
if err := config.OVHClient.Get(endpoint, &r); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}
Expand All @@ -98,8 +98,6 @@ func resourceDomainZoneRead(d *schema.ResourceData, meta interface{}) error {
d.Set(k, v)
}

d.Set("urn", helpers.ServiceURN(config.Plate, "dnsZone", r.Name))

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions ovh/resource_domain_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func TestAccResourceDomainZone_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ovh_domain_zone.zone", "name", name),
resource.TestCheckResourceAttrSet(
"ovh_domain_zone.zone", "urn"),
),
},
},
Expand Down
1 change: 0 additions & 1 deletion ovh/resource_hosting_privatedatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func resourceHostingPrivateDatabaseRead(d *schema.ResourceData, meta interface{}
for k, v := range ds.ToMap() {
d.Set(k, v)
}
d.Set("urn", helpers.ServiceURN(config.Plate, "webCloudDatabases", ds.ServiceName))

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions ovh/resource_hosting_privatedatabase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func TestAccHostingPrivateDatabase_basic(t *testing.T) {
"ovh_hosting_privatedatabase.database", "datacenter", dc),
resource.TestCheckResourceAttr(
"ovh_hosting_privatedatabase.database", "version", engine),
resource.TestCheckResourceAttrSet(
"ovh_hosting_privatedatabase.database", "urn"),
),
},
},
Expand Down
5 changes: 2 additions & 3 deletions ovh/resource_iploadbalancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func resourceIpLoadbalancingUpdate(d *schema.ResourceData, meta interface{}) err

log.Printf("[DEBUG] Will update ipLoadbalancing: %s", serviceName)
opts := (&IpLoadbalancingUpdateOpts{}).FromResource(d)
endpoint := fmt.Sprintf("/ipLoadbalancing/%s", serviceName)
endpoint := fmt.Sprintf("/ipLoadbalancing/%s", url.PathEscape(serviceName))
if err := config.OVHClient.Put(endpoint, opts, nil); err != nil {
return fmt.Errorf("calling Put %s: %q", endpoint, err)
}
Expand All @@ -197,7 +197,7 @@ func resourceIpLoadbalancingRead(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Will read ipLoadbalancing: %s", serviceName)

r := &IpLoadbalancing{}
endpoint := fmt.Sprintf("/ipLoadbalancing/%s", serviceName)
endpoint := fmt.Sprintf("/ipLoadbalancing/%s", url.PathEscape(serviceName))
if err := config.OVHClient.Get(endpoint, &r); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}
Expand All @@ -206,7 +206,6 @@ func resourceIpLoadbalancingRead(d *schema.ResourceData, meta interface{}) error
for k, v := range r.ToMap() {
d.Set(k, v)
}
d.Set("urn", helpers.ServiceURN(config.Plate, "loadbalancer", r.ServiceName))

return nil
}
Expand Down
4 changes: 4 additions & 0 deletions ovh/resource_iploadbalancing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func TestAccResourceIpLoadbalancing_basic(t *testing.T) {
"ovh_iploadbalancing.iplb-lb1", "ipv4"),
resource.TestCheckResourceAttr(
"ovh_iploadbalancing.iplb-lb1", "display_name", desc),
resource.TestCheckResourceAttrSet(
"ovh_iploadbalancing.iplb-lb1", "urn"),
),
},
},
Expand All @@ -200,6 +202,8 @@ func TestAccResourceIpLoadbalancing_internal(t *testing.T) {
"ovh_iploadbalancing.iplb-internal", "ipv4"),
resource.TestCheckResourceAttr(
"ovh_iploadbalancing.iplb-internal", "display_name", desc),
resource.TestCheckResourceAttrSet(
"ovh_iploadbalancing.iplb-internal", "urn"),
),
},
},
Expand Down
6 changes: 3 additions & 3 deletions ovh/resource_vrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ovh
import (
"fmt"
"log"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
Expand Down Expand Up @@ -78,7 +79,7 @@ func resourceVrackUpdate(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] Will update vrack: %s", serviceName)
opts := (&VrackUpdateOpts{}).FromResource(d)
endpoint := fmt.Sprintf("/vrack/%s", serviceName)
endpoint := fmt.Sprintf("/vrack/%s", url.PathEscape(serviceName))
if err := config.OVHClient.Put(endpoint, opts, nil); err != nil {
return fmt.Errorf("calling Put %s: %q", endpoint, err)
}
Expand All @@ -97,7 +98,7 @@ func resourceVrackRead(d *schema.ResourceData, meta interface{}) error {

log.Printf("[DEBUG] Will read vrack: %s", serviceName)
r := &Vrack{}
endpoint := fmt.Sprintf("/vrack/%s", serviceName)
endpoint := fmt.Sprintf("/vrack/%s", url.PathEscape(serviceName))
if err := config.OVHClient.Get(endpoint, &r); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}
Expand All @@ -108,7 +109,6 @@ func resourceVrackRead(d *schema.ResourceData, meta interface{}) error {
for k, v := range r.ToMap() {
d.Set(k, v)
}
d.Set("urn", helpers.ServiceURN(config.Plate, "vrack", serviceName))

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions ovh/resource_vrack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func TestAccResourceVrack_basic(t *testing.T) {
"ovh_vrack.vrack", "description", desc),
resource.TestCheckResourceAttrSet(
"ovh_vrack.vrack", "service_name"),
resource.TestCheckResourceAttrSet(
"ovh_vrack.vrack", "urn"),
),
},
},
Expand Down
Loading