Skip to content

Commit

Permalink
Pull request #1215: OpenSearch: replace some deprecations
Browse files Browse the repository at this point in the history
Merge in CLOUD/terraform-provider-yandex-mirror from refactor/opensearch to master

Squashed commit of the following:

commit 229781c2e62c90430b1301e1caf838506f57d402
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Thu Apr 18 21:37:57 2024 +0200

    update changelog

commit 49832be9c445c21fb1ced3638ae4b53914787580
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Wed Apr 17 09:18:00 2024 +0200

    replace fmt.Errorf formating %s with %w

commit d4e9100d09515513b9cd6d4f4e6d8900560ed97e
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Tue Apr 16 22:17:20 2024 +0200

    replace legacy logger with structured logger

commit a47126f9d4551e3c1ae97604fd6106d11f3ce1be
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Tue Apr 16 14:26:43 2024 +0200

    replace deprecates importer.state

commit 5cecd906f293ed63eab9568de230c3e15ebfcda0
Author: Aleksandr Tuliakov <tulyakov@yandex-team.ru>
Date:   Tue Apr 16 14:23:00 2024 +0200

    replace create, read, update, delete with alternatives with context
  • Loading branch information
Aleksandr Tuliakov authored and Islam Alibekov committed Apr 25, 2024
1 parent 5a15d67 commit 05aca83
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/ENHANCEMENTS-20240418-213738.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: ENHANCEMENTS
body: 'opensearch: replace deprecated methods and logger '
time: 2024-04-18T21:37:38.125436+02:00
21 changes: 12 additions & 9 deletions yandex/data_source_yandex_mdb_opensearch_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/opensearch/v1"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/yandex-cloud/go-sdk/sdkresolvers"
)

func dataSourceYandexMDBOpenSearchCluster() *schema.Resource {
return &schema.Resource{
Read: dataSourceYandexMDBOpenSearchClusterRead,
ReadContext: dataSourceYandexMDBOpenSearchClusterRead,
Schema: map[string]*schema.Schema{
"cluster_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -309,13 +310,12 @@ func dataSourceYandexMDBOpenSearchCluster() *schema.Resource {
}
}

func dataSourceYandexMDBOpenSearchClusterRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceYandexMDBOpenSearchClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
ctx := context.Background()

err := checkOneOf(d, "cluster_id", "name")
if err != nil {
return err
return diag.FromErr(err)
}

clusterID := d.Get("cluster_id").(string)
Expand All @@ -324,7 +324,7 @@ func dataSourceYandexMDBOpenSearchClusterRead(d *schema.ResourceData, meta inter
if clusterNameOk {
clusterID, err = resolveObjectID(ctx, config, d, sdkresolvers.OpenSearchClusterResolver)
if err != nil {
return fmt.Errorf("failed to resolve data source Opensearch Cluster by name: %v", err)
return diag.Errorf("failed to resolve data source Opensearch Cluster by name: %v", err)
}

d.Set("cluster_id", clusterID)
Expand All @@ -334,14 +334,17 @@ func dataSourceYandexMDBOpenSearchClusterRead(d *schema.ResourceData, meta inter
ClusterId: clusterID,
})
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("Cluster %q", d.Get("name").(string)))
return diag.FromErr(handleNotFoundError(err, d, fmt.Sprintf("Cluster %q", d.Get("name").(string))))
}

mw := flattenOpenSearchMaintenanceWindow(cluster.MaintenanceWindow)
if err := d.Set("maintenance_window", mw); err != nil {
return err
return diag.FromErr(err)
}

d.SetId(clusterID)
return resourceYandexMDBOpenSearchClusterReadEx(d, meta, "DataSource")
if err := resourceYandexMDBOpenSearchClusterReadEx(ctx, d, meta, "DataSource"); err != nil {
return diag.FromErr(err)
}
return nil
}
Loading

0 comments on commit 05aca83

Please sign in to comment.