Skip to content

Commit ca9ea9f

Browse files
authored
Merge pull request #403 from lpatte/migrate-with-context
Update to go 1.20 + Use context function for database + some fixes
2 parents e19aa5c + c9dfb7a commit ca9ea9f

File tree

351 files changed

+32975
-6198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

351 files changed

+32975
-6198
lines changed

.cds/terraform-provider-ovh-check.pip.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
make test
1616
make vet
1717
requirements:
18-
- model: shared.infra/Go-official-1.19-bullseye
18+
- model: shared.infra/Go-official-1.20-bullseye

.cds/terraform-provider-ovh-testacc.pip.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
TF_ACC=1 go test ./ovh/ -v -sweep=1
3434
3535
requirements:
36-
- model: shared.infra/Go-official-1.19-bullseye
36+
- model: shared.infra/Go-official-1.20-bullseye

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Requirements
99
------------
1010

1111
- [Terraform](https://www.terraform.io/downloads.html) 0.12.x
12-
- [Go](https://golang.org/doc/install) 1.13 (to build the provider plugin)
12+
- [Go](https://golang.org/doc/install) 1.20 (to build the provider plugin)
1313

1414
Building The Provider
1515
---------------------

go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ module github.com/ovh/terraform-provider-ovh
33
require (
44
github.com/google/go-cmp v0.5.9
55
github.com/hashicorp/go-cleanhttp v0.5.2
6+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
67
github.com/hashicorp/go-version v1.6.0
78
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0
89
github.com/mitchellh/go-homedir v1.1.0
910
github.com/ovh/go-ovh v1.3.0
1011
github.com/ybriffa/rfc3339 v0.0.0-20220203155318-1789e3fd6e70
12+
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2
1113
gopkg.in/ini.v1 v1.57.0
1214
gopkg.in/yaml.v3 v3.0.1
1315
)
@@ -22,7 +24,6 @@ require (
2224
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
2325
github.com/hashicorp/errwrap v1.0.0 // indirect
2426
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
25-
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
2627
github.com/hashicorp/go-hclog v1.2.1 // indirect
2728
github.com/hashicorp/go-multierror v1.1.1 // indirect
2829
github.com/hashicorp/go-plugin v1.4.4 // indirect
@@ -50,14 +51,14 @@ require (
5051
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
5152
github.com/vmihailenco/tagparser v0.1.1 // indirect
5253
github.com/zclconf/go-cty v1.11.0 // indirect
53-
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
54-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
55-
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
56-
golang.org/x/text v0.3.7 // indirect
54+
golang.org/x/crypto v0.1.0 // indirect
55+
golang.org/x/net v0.8.0 // indirect
56+
golang.org/x/sys v0.6.0 // indirect
57+
golang.org/x/text v0.8.0 // indirect
5758
google.golang.org/appengine v1.6.6 // indirect
5859
google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect
5960
google.golang.org/grpc v1.48.0 // indirect
6061
google.golang.org/protobuf v1.28.1 // indirect
6162
)
6263

63-
go 1.19
64+
go 1.20

go.sum

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
227227
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
228228
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
229229
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
230-
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 h1:O8uGbHCqlTp2P6QJSLmCojM4mN6UemYv8K+dCnmHmu0=
231-
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
230+
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
231+
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
232232
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
233+
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 h1:Jvc7gsqn21cJHCmAWx0LiimpP18LZmUxkT5Mp7EZ1mI=
234+
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
233235
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
234236
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
235237
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
@@ -248,8 +250,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
248250
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
249251
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
250252
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
251-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
252-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
253+
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
254+
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
253255
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
254256
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
255257
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -276,16 +278,17 @@ golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7w
276278
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
277279
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
278280
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
279-
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
280281
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
281-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
282+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
283+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
282284
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
285+
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
283286
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
284287
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
285288
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
286289
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
287-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
288-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
290+
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
291+
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
289292
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
290293
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
291294
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=

ovh/data_cloud_project_database.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package ovh
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"net/url"
78

9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
911
)
1012

1113
func dataSourceCloudProjectDatabase() *schema.Resource {
1214
return &schema.Resource{
13-
Read: dataSourceCloudProjectDatabaseRead,
15+
ReadContext: dataSourceCloudProjectDatabaseRead,
1416
Schema: map[string]*schema.Schema{
1517
"service_name": {
1618
Type: schema.TypeString,
@@ -179,7 +181,7 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
179181
}
180182
}
181183

182-
func dataSourceCloudProjectDatabaseRead(d *schema.ResourceData, meta interface{}) error {
184+
func dataSourceCloudProjectDatabaseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
183185
config := meta.(*Config)
184186
serviceName := d.Get("service_name").(string)
185187
engine := d.Get("engine").(string)
@@ -194,22 +196,22 @@ func dataSourceCloudProjectDatabaseRead(d *schema.ResourceData, meta interface{}
194196

195197
log.Printf("[DEBUG] Will read database %s from project: %s", id, serviceName)
196198
if err := config.OVHClient.Get(serviceEndpoint, res); err != nil {
197-
return fmt.Errorf("Error calling GET %s:\n\t %q", serviceEndpoint, err)
199+
return diag.Errorf("Error calling GET %s:\n\t %q", serviceEndpoint, err)
198200
}
199201

200202
nodesEndpoint := fmt.Sprintf("%s/node", serviceEndpoint)
201203
nodeList := &[]string{}
202204
if err := config.OVHClient.Get(nodesEndpoint, nodeList); err != nil {
203-
return fmt.Errorf("unable to get database %s nodes: %v", res.Id, err)
205+
return diag.Errorf("unable to get database %s nodes: %v", res.Id, err)
204206
}
205207

206208
if len(*nodeList) == 0 {
207-
return fmt.Errorf("no node found for database %s", res.Id)
209+
return diag.Errorf("no node found for database %s", res.Id)
208210
}
209211
nodeEndpoint := fmt.Sprintf("%s/%s", nodesEndpoint, url.PathEscape((*nodeList)[0]))
210212
node := &CloudProjectDatabaseNodes{}
211213
if err := config.OVHClient.Get(nodeEndpoint, node); err != nil {
212-
return fmt.Errorf("unable to get database %s node %s: %v", res.Id, (*nodeList)[0], err)
214+
return diag.Errorf("unable to get database %s node %s: %v", res.Id, (*nodeList)[0], err)
213215
}
214216

215217
res.Region = node.Region
@@ -218,7 +220,7 @@ func dataSourceCloudProjectDatabaseRead(d *schema.ResourceData, meta interface{}
218220
advancedConfigEndpoint := fmt.Sprintf("%s/advancedConfiguration", serviceEndpoint)
219221
advancedConfigMap := &map[string]string{}
220222
if err := config.OVHClient.Get(advancedConfigEndpoint, advancedConfigMap); err != nil {
221-
return fmt.Errorf("unable to get database %s advanced configuration: %v", res.Id, err)
223+
return diag.Errorf("unable to get database %s advanced configuration: %v", res.Id, err)
222224
}
223225
res.AdvancedConfiguration = *advancedConfigMap
224226
}

ovh/data_cloud_project_database_capabilities.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package ovh
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"net/url"
78

9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
911
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
1012
)
1113

1214
func dataSourceCloudProjectDatabaseCapabilities() *schema.Resource {
1315
return &schema.Resource{
14-
Read: dataSourceCloudProjectDatabaseCapabilitiesRead,
16+
ReadContext: dataSourceCloudProjectDatabaseCapabilitiesRead,
1517
Schema: map[string]*schema.Schema{
1618
"service_name": {
1719
Type: schema.TypeString,
@@ -132,7 +134,7 @@ func dataSourceCloudProjectDatabaseCapabilities() *schema.Resource {
132134
}
133135
}
134136

135-
func dataSourceCloudProjectDatabaseCapabilitiesRead(d *schema.ResourceData, meta interface{}) error {
137+
func dataSourceCloudProjectDatabaseCapabilitiesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
136138
config := meta.(*Config)
137139
serviceName := d.Get("service_name").(string)
138140

@@ -143,7 +145,7 @@ func dataSourceCloudProjectDatabaseCapabilitiesRead(d *schema.ResourceData, meta
143145

144146
log.Printf("[DEBUG] Will read capabilities from project %s", serviceName)
145147
if err := config.OVHClient.Get(capabilitiesEndpoint, capabilitiesRes); err != nil {
146-
return helpers.CheckDeleted(d, err, capabilitiesEndpoint)
148+
return diag.FromErr(helpers.CheckDeleted(d, err, capabilitiesEndpoint))
147149
}
148150

149151
d.SetId(serviceName)

ovh/data_cloud_project_database_certificates.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package ovh
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"net/url"
78
"strconv"
89

10+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1012
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
1113
"github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode"
1214
)
1315

1416
func dataSourceCloudProjectDatabaseCertificates() *schema.Resource {
1517
return &schema.Resource{
16-
Read: dataSourceCloudProjectDatabaseCertificatesRead,
18+
ReadContext: dataSourceCloudProjectDatabaseCertificatesRead,
1719
Schema: map[string]*schema.Schema{
1820
"service_name": {
1921
Type: schema.TypeString,
@@ -42,22 +44,22 @@ func dataSourceCloudProjectDatabaseCertificates() *schema.Resource {
4244
}
4345
}
4446

45-
func dataSourceCloudProjectDatabaseCertificatesRead(d *schema.ResourceData, meta interface{}) error {
47+
func dataSourceCloudProjectDatabaseCertificatesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
4648
config := meta.(*Config)
4749
serviceName := d.Get("service_name").(string)
4850
engine := d.Get("engine").(string)
49-
clusterId := d.Get("cluster_id").(string)
51+
clusterID := d.Get("cluster_id").(string)
5052

5153
endpoint := fmt.Sprintf("/cloud/project/%s/database/%s/%s/certificates",
5254
url.PathEscape(serviceName),
5355
url.PathEscape(engine),
54-
url.PathEscape(clusterId),
56+
url.PathEscape(clusterID),
5557
)
5658
res := &CloudProjectDatabaseCertificatesResponse{}
5759

58-
log.Printf("[DEBUG] Will read certificates from cluster %s from project %s", clusterId, serviceName)
60+
log.Printf("[DEBUG] Will read certificates from cluster %s from project %s", clusterID, serviceName)
5961
if err := config.OVHClient.Get(endpoint, res); err != nil {
60-
return helpers.CheckDeleted(d, err, endpoint)
62+
return diag.FromErr(helpers.CheckDeleted(d, err, endpoint))
6163
}
6264

6365
d.SetId(strconv.Itoa(hashcode.String(res.Ca)))

ovh/data_cloud_project_database_database.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package ovh
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"net/url"
78

9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
911
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
1012
)
1113

1214
func dataSourceCloudProjectDatabaseDatabase() *schema.Resource {
1315
return &schema.Resource{
14-
Read: dataSourceCloudProjectDatabaseDatabaseRead,
16+
ReadContext: dataSourceCloudProjectDatabaseDatabaseRead,
1517
Schema: map[string]*schema.Schema{
1618
"service_name": {
1719
Type: schema.TypeString,
@@ -45,39 +47,39 @@ func dataSourceCloudProjectDatabaseDatabase() *schema.Resource {
4547
}
4648
}
4749

48-
func dataSourceCloudProjectDatabaseDatabaseRead(d *schema.ResourceData, meta interface{}) error {
50+
func dataSourceCloudProjectDatabaseDatabaseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
4951
config := meta.(*Config)
5052
serviceName := d.Get("service_name").(string)
5153
engine := d.Get("engine").(string)
52-
clusterId := d.Get("cluster_id").(string)
54+
clusterID := d.Get("cluster_id").(string)
5355
name := d.Get("name").(string)
5456

5557
listEndpoint := fmt.Sprintf("/cloud/project/%s/database/%s/%s/database",
5658
url.PathEscape(serviceName),
5759
url.PathEscape(engine),
58-
url.PathEscape(clusterId),
60+
url.PathEscape(clusterID),
5961
)
6062

6163
listRes := make([]string, 0)
6264

63-
log.Printf("[DEBUG] Will read databases from cluster %s from project %s", clusterId, serviceName)
65+
log.Printf("[DEBUG] Will read databases from cluster %s from project %s", clusterID, serviceName)
6466
if err := config.OVHClient.Get(listEndpoint, &listRes); err != nil {
65-
return fmt.Errorf("Error calling GET %s:\n\t %q", listEndpoint, err)
67+
return diag.Errorf("Error calling GET %s:\n\t %q", listEndpoint, err)
6668
}
6769

6870
for _, id := range listRes {
6971
endpoint := fmt.Sprintf("/cloud/project/%s/database/%s/%s/database/%s",
7072
url.PathEscape(serviceName),
7173
url.PathEscape(engine),
72-
url.PathEscape(clusterId),
74+
url.PathEscape(clusterID),
7375
url.PathEscape(id),
7476
)
7577

7678
res := &CloudProjectDatabaseDatabaseResponse{}
7779

78-
log.Printf("[DEBUG] Will read database %s from cluster %s from project %s", id, clusterId, serviceName)
80+
log.Printf("[DEBUG] Will read database %s from cluster %s from project %s", id, clusterID, serviceName)
7981
if err := config.OVHClient.Get(endpoint, res); err != nil {
80-
return fmt.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
82+
return diag.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
8183
}
8284

8385
if res.Name == name {
@@ -93,5 +95,5 @@ func dataSourceCloudProjectDatabaseDatabaseRead(d *schema.ResourceData, meta int
9395
}
9496
}
9597

96-
return fmt.Errorf("Database name %s not found for cluster %s from project %s", name, clusterId, serviceName)
98+
return diag.Errorf("Database name %s not found for cluster %s from project %s", name, clusterID, serviceName)
9799
}

ovh/data_cloud_project_database_databases.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package ovh
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"net/url"
78
"sort"
89

10+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1012
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
1113
"github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode"
1214
)
1315

1416
func dataSourceCloudProjectDatabaseDatabases() *schema.Resource {
1517
return &schema.Resource{
16-
Read: dataSourceCloudProjectDatabaseDatabasesRead,
18+
ReadContext: dataSourceCloudProjectDatabaseDatabasesRead,
1719
Schema: map[string]*schema.Schema{
1820
"service_name": {
1921
Type: schema.TypeString,
@@ -43,23 +45,23 @@ func dataSourceCloudProjectDatabaseDatabases() *schema.Resource {
4345
}
4446
}
4547

46-
func dataSourceCloudProjectDatabaseDatabasesRead(d *schema.ResourceData, meta interface{}) error {
48+
func dataSourceCloudProjectDatabaseDatabasesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
4749
config := meta.(*Config)
4850
serviceName := d.Get("service_name").(string)
4951
engine := d.Get("engine").(string)
50-
clusterId := d.Get("cluster_id").(string)
52+
clusterID := d.Get("cluster_id").(string)
5153

5254
endpoint := fmt.Sprintf("/cloud/project/%s/database/%s/%s/database",
5355
url.PathEscape(serviceName),
5456
url.PathEscape(engine),
55-
url.PathEscape(clusterId),
57+
url.PathEscape(clusterID),
5658
)
5759

5860
res := make([]string, 0)
5961

60-
log.Printf("[DEBUG] Will read databases from cluster %s from project %s", clusterId, serviceName)
62+
log.Printf("[DEBUG] Will read databases from cluster %s from project %s", clusterID, serviceName)
6163
if err := config.OVHClient.Get(endpoint, &res); err != nil {
62-
return fmt.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
64+
return diag.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
6365
}
6466

6567
// sort.Strings sorts in place, returns nothing

0 commit comments

Comments
 (0)