Skip to content

Commit

Permalink
chore(deps): bump aiven-go-client to v2 (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel authored Sep 25, 2023
1 parent 35dd901 commit bda1d26
Show file tree
Hide file tree
Showing 163 changed files with 1,366 additions and 920 deletions.
4 changes: 3 additions & 1 deletion examples_tests/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/kelseyhightower/envconfig"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -64,6 +64,8 @@ func (s *BaseTestSuite) TearDownSuite() {
}

// withDefaults adds default options for terraform test
//
//lint:ignore U1000 Ignore unused function. Used in child structs
func (s *BaseTestSuite) withDefaults(opts *terraform.Options) *terraform.Options {
// No need to use lock file for dev build
opts.Lock = false
Expand Down
9 changes: 6 additions & 3 deletions examples_tests/kafka_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package examples

import (
"context"
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
Expand Down Expand Up @@ -39,19 +40,21 @@ func (s *KafkaConnectTestSuite) TestKafkaConnect() {
terraform.Apply(s.T(), opts)

// Then
kafkaService, err := s.client.Services.Get(s.config.Project, kafkaServiceName)
ctx := context.Background()

kafkaService, err := s.client.Services.Get(ctx, s.config.Project, kafkaServiceName)
s.NoError(err)
s.Equal("kafka", kafkaService.Type)
s.Equal("startup-2", kafkaService.Plan)
s.Equal("google-europe-west1", kafkaService.CloudName)

kafkaConnect, err := s.client.Services.Get(s.config.Project, kafkaConnectName)
kafkaConnect, err := s.client.Services.Get(ctx, s.config.Project, kafkaConnectName)
s.NoError(err)
s.Equal("kafka_connect", kafkaConnect.Type)
s.Equal("startup-4", kafkaConnect.Plan)
s.Equal("google-europe-west1", kafkaConnect.CloudName)

integrations, err := s.client.ServiceIntegrations.List(s.config.Project, kafkaServiceName)
integrations, err := s.client.ServiceIntegrations.List(ctx, s.config.Project, kafkaServiceName)
s.NoError(err)

// We don't have integration ID here
Expand Down
9 changes: 6 additions & 3 deletions examples_tests/kafka_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package examples

import (
"context"
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
Expand Down Expand Up @@ -43,17 +44,19 @@ func (s *KafkaConnectorTestSuite) TestKafkaConnectorOS() {
terraform.Apply(s.T(), opts)

// Then
kafkaService, err := s.client.Services.Get(s.config.Project, kafkaServiceName)
ctx := context.Background()

kafkaService, err := s.client.Services.Get(ctx, s.config.Project, kafkaServiceName)
s.NoError(err)
s.Equal("kafka", kafkaService.Type)
s.Equal("business-4", kafkaService.Plan)
s.Equal("google-europe-west1", kafkaService.CloudName)

kafkaConnector, err := s.client.KafkaConnectors.GetByName(s.config.Project, kafkaServiceName, kafkaConnectorName)
kafkaConnector, err := s.client.KafkaConnectors.GetByName(ctx, s.config.Project, kafkaServiceName, kafkaConnectorName)
s.NoError(err)
s.Equal(kafkaConnector.Name, kafkaConnectorName)

osService, err := s.client.Services.Get(s.config.Project, osServiceName)
osService, err := s.client.Services.Get(ctx, s.config.Project, osServiceName)
s.NoError(err)
s.Equal("opensearch", osService.Type)
s.Equal("startup-4", osService.Plan)
Expand Down
11 changes: 7 additions & 4 deletions examples_tests/kafka_prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
package examples

import (
"context"
"testing"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -42,13 +43,15 @@ func (s *KafkaPrometheusTestSuite) TestKafkaPrometheus() {
terraform.Apply(s.T(), opts)

// Then
kafkaService, err := s.client.Services.Get(s.config.Project, kafkaServiceName)
ctx := context.Background()

kafkaService, err := s.client.Services.Get(ctx, s.config.Project, kafkaServiceName)
s.NoError(err)
s.Equal("kafka", kafkaService.Type)
s.Equal("business-4", kafkaService.Plan)
s.Equal("google-europe-west1", kafkaService.CloudName)

endpoints, err := s.client.ServiceIntegrationEndpoints.List(s.config.Project)
endpoints, err := s.client.ServiceIntegrationEndpoints.List(ctx, s.config.Project)
s.NoError(err)
foundEndpoints := make([]*aiven.ServiceIntegrationEndpoint, 0)
for _, e := range endpoints {
Expand All @@ -58,7 +61,7 @@ func (s *KafkaPrometheusTestSuite) TestKafkaPrometheus() {
}
s.Len(foundEndpoints, 1)

integrations, err := s.client.ServiceIntegrations.List(s.config.Project, kafkaServiceName)
integrations, err := s.client.ServiceIntegrations.List(ctx, s.config.Project, kafkaServiceName)
s.NoError(err)
foundIntegrations := 0
for _, i := range integrations {
Expand Down
5 changes: 4 additions & 1 deletion examples_tests/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package examples

import (
"context"
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
Expand Down Expand Up @@ -39,7 +40,9 @@ func (s *MysqlTestSuite) TestMysql() {
terraform.Apply(s.T(), opts)

// Then
mysql, err := s.client.Services.Get(s.config.Project, mysqlName)
ctx := context.Background()

mysql, err := s.client.Services.Get(ctx, s.config.Project, mysqlName)
s.NoError(err)
s.Equal("mysql", mysql.Type)
s.Equal("business-4", mysql.Plan)
Expand Down
9 changes: 6 additions & 3 deletions examples_tests/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package examples

import (
"context"
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
Expand Down Expand Up @@ -41,19 +42,21 @@ func (s *PostgresTestSuite) TestPostgres() {
terraform.Apply(s.T(), opts)

// Then
pgEU, err := s.client.Services.Get(s.config.Project, pgNameEU)
ctx := context.Background()

pgEU, err := s.client.Services.Get(ctx, s.config.Project, pgNameEU)
s.NoError(err)
s.Equal("pg", pgEU.Type)
s.Equal("startup-4", pgEU.Plan)
s.Equal("aws-eu-west-2", pgEU.CloudName)

pgUS, err := s.client.Services.Get(s.config.Project, pgNameUS)
pgUS, err := s.client.Services.Get(ctx, s.config.Project, pgNameUS)
s.NoError(err)
s.Equal("pg", pgUS.Type)
s.Equal("business-8", pgUS.Plan)
s.Equal("do-nyc", pgUS.CloudName)

pgAS, err := s.client.Services.Get(s.config.Project, pgNameAS)
pgAS, err := s.client.Services.Get(ctx, s.config.Project, pgNameAS)
s.NoError(err)
s.Equal("pg", pgAS.Type)
s.Equal("business-8", pgAS.Plan)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aiven/terraform-provider-aiven
go 1.21.1

require (
github.com/aiven/aiven-go-client v1.36.0
github.com/aiven/aiven-go-client/v2 v2.0.0
github.com/dave/jennifer v1.7.0
github.com/docker/go-units v0.5.0
github.com/ettle/strcase v0.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/aiven/aiven-go-client v1.36.0 h1:AUuldvYdk2b9wu4v7L9qx01d6ZB5VckiMgRW37yxZVE=
github.com/aiven/aiven-go-client v1.36.0/go.mod h1:3Hh1PDNcqNNCYrkU/jSAHMV/b/ynoy73fwhBPKnMe6I=
github.com/aiven/aiven-go-client/v2 v2.0.0 h1:eqeJveyqB1RKDUjT212gNjFujLqx45SXwokRlhjYARU=
github.com/aiven/aiven-go-client/v2 v2.0.0/go.mod h1:x0xhzxWEKAwKv0xY5FvECiI6tesWshcPHvjwl0B/1SU=
github.com/aiven/go-api-schemas v1.27.1-0.20230823111901-1e0306909d02 h1:nFAKxncY/5aokoDdnKRvUVsjV6MKQq0Cf/21uAPRjDg=
github.com/aiven/go-api-schemas v1.27.1-0.20230823111901-1e0306909d02/go.mod h1:RmQ8MfxwxAP2ji9eJtP6dICOaTMcQD9b5aQT3Bp7uzI=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down
7 changes: 5 additions & 2 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"testing"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/terraform"

Expand Down Expand Up @@ -62,6 +62,9 @@ func TestAccPreCheck(t *testing.T) {

func TestAccCheckAivenServiceResourceDestroy(s *terraform.State) error {
c := GetTestAivenClient()

ctx := context.Background()

// loop through the resources in state, verifying each service is destroyed
for n, rs := range s.RootModule().Resources {
// ignore datasource
Expand Down Expand Up @@ -95,7 +98,7 @@ func TestAccCheckAivenServiceResourceDestroy(s *terraform.State) error {
return err
}

p, err := c.Services.Get(projectName, serviceName)
p, err := c.Services.Get(ctx, projectName, serviceName)
if err != nil {
if !aiven.IsNotFound(err) {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
)

func NewAivenClient() (*aiven.Client, error) {
Expand Down
12 changes: 6 additions & 6 deletions internal/plugin/service/organization/organization_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package organization
import (
"context"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -132,13 +132,13 @@ func (r *organizationDataSource) ConfigValidators(_ context.Context) []datasourc
}

// fillModel fills the organization data source model from the Aiven API.
func (r *organizationDataSource) fillModel(model *organizationDataSourceModel) (err error) {
normalizedID, err := schemautil.NormalizeOrganizationID(r.client, model.ID.ValueString())
func (r *organizationDataSource) fillModel(ctx context.Context, model *organizationDataSourceModel) (err error) {
normalizedID, err := schemautil.NormalizeOrganizationID(ctx, r.client, model.ID.ValueString())
if err != nil {
return
}

account, err := r.client.Accounts.Get(normalizedID)
account, err := r.client.Accounts.Get(ctx, normalizedID)
if err != nil {
return
}
Expand All @@ -163,7 +163,7 @@ func (r *organizationDataSource) Read(ctx context.Context, req datasource.ReadRe
}

if state.ID.IsNull() {
list, err := r.client.Accounts.List()
list, err := r.client.Accounts.List(ctx)
if err != nil {
resp.Diagnostics = util.DiagErrorReadingDataSource(resp.Diagnostics, r, err)

Expand All @@ -187,7 +187,7 @@ func (r *organizationDataSource) Read(ctx context.Context, req datasource.ReadRe
}
}

err := r.fillModel(&state)
err := r.fillModel(ctx, &state)
if err != nil {
resp.Diagnostics = util.DiagErrorReadingDataSource(resp.Diagnostics, r, err)

Expand Down
24 changes: 12 additions & 12 deletions internal/plugin/service/organization/organization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package organization
import (
"context"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -123,13 +123,13 @@ func (r *organizationResource) Configure(
}

// fillModel fills the organization resource model from the Aiven API.
func (r *organizationResource) fillModel(model *organizationResourceModel) (err error) {
normalizedID, err := schemautil.NormalizeOrganizationID(r.client, model.ID.ValueString())
func (r *organizationResource) fillModel(ctx context.Context, model *organizationResourceModel) (err error) {
normalizedID, err := schemautil.NormalizeOrganizationID(ctx, r.client, model.ID.ValueString())
if err != nil {
return
}

account, err := r.client.Accounts.Get(normalizedID)
account, err := r.client.Accounts.Get(ctx, normalizedID)
if err != nil {
return
}
Expand All @@ -153,7 +153,7 @@ func (r *organizationResource) Create(ctx context.Context, req resource.CreateRe
return
}

account, err := r.client.Accounts.Create(aiven.Account{
account, err := r.client.Accounts.Create(ctx, aiven.Account{
Name: plan.Name.ValueString(),
})
if err != nil {
Expand All @@ -164,7 +164,7 @@ func (r *organizationResource) Create(ctx context.Context, req resource.CreateRe

plan.ID = types.StringValue(account.Account.OrganizationId)

err = r.fillModel(&plan)
err = r.fillModel(ctx, &plan)
if err != nil {
resp.Diagnostics = util.DiagErrorCreatingResource(resp.Diagnostics, r, err)

Expand All @@ -184,7 +184,7 @@ func (r *organizationResource) Read(ctx context.Context, req resource.ReadReques
return
}

err := r.fillModel(&state)
err := r.fillModel(ctx, &state)
if err != nil {
resp.Diagnostics = util.DiagErrorReadingResource(resp.Diagnostics, r, err)

Expand All @@ -204,14 +204,14 @@ func (r *organizationResource) Update(ctx context.Context, req resource.UpdateRe
return
}

normalizedID, err := schemautil.NormalizeOrganizationID(r.client, plan.ID.ValueString())
normalizedID, err := schemautil.NormalizeOrganizationID(ctx, r.client, plan.ID.ValueString())
if err != nil {
resp.Diagnostics = util.DiagErrorUpdatingResource(resp.Diagnostics, r, err)

return
}

_, err = r.client.Accounts.Update(normalizedID, aiven.Account{
_, err = r.client.Accounts.Update(ctx, normalizedID, aiven.Account{
Name: plan.Name.ValueString(),
})
if err != nil {
Expand All @@ -220,7 +220,7 @@ func (r *organizationResource) Update(ctx context.Context, req resource.UpdateRe
return
}

err = r.fillModel(&plan)
err = r.fillModel(ctx, &plan)
if err != nil {
resp.Diagnostics = util.DiagErrorUpdatingResource(resp.Diagnostics, r, err)

Expand All @@ -240,14 +240,14 @@ func (r *organizationResource) Delete(ctx context.Context, req resource.DeleteRe
return
}

normalizedID, err := schemautil.NormalizeOrganizationID(r.client, state.ID.ValueString())
normalizedID, err := schemautil.NormalizeOrganizationID(ctx, r.client, state.ID.ValueString())
if err != nil {
resp.Diagnostics = util.DiagErrorDeletingResource(resp.Diagnostics, r, err)

return
}

err = r.client.Accounts.Delete(normalizedID)
err = r.client.Accounts.Delete(ctx, normalizedID)
if err != nil {
resp.Diagnostics = util.DiagErrorDeletingResource(resp.Diagnostics, r, err)

Expand Down
6 changes: 3 additions & 3 deletions internal/schemautil/custom_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/aiven/aiven-go-client"
"github.com/aiven/aiven-go-client/v2"
"github.com/docker/go-units"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -126,7 +126,7 @@ func CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether(_ context.Contex

// CustomizeDiffCheckStaticIPDisassociation checks that we dont disassociate ips we should not
// and are not assigning ips that are not 'created'
func CustomizeDiffCheckStaticIPDisassociation(_ context.Context, d *schema.ResourceDiff, m interface{}) error {
func CustomizeDiffCheckStaticIPDisassociation(ctx context.Context, d *schema.ResourceDiff, m interface{}) error {
contains := func(l []string, e string) bool {
for i := range l {
if l[i] == e {
Expand All @@ -148,7 +148,7 @@ func CustomizeDiffCheckStaticIPDisassociation(_ context.Context, d *schema.Resou
plannedStaticIps = FlattenToString(staticIps.(*schema.Set).List())
}

resp, err := client.StaticIPs.List(projectName)
resp, err := client.StaticIPs.List(ctx, projectName)
if err != nil {
return fmt.Errorf("unable to get static ips for project '%s': %w", projectName, err)
}
Expand Down
Loading

0 comments on commit bda1d26

Please sign in to comment.