From 8712b3397ca5c5dfbcd6da380abcbe88d0054332 Mon Sep 17 00:00:00 2001 From: Aleksander Zaruczewski Date: Thu, 14 Sep 2023 14:37:35 -0400 Subject: [PATCH] chore(deps): bump aiven-go-client to v2 --- examples_tests/base.go | 4 +- examples_tests/kafka_connect_test.go | 9 +- examples_tests/kafka_connector_test.go | 9 +- examples_tests/kafka_prometheus_test.go | 11 +- examples_tests/mysql_test.go | 5 +- examples_tests/postgres_test.go | 9 +- go.mod | 4 +- go.sum | 28 +- internal/acctest/acctest.go | 7 +- internal/common/client.go | 2 +- .../organization/organization_data_source.go | 12 +- .../organization/organization_resource.go | 24 +- internal/schemautil/custom_diff.go | 6 +- internal/schemautil/database.go | 6 +- internal/schemautil/helpers.go | 17 +- internal/schemautil/schemautil.go | 2 +- internal/schemautil/service.go | 20 +- internal/schemautil/service_user.go | 17 +- internal/schemautil/static_ips.go | 10 +- .../stateupgrader/v0/kafka/kafka.go | 4 +- internal/schemautil/wait.go | 32 ++- .../sdkprovider/service/account/account.go | 11 +- .../service/account/account_authentication.go | 13 +- .../account_authentication_data_source.go | 4 +- .../account/account_authentication_test.go | 19 +- .../service/account/account_data_source.go | 4 +- .../service/account/account_team.go | 13 +- .../account/account_team_data_source.go | 4 +- .../service/account/account_team_member.go | 18 +- .../account/account_team_member_test.go | 9 +- .../service/account/account_team_project.go | 13 +- .../account/account_team_project_test.go | 9 +- .../service/account/account_team_test.go | 9 +- .../service/account/account_test.go | 7 +- internal/sdkprovider/service/account/sweep.go | 265 +++++++++--------- .../service/cassandra/cassandra_user_test.go | 7 +- .../service/clickhouse/clickhouse_database.go | 12 +- .../clickhouse_database_data_source.go | 4 +- .../service/clickhouse/clickhouse_grant.go | 18 +- .../clickhouse/clickhouse_grant_test.go | 15 +- .../service/clickhouse/clickhouse_role.go | 12 +- .../clickhouse/clickhouse_role_test.go | 7 +- .../service/clickhouse/clickhouse_user.go | 11 +- .../clickhouse/clickhouse_user_data_source.go | 4 +- .../clickhouse/clickhouse_user_test.go | 7 +- .../sdkprovider/service/clickhouse/grant.go | 63 ++++- .../sdkprovider/service/clickhouse/role.go | 15 +- .../service/connectionpool/connection_pool.go | 12 +- .../connection_pool_data_source.go | 4 +- .../connectionpool/connection_pool_test.go | 7 +- .../service/flink/flink_application.go | 14 +- .../flink/flink_application_data_source.go | 4 +- .../flink/flink_application_deployment.go | 14 +- .../flink/flink_application_version.go | 12 +- .../flink_application_version_data_source.go | 4 +- .../flink/flink_application_version_test.go | 8 +- .../service/influxdb/influxdb_database.go | 8 +- .../influxdb/influxdb_database_data_source.go | 4 +- .../influxdb/influxdb_database_test.go | 7 +- .../service/influxdb/influxdb_user_test.go | 7 +- internal/sdkprovider/service/kafka/kafka.go | 10 +- .../sdkprovider/service/kafka/kafka_acl.go | 11 +- .../service/kafka/kafka_acl_cache.go | 30 +- .../service/kafka/kafka_acl_data_source.go | 4 +- .../service/kafka/kafka_acl_test.go | 7 +- .../service/kafka/kafka_connector.go | 12 +- .../kafka/kafka_connector_data_source.go | 4 +- .../service/kafka/kafka_connector_test.go | 11 +- .../sdkprovider/service/kafka/kafka_test.go | 10 +- .../service/kafka/kafka_user_test.go | 7 +- .../kafka/mirrormaker_replication_flow.go | 13 +- .../mirrormaker_replication_flow_test.go | 9 +- .../service/kafkaschema/kafka_schema.go | 33 ++- .../kafkaschema/kafka_schema_configuration.go | 11 +- .../kafka_schema_configuration_data_source.go | 4 +- .../kafkaschema/kafka_schema_data_source.go | 4 +- .../kafkaschema/kafka_schema_registry_acl.go | 11 +- .../kafka_schema_registry_acl_data_source.go | 4 +- .../kafka_schema_registry_acl_test.go | 7 +- .../service/kafkaschema/kafka_schema_test.go | 11 +- .../service/kafkatopic/kafka_topic.go | 12 +- .../service/kafkatopic/kafka_topic_cache.go | 2 +- .../kafkatopic/kafka_topic_cache_test.go | 2 +- .../service/kafkatopic/kafka_topic_create.go | 5 +- .../service/kafkatopic/kafka_topic_test.go | 18 +- .../service/kafkatopic/kafka_topic_wait.go | 17 +- .../service/m3db/m3db_user_test.go | 7 +- .../service/mysql/mysql_database.go | 7 +- .../mysql/mysql_database_data_source.go | 4 +- .../service/mysql/mysql_database_test.go | 7 +- .../sdkprovider/service/mysql/mysql_user.go | 7 +- .../service/mysql/mysql_user_test.go | 7 +- .../sdkprovider/service/opensearch/common.go | 32 ++- .../opensearch/opensearch_acl_config.go | 12 +- .../opensearch_acl_config_data_source.go | 4 +- .../opensearch/opensearch_acl_config_test.go | 7 +- .../service/opensearch/opensearch_acl_rule.go | 16 +- .../opensearch_acl_rule_data_source.go | 4 +- .../opensearch/opensearch_acl_rule_test.go | 7 +- .../opensearch_security_plugin_config.go | 8 +- ...arch_security_plugin_config_data_source.go | 4 +- .../service/opensearch/opensearch_user.go | 16 +- .../opensearch/opensearch_user_test.go | 7 +- .../service/organization/organization_user.go | 16 +- .../organization/organization_user_group.go | 13 +- .../organization_user_group_data_source.go | 4 +- .../organization_user_group_test.go | 7 +- .../organization/organization_user_test.go | 9 +- .../organization/organizational_unit.go | 16 +- .../organizational_unit_data_source.go | 4 +- internal/sdkprovider/service/pg/pg.go | 9 +- .../sdkprovider/service/pg/pg_database.go | 7 +- .../service/pg/pg_database_data_source.go | 4 +- .../service/pg/pg_database_test.go | 7 +- internal/sdkprovider/service/pg/pg_test.go | 32 ++- internal/sdkprovider/service/pg/pg_user.go | 11 +- .../service/pg/pg_user_data_source.go | 4 +- .../sdkprovider/service/pg/pg_user_test.go | 7 +- .../service/project/billing_group.go | 29 +- .../service/project/billing_group_test.go | 7 +- .../sdkprovider/service/project/project.go | 78 ++++-- .../service/project/project_data_source.go | 8 +- .../service/project/project_test.go | 7 +- .../service/project/project_user.go | 14 +- .../project/project_user_data_source.go | 4 +- .../service/project/project_user_test.go | 7 +- internal/sdkprovider/service/project/sweep.go | 4 +- internal/sdkprovider/service/project/util.go | 8 +- .../sdkprovider/service/redis/redis_user.go | 11 +- .../service/redis/redis_user_data_source.go | 4 +- .../service/redis/redis_user_test.go | 7 +- .../service_component_data_source.go | 6 +- .../serviceintegration/service_integration.go | 20 +- .../service_integration_data_source.go | 4 +- .../service_integration_endpoint.go | 12 +- ...ervice_integration_endpoint_data_source.go | 4 +- .../service_integration_endpoint_test.go | 7 +- .../service_integration_test.go | 7 +- .../service/serviceintegration/sweep.go | 6 +- .../sdkprovider/service/staticip/static_ip.go | 17 +- .../sdkprovider/service/staticip/sweep.go | 4 +- .../service/vpc/aws_privatelink.go | 17 +- .../service/vpc/aws_vpc_peering_connection.go | 24 +- .../aws_vpc_peering_connection_data_source.go | 4 +- .../service/vpc/azure_privatelink.go | 40 ++- .../azure_privatelink_connection_approve.go | 28 +- .../service/vpc/azure_privatelink_test.go | 7 +- .../vpc/azure_vpc_peering_connection.go | 26 +- ...zure_vpc_peering_connection_data_source.go | 4 +- .../service/vpc/gcp_privatelink.go | 24 +- .../vpc/gcp_privatelink_connection_approve.go | 17 +- .../service/vpc/gcp_privatelink_test.go | 7 +- .../service/vpc/gcp_vpc_peering_connection.go | 24 +- .../gcp_vpc_peering_connection_data_source.go | 4 +- .../vpc/gcp_vpc_peering_connection_test.go | 10 +- .../sdkprovider/service/vpc/project_vpc.go | 17 +- .../service/vpc/project_vpc_data_source.go | 6 +- .../vpc/project_vpc_data_source_test.go | 2 +- .../service/vpc/project_vpc_test.go | 7 +- .../vpc/transit_gateway_vpc_attachment.go | 6 +- .../service/vpc/vpc_peering_connection.go | 36 ++- .../vpc/vpc_peering_connection_data_source.go | 4 +- internal/sweep/sweep.go | 20 +- 163 files changed, 1276 insertions(+), 824 deletions(-) diff --git a/examples_tests/base.go b/examples_tests/base.go index fa5144417..3c27812dc 100644 --- a/examples_tests/base.go +++ b/examples_tests/base.go @@ -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" @@ -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 diff --git a/examples_tests/kafka_connect_test.go b/examples_tests/kafka_connect_test.go index f9c1f6d0e..30da5a725 100644 --- a/examples_tests/kafka_connect_test.go +++ b/examples_tests/kafka_connect_test.go @@ -3,6 +3,7 @@ package examples import ( + "context" "testing" "github.com/gruntwork-io/terratest/modules/terraform" @@ -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 diff --git a/examples_tests/kafka_connector_test.go b/examples_tests/kafka_connector_test.go index ff30666aa..2049b4981 100644 --- a/examples_tests/kafka_connector_test.go +++ b/examples_tests/kafka_connector_test.go @@ -3,6 +3,7 @@ package examples import ( + "context" "testing" "github.com/gruntwork-io/terratest/modules/terraform" @@ -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) diff --git a/examples_tests/kafka_prometheus_test.go b/examples_tests/kafka_prometheus_test.go index 8f2b5133c..3638de290 100644 --- a/examples_tests/kafka_prometheus_test.go +++ b/examples_tests/kafka_prometheus_test.go @@ -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" ) @@ -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 { @@ -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 { diff --git a/examples_tests/mysql_test.go b/examples_tests/mysql_test.go index f8da77a18..5ff307e57 100644 --- a/examples_tests/mysql_test.go +++ b/examples_tests/mysql_test.go @@ -3,6 +3,7 @@ package examples import ( + "context" "testing" "github.com/gruntwork-io/terratest/modules/terraform" @@ -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) diff --git a/examples_tests/postgres_test.go b/examples_tests/postgres_test.go index 363d161ce..18c537d6c 100644 --- a/examples_tests/postgres_test.go +++ b/examples_tests/postgres_test.go @@ -3,6 +3,7 @@ package examples import ( + "context" "testing" "github.com/gruntwork-io/terratest/modules/terraform" @@ -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) diff --git a/go.mod b/go.mod index a2fd9831f..b22c91451 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module github.com/aiven/terraform-provider-aiven -go 1.19 +go 1.21 require ( - github.com/aiven/aiven-go-client v1.36.0 + github.com/aiven/aiven-go-client/v2 v2.0.0-rc.5 github.com/dave/jennifer v1.7.0 github.com/docker/go-units v0.5.0 github.com/ettle/strcase v0.1.1 diff --git a/go.sum b/go.sum index b642b0806..409fd9307 100644 --- a/go.sum +++ b/go.sum @@ -116,6 +116,7 @@ cloud.google.com/go/language v1.6.0/go.mod h1:6dJ8t3B+lUYfStgls25GusK04NLh3eDLQn cloud.google.com/go/lifesciences v0.5.0/go.mod h1:3oIKy8ycWGPUyZDR/8RNnTOYevhaMLqh5vLUXs9zvT8= cloud.google.com/go/lifesciences v0.6.0/go.mod h1:ddj6tSX/7BOnhxCSd3ZcETvtNr8NZ6t/iPhY2Tyfu08= cloud.google.com/go/longrunning v0.4.1 h1:v+yFJOfKC3yZdY6ZUI933pIYdhyhV8S3NpWrXWmg7jM= +cloud.google.com/go/longrunning v0.4.1/go.mod h1:4iWDqhBZ70CvZ6BfETbvam3T8FMvLK+eFj0E6AaRQTo= cloud.google.com/go/mediatranslation v0.5.0/go.mod h1:jGPUhGTybqsPQn91pNXw0xVHfuJ3leR1wj37oU3y1f4= cloud.google.com/go/mediatranslation v0.6.0/go.mod h1:hHdBCTYNigsBxshbznuIMFNe5QXEowAuNmmC7h8pu5w= cloud.google.com/go/memcache v1.4.0/go.mod h1:rTOfiGZtJX1AaFUrOgsMHX5kAzaTQ8azHiuDoTPzNsE= @@ -189,15 +190,17 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= +github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= 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-rc.5 h1:iftFzqK5NKsrwxVP/4rN6CG4UNKjAbyeO/ZGYZPDnQo= +github.com/aiven/aiven-go-client/v2 v2.0.0-rc.5/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= @@ -240,6 +243,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -257,10 +261,14 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= +github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= +github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= github.com/go-git/go-git/v5 v5.6.1 h1:q4ZRqQl4pR/ZJHc1L5CFjGA1a10u76aV1iC+nh+bHsk= +github.com/go-git/go-git/v5 v5.6.1/go.mod h1:mvyoL6Unz0PiTQrGQfSfiLFhBH1c1e84ylC2MDs4ee8= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -327,6 +335,7 @@ github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIG github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw= +github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= @@ -431,8 +440,11 @@ github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbg github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= +github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o= github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -444,6 +456,7 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= @@ -485,11 +498,15 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw= +github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -498,7 +515,9 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= +github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -529,6 +548,7 @@ github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgq github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -768,6 +788,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= +golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1066,11 +1087,14 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/acctest/acctest.go b/internal/acctest/acctest.go index 44ba68e04..828b5e690 100644 --- a/internal/acctest/acctest.go +++ b/internal/acctest/acctest.go @@ -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" @@ -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 @@ -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 diff --git a/internal/common/client.go b/internal/common/client.go index 33ca1002e..494eb1766 100644 --- a/internal/common/client.go +++ b/internal/common/client.go @@ -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) { diff --git a/internal/plugin/service/organization/organization_data_source.go b/internal/plugin/service/organization/organization_data_source.go index 75295cfa3..723e6a287 100644 --- a/internal/plugin/service/organization/organization_data_source.go +++ b/internal/plugin/service/organization/organization_data_source.go @@ -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" @@ -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 } @@ -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) @@ -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) diff --git a/internal/plugin/service/organization/organization_resource.go b/internal/plugin/service/organization/organization_resource.go index cff23ba06..d0ac680b4 100644 --- a/internal/plugin/service/organization/organization_resource.go +++ b/internal/plugin/service/organization/organization_resource.go @@ -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" @@ -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 } @@ -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 { @@ -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) @@ -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) @@ -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 { @@ -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) @@ -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) diff --git a/internal/schemautil/custom_diff.go b/internal/schemautil/custom_diff.go index 5019feb80..7ebbee80a 100644 --- a/internal/schemautil/custom_diff.go +++ b/internal/schemautil/custom_diff.go @@ -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" @@ -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 { @@ -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) } diff --git a/internal/schemautil/database.go b/internal/schemautil/database.go index 8d8ad6157..c9d0150e1 100644 --- a/internal/schemautil/database.go +++ b/internal/schemautil/database.go @@ -1,14 +1,16 @@ package schemautil import ( + "context" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) // DatabaseDeleteWaiter is used to wait for Database to be deleted. type DatabaseDeleteWaiter struct { + Context context.Context Client *aiven.Client ProjectName string ServiceName string @@ -19,7 +21,7 @@ type DatabaseDeleteWaiter struct { // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. func (w *DatabaseDeleteWaiter) RefreshFunc() resource.StateRefreshFunc { return func() (interface{}, string, error) { - err := w.Client.Databases.Delete(w.ProjectName, w.ServiceName, w.Database) + err := w.Client.Databases.Delete(w.Context, w.ProjectName, w.ServiceName, w.Database) if err != nil && !aiven.IsNotFound(err) { return nil, "REMOVING", nil } diff --git a/internal/schemautil/helpers.go b/internal/schemautil/helpers.go index 661b2bb3d..e1b87ab99 100644 --- a/internal/schemautil/helpers.go +++ b/internal/schemautil/helpers.go @@ -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/terraform-plugin-sdk/v2/diag" ) @@ -91,8 +91,8 @@ func GetServicePlanParametersFromSchema(ctx context.Context, client *aiven.Clien return getServicePlanParametersInternal(ctx, client, project, serviceType, servicePlan) } -func getServicePlanParametersInternal(_ context.Context, client *aiven.Client, project, serviceType, servicePlan string) (PlanParameters, error) { - servicePlanResponse, err := client.ServiceTypes.GetPlan(project, serviceType, servicePlan) +func getServicePlanParametersInternal(ctx context.Context, client *aiven.Client, project, serviceType, servicePlan string) (PlanParameters, error) { + servicePlanResponse, err := client.ServiceTypes.GetPlan(ctx, project, serviceType, servicePlan) if err != nil { return PlanParameters{}, err } @@ -103,7 +103,7 @@ func getServicePlanParametersInternal(_ context.Context, client *aiven.Client, p }, nil } -func dynamicDiskSpaceIsAllowedByPricing(_ context.Context, client *aiven.Client, d ResourceStateOrResourceDiff) (bool, error) { +func dynamicDiskSpaceIsAllowedByPricing(ctx context.Context, client *aiven.Client, d ResourceStateOrResourceDiff) (bool, error) { // to check if dynamic disk space is allowed, we currently have to check // the pricing api to see if the `extra_disk_price_per_gb_usd` field is set @@ -112,7 +112,7 @@ func dynamicDiskSpaceIsAllowedByPricing(_ context.Context, client *aiven.Client, servicePlan := d.Get("plan").(string) cloudName := d.Get("cloud_name").(string) - servicePlanPricingResponse, err := client.ServiceTypes.GetPlanPricing(project, serviceType, servicePlan, cloudName) + servicePlanPricingResponse, err := client.ServiceTypes.GetPlanPricing(ctx, project, serviceType, servicePlan, cloudName) if err != nil { return false, fmt.Errorf("unable to get service plan pricing from api: %w", err) } @@ -135,9 +135,9 @@ func isStringAnOrganizationID(s string) bool { // NormalizeOrganizationID is a helper function that returns the ID to use for the API call. // If the ID is an organization ID, it will be converted to an account ID via the API. // If the ID is an account ID, it will be returned as is, without performing any API calls. -func NormalizeOrganizationID(client *aiven.Client, id string) (string, error) { +func NormalizeOrganizationID(ctx context.Context, client *aiven.Client, id string) (string, error) { if isStringAnOrganizationID(id) { - r, err := client.Organization.Get(id) + r, err := client.Organization.Get(ctx, id) if err != nil { return "", err } @@ -156,6 +156,7 @@ func NormalizeOrganizationID(client *aiven.Client, id string) (string, error) { // If the ID is an account ID, it will be returned as is, without performing any API calls. // If the ID is an organization ID, it will be refreshed via the provided account ID and returned. func DetermineMixedOrganizationConstraintIDToStore( + ctx context.Context, client *aiven.Client, stateID string, accountID string, @@ -168,7 +169,7 @@ func DetermineMixedOrganizationConstraintIDToStore( return accountID, nil } - r, err := client.Accounts.Get(accountID) + r, err := client.Accounts.Get(ctx, accountID) if err != nil { return "", err } diff --git a/internal/schemautil/schemautil.go b/internal/schemautil/schemautil.go index 850c57989..0ec28177a 100644 --- a/internal/schemautil/schemautil.go +++ b/internal/schemautil/schemautil.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/docker/go-units" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) diff --git a/internal/schemautil/service.go b/internal/schemautil/service.go index 59293dc15..785785011 100644 --- a/internal/schemautil/service.go +++ b/internal/schemautil/service.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/docker/go-units" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -332,7 +332,7 @@ func ResourceServiceRead(ctx context.Context, d *schema.ResourceData, m interfac return diag.Errorf("error splitting service ID: %s", err) } - s, err := client.Services.Get(projectName, serviceName) + s, err := client.Services.Get(ctx, projectName, serviceName) if err != nil { if err = ResourceReadHandleNotFound(err, d); err != nil { return diag.Errorf("unable to GET service %s: %s", d.Id(), err) @@ -358,7 +358,7 @@ func ResourceServiceRead(ctx context.Context, d *schema.ResourceData, m interfac return diag.Errorf("unable to set static ips field in schema: %s", err) } - t, err := client.ServiceTags.Get(projectName, serviceName) + t, err := client.ServiceTags.Get(ctx, projectName, serviceName) if err != nil { return diag.Errorf("unable to get service tags: %s", err) } @@ -409,6 +409,7 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, m interf } _, err = client.Services.Create( + ctx, project, aiven.CreateServiceRequest{ Cloud: d.Get("cloud_name").(string), @@ -435,7 +436,7 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, m interf return diag.Errorf("error waiting for service creation: %s", err) } - _, err = client.ServiceTags.Set(project, d.Get("service_name").(string), aiven.ServiceTagsRequest{ + _, err = client.ServiceTags.Set(ctx, project, d.Get("service_name").(string), aiven.ServiceTagsRequest{ Tags: GetTagsFromSchema(d), }) if err != nil { @@ -476,7 +477,7 @@ func ResourceServiceUpdate(ctx context.Context, d *schema.ResourceData, m interf // associate first, so that we can enable `static_ips` for a preexisting common for _, aip := range ass { - if err := client.StaticIPs.Associate(projectName, aip, aiven.AssociateStaticIPRequest{ServiceName: serviceName}); err != nil { + if err := client.StaticIPs.Associate(ctx, projectName, aip, aiven.AssociateStaticIPRequest{ServiceName: serviceName}); err != nil { return diag.Errorf("error associating Static IP (%s) to a service: %s", aip, err) } } @@ -497,6 +498,7 @@ func ResourceServiceUpdate(ctx context.Context, d *schema.ResourceData, m interf } if _, err := client.Services.Update( + ctx, projectName, serviceName, aiven.UpdateServiceRequest{ @@ -520,7 +522,7 @@ func ResourceServiceUpdate(ctx context.Context, d *schema.ResourceData, m interf if len(dis) > 0 { for _, dip := range dis { - if err := client.StaticIPs.Dissociate(projectName, dip); err != nil { + if err := client.StaticIPs.Dissociate(ctx, projectName, dip); err != nil { return diag.Errorf("error dissociating Static IP (%s) from the service (%s): %s", dip, serviceName, err) } } @@ -529,7 +531,7 @@ func ResourceServiceUpdate(ctx context.Context, d *schema.ResourceData, m interf } } - _, err = client.ServiceTags.Set(projectName, serviceName, aiven.ServiceTagsRequest{ + _, err = client.ServiceTags.Set(ctx, projectName, serviceName, aiven.ServiceTagsRequest{ Tags: GetTagsFromSchema(d), }) if err != nil { @@ -572,7 +574,7 @@ func ResourceServiceDelete(ctx context.Context, d *schema.ResourceData, m interf return diag.Errorf("error splitting service ID: %s", err) } - if err := client.Services.Delete(projectName, serviceName); err != nil && !aiven.IsNotFound(err) { + if err := client.Services.Delete(ctx, projectName, serviceName); err != nil && !aiven.IsNotFound(err) { return diag.Errorf("error deleting a service: %s", err) } @@ -842,7 +844,7 @@ func DatasourceServiceRead(ctx context.Context, d *schema.ResourceData, m interf serviceName := d.Get("service_name").(string) d.SetId(BuildResourceID(projectName, serviceName)) - services, err := client.Services.List(projectName) + services, err := client.Services.List(ctx, projectName) if err != nil { return diag.Errorf("error getting a list of services: %s", err) } diff --git a/internal/schemautil/service_user.go b/internal/schemautil/service_user.go index 8d7257873..c9193ab31 100644 --- a/internal/schemautil/service_user.go +++ b/internal/schemautil/service_user.go @@ -5,7 +5,7 @@ import ( "fmt" "log" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -19,6 +19,7 @@ func ResourceServiceUserCreate(ctx context.Context, d *schema.ResourceData, m in serviceName := d.Get("service_name").(string) username := d.Get("username").(string) _, err := client.ServiceUsers.Create( + ctx, projectName, serviceName, aiven.CreateServiceUserRequest{ @@ -30,7 +31,7 @@ func ResourceServiceUserCreate(ctx context.Context, d *schema.ResourceData, m in } if _, ok := d.GetOk("password"); ok { - _, err := client.ServiceUsers.Update(projectName, serviceName, username, + _, err := client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ NewPassword: OptionalStringPointer(d, "password"), }) @@ -52,7 +53,7 @@ func ResourceServiceUserUpdate(ctx context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - _, err = client.ServiceUsers.Update(projectName, serviceName, username, + _, err = client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ NewPassword: OptionalStringPointer(d, "password"), }) @@ -63,7 +64,7 @@ func ResourceServiceUserUpdate(ctx context.Context, d *schema.ResourceData, m in return ResourceServiceUserRead(ctx, d, m) } -func ResourceServiceUserRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func ResourceServiceUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, username, err := SplitResourceID3(d.Id()) @@ -71,7 +72,7 @@ func ResourceServiceUserRead(_ context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } - user, err := client.ServiceUsers.Get(projectName, serviceName, username) + user, err := client.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { return diag.FromErr(ResourceReadHandleNotFound(err, d)) } @@ -84,7 +85,7 @@ func ResourceServiceUserRead(_ context.Context, d *schema.ResourceData, m interf return nil } -func ResourceServiceUserDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func ResourceServiceUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, username, err := SplitResourceID3(d.Id()) @@ -92,7 +93,7 @@ func ResourceServiceUserDelete(_ context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - err = client.ServiceUsers.Delete(projectName, serviceName, username) + err = client.ServiceUsers.Delete(ctx, projectName, serviceName, username) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } @@ -107,7 +108,7 @@ func DatasourceServiceUserRead(ctx context.Context, d *schema.ResourceData, m in serviceName := d.Get("service_name").(string) userName := d.Get("username").(string) - list, err := client.ServiceUsers.List(projectName, serviceName) + list, err := client.ServiceUsers.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/schemautil/static_ips.go b/internal/schemautil/static_ips.go index 17d4b7f60..f15250507 100644 --- a/internal/schemautil/static_ips.go +++ b/internal/schemautil/static_ips.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -15,11 +15,11 @@ const ( StaticIPAssigned = "assigned" ) -func CurrentlyAllocatedStaticIps(_ context.Context, projectName, serviceName string, m interface{}) ([]string, error) { +func CurrentlyAllocatedStaticIps(ctx context.Context, projectName, serviceName string, m interface{}) ([]string, error) { client := m.(*aiven.Client) // special handling for static ips - staticIPListResponse, err := client.StaticIPs.List(projectName) + staticIPListResponse, err := client.StaticIPs.List(ctx, projectName) if err != nil { return nil, fmt.Errorf("unable to list static ips for project '%s': %w", projectName, err) } @@ -48,13 +48,13 @@ func staticIpsFromSchema(d *schema.ResourceData) []string { return FlattenToString(d.Get("static_ips").(*schema.Set).List()) } -func staticIpsFromAPI(_ context.Context, d *schema.ResourceData, m interface{}) ([]string, error) { +func staticIpsFromAPI(ctx context.Context, d *schema.ResourceData, m interface{}) ([]string, error) { client := m.(*aiven.Client) project := d.Get("project").(string) serviceName := d.Get("service_name").(string) - staticIpsForProject, err := client.StaticIPs.List(project) + staticIpsForProject, err := client.StaticIPs.List(ctx, project) if err != nil { return nil, fmt.Errorf("unable to list static ips for project '%s': %w", project, err) } diff --git a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go index 1f73ddcd5..bfeea13f6 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go @@ -5,7 +5,7 @@ import ( "strconv" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -124,7 +124,7 @@ func ResourceKafka() *schema.Resource { serviceName := d.Get("service_name").(string) client := m.(*aiven.Client) - kafka, err := client.Services.Get(project, serviceName) + kafka, err := client.Services.Get(ctx, project, serviceName) if err != nil { return false } diff --git a/internal/schemautil/wait.go b/internal/schemautil/wait.go index 57fa1c2ed..fd3dad03a 100644 --- a/internal/schemautil/wait.go +++ b/internal/schemautil/wait.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -37,7 +37,7 @@ func WaitForServiceCreation(ctx context.Context, d *schema.ResourceData, m inter MinTimeout: 2 * time.Second, ContinuousTargetOccurence: 5, Refresh: func() (interface{}, string, error) { - service, err := client.Services.Get(projectName, serviceName) + service, err := client.Services.Get(ctx, projectName, serviceName) if err != nil { return nil, "", fmt.Errorf("unable to fetch service from api: %w", err) } @@ -59,7 +59,7 @@ func WaitForServiceCreation(ctx context.Context, d *schema.ResourceData, m inter return service, aivenServicesStartingState, nil } - if rdy, err := staticIpsReady(d, m); err != nil { + if rdy, err := staticIpsReady(ctx, d, m); err != nil { return nil, "", fmt.Errorf("unable to check if static ips are ready: %w", err) } else if !rdy { log.Printf("[DEBUG] service reports as %s, still waiting for static ips", state) @@ -94,7 +94,7 @@ func WaitForServiceUpdate(ctx context.Context, d *schema.ResourceData, m interfa MinTimeout: 2 * time.Second, ContinuousTargetOccurence: 5, Refresh: func() (interface{}, string, error) { - service, err := client.Services.Get(projectName, serviceName) + service, err := client.Services.Get(ctx, projectName, serviceName) if err != nil { return nil, "", fmt.Errorf("unable to fetch service from api: %w", err) } @@ -111,7 +111,7 @@ func WaitForServiceUpdate(ctx context.Context, d *schema.ResourceData, m interfa return service, "updating", nil } - if rdy, err := staticIpsReady(d, m); err != nil { + if rdy, err := staticIpsReady(ctx, d, m); err != nil { return nil, "", fmt.Errorf("unable to check if static ips are ready: %w", err) } else if !rdy { log.Printf("[DEBUG] service reports as %s, still waiting for static ips", state) @@ -142,7 +142,7 @@ func WaitStaticIpsDissassociation(ctx context.Context, d *schema.ResourceData, m MinTimeout: 2 * time.Second, ContinuousTargetOccurence: 5, Refresh: func() (interface{}, string, error) { - if dis, err := staticIpsAreDisassociated(d, m); err != nil { + if dis, err := staticIpsAreDisassociated(ctx, d, m); err != nil { return nil, "", fmt.Errorf("unable to check if static ips are disassociated: %w", err) } else if !dis { log.Printf("[DEBUG] still waiting for static ips to be disassociated") @@ -176,14 +176,14 @@ func WaitForDeletion(ctx context.Context, d *schema.ResourceData, m interface{}) MinTimeout: 20 * time.Second, ContinuousTargetOccurence: 5, Refresh: func() (interface{}, string, error) { - _, err := client.Services.Get(projectName, serviceName) + _, err := client.Services.Get(ctx, projectName, serviceName) if err != nil && !aiven.IsNotFound(err) { return nil, "", fmt.Errorf("unable to check if service is gone: %w", err) } log.Printf("[DEBUG] service gone, still waiting for static ips to be disassociated") - if dis, err := staticIpsDisassociatedAfterServiceDeletion(d, m); err != nil { + if dis, err := staticIpsDisassociatedAfterServiceDeletion(ctx, d, m); err != nil { return nil, "", fmt.Errorf("unable to check if static ips are disassociated: %w", err) } else if !dis { return struct{}{}, "deleting", nil @@ -270,7 +270,7 @@ func backupsReady(service *aiven.Service) bool { // staticIpsReady checks that the static ips that are associated with the service are either // in state 'assigned' or 'available' -func staticIpsReady(d *schema.ResourceData, m interface{}) (bool, error) { +func staticIpsReady(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { expectedStaticIps := staticIpsForServiceFromSchema(d) if len(expectedStaticIps) == 0 { return true, nil @@ -279,7 +279,7 @@ func staticIpsReady(d *schema.ResourceData, m interface{}) (bool, error) { client := m.(*aiven.Client) projectName, serviceName := d.Get("project").(string), d.Get("service_name").(string) - staticIpsList, err := client.StaticIPs.List(projectName) + staticIpsList, err := client.StaticIPs.List(ctx, projectName) if err != nil { return false, fmt.Errorf("unable to fetch static ips for project '%s': '%w", projectName, err) } @@ -303,7 +303,11 @@ L: // staticIpsDisassociatedAfterServiceDeletion checks that after service deletion // all static ips that were associated to the service are available again -func staticIpsDisassociatedAfterServiceDeletion(d *schema.ResourceData, m interface{}) (bool, error) { +func staticIpsDisassociatedAfterServiceDeletion( + ctx context.Context, + d *schema.ResourceData, + m interface{}, +) (bool, error) { expectedStaticIps := staticIpsForServiceFromSchema(d) if len(expectedStaticIps) == 0 { return true, nil @@ -312,7 +316,7 @@ func staticIpsDisassociatedAfterServiceDeletion(d *schema.ResourceData, m interf client := m.(*aiven.Client) projectName := d.Get("project").(string) - staticIpsList, err := client.StaticIPs.List(projectName) + staticIpsList, err := client.StaticIPs.List(ctx, projectName) if err != nil { return false, fmt.Errorf("unable to fetch static ips for project '%s': '%w", projectName, err) } @@ -334,12 +338,12 @@ func staticIpsDisassociatedAfterServiceDeletion(d *schema.ResourceData, m interf // staticIpsAreDisassociated checks that after service update // all static ips that are not used by the service anymore are available again -func staticIpsAreDisassociated(d *schema.ResourceData, m interface{}) (bool, error) { +func staticIpsAreDisassociated(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) { client := m.(*aiven.Client) projectName := d.Get("project").(string) serviceName := d.Get("service_name").(string) - staticIpsList, err := client.StaticIPs.List(projectName) + staticIpsList, err := client.StaticIPs.List(ctx, projectName) if err != nil { return false, fmt.Errorf("unable to fetch static ips for project '%s': '%w", projectName, err) } diff --git a/internal/sdkprovider/service/account/account.go b/internal/sdkprovider/service/account/account.go index c2513edfc..9521588a2 100644 --- a/internal/sdkprovider/service/account/account.go +++ b/internal/sdkprovider/service/account/account.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -85,6 +85,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf bgID := d.Get("primary_billing_group_id").(string) r, err := client.Accounts.Create( + ctx, aiven.Account{ Name: name, PrimaryBillingGroupId: bgID, @@ -99,10 +100,10 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf return resourceAccountRead(ctx, d, m) } -func resourceAccountRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - r, err := client.Accounts.Get(d.Id()) + r, err := client.Accounts.Get(ctx, d.Id()) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -138,7 +139,7 @@ func resourceAccountRead(_ context.Context, d *schema.ResourceData, m interface{ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - r, err := client.Accounts.Update(d.Id(), aiven.Account{ + r, err := client.Accounts.Update(ctx, d.Id(), aiven.Account{ Name: d.Get("name").(string), PrimaryBillingGroupId: d.Get("primary_billing_group_id").(string), }) @@ -161,7 +162,7 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf // TODO: Ideally, this should be fixed in the Aiven API. This is a temporary workaround, and should be removed // once the API is fixed. if err := retry.RetryContext(ctx, time.Second*30, func() *retry.RetryError { - err := client.Accounts.Delete(d.Id()) + err := client.Accounts.Delete(ctx, d.Id()) if err != nil { return &retry.RetryError{ Err: err, diff --git a/internal/sdkprovider/service/account/account_authentication.go b/internal/sdkprovider/service/account/account_authentication.go index a9dff4b7c..dc0e81d13 100644 --- a/internal/sdkprovider/service/account/account_authentication.go +++ b/internal/sdkprovider/service/account/account_authentication.go @@ -4,7 +4,7 @@ import ( "context" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -162,6 +162,7 @@ func resourceAccountAuthenticationCreate(ctx context.Context, d *schema.Resource accountID := d.Get("account_id").(string) r, err := client.AccountAuthentications.Create( + ctx, accountID, aiven.AccountAuthenticationMethodCreate{ AuthenticationMethodName: d.Get("name").(string), @@ -188,7 +189,7 @@ func resourceAccountAuthenticationCreate(ctx context.Context, d *schema.Resource return resourceAccountAuthenticationRead(ctx, d, m) } -func resourceAccountAuthenticationRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountAuthenticationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) accountID, authID, err := schemautil.SplitResourceID2(d.Id()) @@ -196,7 +197,7 @@ func resourceAccountAuthenticationRead(_ context.Context, d *schema.ResourceData return diag.FromErr(err) } - r, err := client.AccountAuthentications.Get(accountID, authID) + r, err := client.AccountAuthentications.Get(ctx, accountID, authID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -295,7 +296,7 @@ func resourceAccountAuthenticationUpdate(ctx context.Context, d *schema.Resource SAMLEntity: d.Get("saml_entity_id").(string), } - _, err = client.AccountAuthentications.Update(accountID, authID, r) + _, err = client.AccountAuthentications.Update(ctx, accountID, authID, r) if err != nil { return diag.FromErr(err) } @@ -304,7 +305,7 @@ func resourceAccountAuthenticationUpdate(ctx context.Context, d *schema.Resource return resourceAccountAuthenticationRead(ctx, d, m) } -func resourceAccountAuthenticationDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountAuthenticationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) accountID, teamID, err := schemautil.SplitResourceID2(d.Id()) @@ -312,7 +313,7 @@ func resourceAccountAuthenticationDelete(_ context.Context, d *schema.ResourceDa return diag.FromErr(err) } - err = client.AccountAuthentications.Delete(accountID, teamID) + err = client.AccountAuthentications.Delete(ctx, accountID, teamID) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/account/account_authentication_data_source.go b/internal/sdkprovider/service/account/account_authentication_data_source.go index 0fbb6e37e..b4c06e21b 100644 --- a/internal/sdkprovider/service/account/account_authentication_data_source.go +++ b/internal/sdkprovider/service/account/account_authentication_data_source.go @@ -3,7 +3,7 @@ package account import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -25,7 +25,7 @@ func datasourceAccountAuthenticationRead(ctx context.Context, d *schema.Resource name := d.Get("name").(string) accountID := d.Get("account_id").(string) - r, err := client.AccountAuthentications.List(accountID) + r, err := client.AccountAuthentications.List(ctx, accountID) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/account/account_authentication_test.go b/internal/sdkprovider/service/account/account_authentication_test.go index ae35c8394..4c3cb85ef 100644 --- a/internal/sdkprovider/service/account/account_authentication_test.go +++ b/internal/sdkprovider/service/account/account_authentication_test.go @@ -2,6 +2,7 @@ package account_test import ( "bytes" + "context" "crypto/rand" "crypto/rsa" "crypto/x509" @@ -14,7 +15,7 @@ import ( "testing" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -212,6 +213,8 @@ data "aiven_account_authentication" "auth" { func testAccCheckAivenAccountAuthenticationResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each account authentication is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_account_authentication" { @@ -223,7 +226,7 @@ func testAccCheckAivenAccountAuthenticationResourceDestroy(s *terraform.State) e return err } - r, err := c.Accounts.List() + r, err := c.Accounts.List(ctx) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -234,7 +237,7 @@ func testAccCheckAivenAccountAuthenticationResourceDestroy(s *terraform.State) e for _, ac := range r.Accounts { if ac.Id == accountID { - ra, err := c.AccountAuthentications.List(accountID) + ra, err := c.AccountAuthentications.List(ctx, accountID) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -258,6 +261,8 @@ func testAccCheckAivenAccountAuthenticationResourceDestroy(s *terraform.State) e func testAccCheckAivenAccountAuthenticationWithAutoJoinTeamIDResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each account authentication is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_account_team" && rs.Type != "aiven_account_authentication" { @@ -271,7 +276,7 @@ func testAccCheckAivenAccountAuthenticationWithAutoJoinTeamIDResourceDestroy(s * return err } - r, err := c.Accounts.List() + r, err := c.Accounts.List(ctx) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -280,10 +285,12 @@ func testAccCheckAivenAccountAuthenticationWithAutoJoinTeamIDResourceDestroy(s * return nil } + ctx := context.Background() + for _, ac := range r.Accounts { if ac.Id == accountID { if isTeam { - rl, err := c.AccountTeams.List(accountID) + rl, err := c.AccountTeams.List(ctx, accountID) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -298,7 +305,7 @@ func testAccCheckAivenAccountAuthenticationWithAutoJoinTeamIDResourceDestroy(s * } } } else { - ra, err := c.AccountAuthentications.List(accountID) + ra, err := c.AccountAuthentications.List(ctx, accountID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/account/account_data_source.go b/internal/sdkprovider/service/account/account_data_source.go index cb9ace575..575f487be 100644 --- a/internal/sdkprovider/service/account/account_data_source.go +++ b/internal/sdkprovider/service/account/account_data_source.go @@ -3,7 +3,7 @@ package account import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -23,7 +23,7 @@ func datasourceAccountRead(ctx context.Context, d *schema.ResourceData, m interf name := d.Get("name").(string) - r, err := client.Accounts.List() + r, err := client.Accounts.List(ctx) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/account/account_team.go b/internal/sdkprovider/service/account/account_team.go index b31ab453e..13c93e285 100644 --- a/internal/sdkprovider/service/account/account_team.go +++ b/internal/sdkprovider/service/account/account_team.go @@ -3,7 +3,7 @@ package account import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -60,6 +60,7 @@ func resourceAccountTeamCreate(ctx context.Context, d *schema.ResourceData, m in accountID := d.Get("account_id").(string) r, err := client.AccountTeams.Create( + ctx, accountID, aiven.AccountTeam{ Name: name, @@ -74,7 +75,7 @@ func resourceAccountTeamCreate(ctx context.Context, d *schema.ResourceData, m in return resourceAccountTeamRead(ctx, d, m) } -func resourceAccountTeamRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountTeamRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) accountID, teamID, err := schemautil.SplitResourceID2(d.Id()) @@ -82,7 +83,7 @@ func resourceAccountTeamRead(_ context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } - r, err := client.AccountTeams.Get(accountID, teamID) + r, err := client.AccountTeams.Get(ctx, accountID, teamID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -113,7 +114,7 @@ func resourceAccountTeamUpdate(ctx context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - r, err := client.AccountTeams.Update(accountID, teamID, aiven.AccountTeam{ + r, err := client.AccountTeams.Update(ctx, accountID, teamID, aiven.AccountTeam{ Name: d.Get("name").(string), }) if err != nil { @@ -125,7 +126,7 @@ func resourceAccountTeamUpdate(ctx context.Context, d *schema.ResourceData, m in return resourceAccountTeamRead(ctx, d, m) } -func resourceAccountTeamDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountTeamDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) accountID, teamID, err := schemautil.SplitResourceID2(d.Id()) @@ -133,7 +134,7 @@ func resourceAccountTeamDelete(_ context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - err = client.AccountTeams.Delete(accountID, teamID) + err = client.AccountTeams.Delete(ctx, accountID, teamID) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/account/account_team_data_source.go b/internal/sdkprovider/service/account/account_team_data_source.go index 576405a3c..cbec42a7b 100644 --- a/internal/sdkprovider/service/account/account_team_data_source.go +++ b/internal/sdkprovider/service/account/account_team_data_source.go @@ -3,7 +3,7 @@ package account import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -25,7 +25,7 @@ func datasourceAccountTeamRead(ctx context.Context, d *schema.ResourceData, m in name := d.Get("name").(string) accountID := d.Get("account_id").(string) - r, err := client.AccountTeams.List(accountID) + r, err := client.AccountTeams.List(ctx, accountID) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/account/account_team_member.go b/internal/sdkprovider/service/account/account_team_member.go index fd110ff08..2c26c0faf 100644 --- a/internal/sdkprovider/service/account/account_team_member.go +++ b/internal/sdkprovider/service/account/account_team_member.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -78,9 +78,11 @@ func resourceAccountTeamMemberCreate(ctx context.Context, d *schema.ResourceData userEmail := d.Get("user_email").(string) err := client.AccountTeamMembers.Invite( + ctx, accountID, teamID, - userEmail) + userEmail, + ) if err != nil { return diag.FromErr(err) } @@ -99,7 +101,7 @@ func resourceAccountTeamMemberRead(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - r, err := client.AccountTeamInvites.List(accountID, teamID) + r, err := client.AccountTeamInvites.List(ctx, accountID, teamID) if err != nil { return diag.FromErr(err) } @@ -132,7 +134,7 @@ func resourceAccountTeamMemberRead(ctx context.Context, d *schema.ResourceData, } if !found { - rm, err := client.AccountTeamMembers.List(accountID, teamID) + rm, err := client.AccountTeamMembers.List(ctx, accountID, teamID) if err != nil { return diag.FromErr(err) } @@ -174,7 +176,7 @@ func resourceAccountTeamMemberRead(ctx context.Context, d *schema.ResourceData, return nil } -func resourceAccountTeamMemberDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountTeamMemberDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) accountID, teamID, userEmail, err := schemautil.SplitResourceID3(d.Id()) @@ -183,12 +185,12 @@ func resourceAccountTeamMemberDelete(_ context.Context, d *schema.ResourceData, } // delete account team user invitation - err = client.AccountTeamInvites.Delete(accountID, teamID, userEmail) + err = client.AccountTeamInvites.Delete(ctx, accountID, teamID, userEmail) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } - r, err := client.AccountTeamMembers.List(accountID, teamID) + r, err := client.AccountTeamMembers.List(ctx, accountID, teamID) if err != nil { return diag.FromErr(err) } @@ -201,7 +203,7 @@ func resourceAccountTeamMemberDelete(_ context.Context, d *schema.ResourceData, found := false for _, m := range r.Members { if m.UserEmail == userEmail { - err = client.AccountTeamMembers.Delete(accountID, teamID, m.UserId) + err = client.AccountTeamMembers.Delete(ctx, accountID, teamID, m.UserId) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/account/account_team_member_test.go b/internal/sdkprovider/service/account/account_team_member_test.go index 071d052b5..c7a270a66 100644 --- a/internal/sdkprovider/service/account/account_team_member_test.go +++ b/internal/sdkprovider/service/account/account_team_member_test.go @@ -1,11 +1,12 @@ package account_test import ( + "context" "fmt" "log" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -64,6 +65,8 @@ data "aiven_account_team_member" "member" { func testAccCheckAivenAccountTeamMemberResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each account team project is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_account_team_member" { @@ -75,7 +78,7 @@ func testAccCheckAivenAccountTeamMemberResourceDestroy(s *terraform.State) error return err } - r, err := c.Accounts.List() + r, err := c.Accounts.List(ctx) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -86,7 +89,7 @@ func testAccCheckAivenAccountTeamMemberResourceDestroy(s *terraform.State) error for _, a := range r.Accounts { if a.Id == accountID { - ri, err := c.AccountTeamInvites.List(accountID, teamID) + ri, err := c.AccountTeamInvites.List(ctx, accountID, teamID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/account/account_team_project.go b/internal/sdkprovider/service/account/account_team_project.go index 8917f4f87..7bd72b47c 100644 --- a/internal/sdkprovider/service/account/account_team_project.go +++ b/internal/sdkprovider/service/account/account_team_project.go @@ -3,7 +3,7 @@ package account import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -67,6 +67,7 @@ func resourceAccountTeamProjectCreate(ctx context.Context, d *schema.ResourceDat teamType := d.Get("team_type").(string) err := client.AccountTeamProjects.Create( + ctx, accountID, teamID, aiven.AccountTeamProject{ @@ -83,7 +84,7 @@ func resourceAccountTeamProjectCreate(ctx context.Context, d *schema.ResourceDat return resourceAccountTeamProjectRead(ctx, d, m) } -func resourceAccountTeamProjectRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountTeamProjectRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) accountID, teamID, projectName, err := schemautil.SplitResourceID3(d.Id()) @@ -91,7 +92,7 @@ func resourceAccountTeamProjectRead(_ context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - r, err := client.AccountTeamProjects.List(accountID, teamID) + r, err := client.AccountTeamProjects.List(ctx, accountID, teamID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -134,7 +135,7 @@ func resourceAccountTeamProjectUpdate(ctx context.Context, d *schema.ResourceDat newProjectName := d.Get("project_name").(string) teamType := d.Get("team_type").(string) - err = client.AccountTeamProjects.Update(accountID, teamID, aiven.AccountTeamProject{ + err = client.AccountTeamProjects.Update(ctx, accountID, teamID, aiven.AccountTeamProject{ TeamType: teamType, ProjectName: newProjectName, }) @@ -147,7 +148,7 @@ func resourceAccountTeamProjectUpdate(ctx context.Context, d *schema.ResourceDat return resourceAccountTeamProjectRead(ctx, d, m) } -func resourceAccountTeamProjectDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAccountTeamProjectDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) accountID, teamID, projectName, err := schemautil.SplitResourceID3(d.Id()) @@ -155,7 +156,7 @@ func resourceAccountTeamProjectDelete(_ context.Context, d *schema.ResourceData, return diag.FromErr(err) } - err = client.AccountTeamProjects.Delete(accountID, teamID, projectName) + err = client.AccountTeamProjects.Delete(ctx, accountID, teamID, projectName) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/account/account_team_project_test.go b/internal/sdkprovider/service/account/account_team_project_test.go index 32b8b2e96..49c3f8fa3 100644 --- a/internal/sdkprovider/service/account/account_team_project_test.go +++ b/internal/sdkprovider/service/account/account_team_project_test.go @@ -1,11 +1,12 @@ package account_test import ( + "context" "fmt" "log" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -70,6 +71,8 @@ data "aiven_account_team_project" "project" { func testAccCheckAivenAccountTeamProjectResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each account team project is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_account_team_project" { @@ -81,7 +84,7 @@ func testAccCheckAivenAccountTeamProjectResourceDestroy(s *terraform.State) erro return err } - r, err := c.Accounts.List() + r, err := c.Accounts.List(ctx) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -92,7 +95,7 @@ func testAccCheckAivenAccountTeamProjectResourceDestroy(s *terraform.State) erro for _, a := range r.Accounts { if a.Id == accountID { - rp, err := c.AccountTeamProjects.List(accountID, teamID) + rp, err := c.AccountTeamProjects.List(ctx, accountID, teamID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/account/account_team_test.go b/internal/sdkprovider/service/account/account_team_test.go index e08ccd02d..24c9031e0 100644 --- a/internal/sdkprovider/service/account/account_team_test.go +++ b/internal/sdkprovider/service/account/account_team_test.go @@ -1,11 +1,12 @@ package account_test import ( + "context" "fmt" "log" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -56,6 +57,8 @@ data "aiven_account_team" "team" { func testAccCheckAivenAccountTeamResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each account team is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_account_team" { @@ -67,7 +70,7 @@ func testAccCheckAivenAccountTeamResourceDestroy(s *terraform.State) error { return err } - r, err := c.Accounts.List() + r, err := c.Accounts.List(ctx) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -78,7 +81,7 @@ func testAccCheckAivenAccountTeamResourceDestroy(s *terraform.State) error { for _, ac := range r.Accounts { if ac.Id == accountID { - rl, err := c.AccountTeams.List(accountID) + rl, err := c.AccountTeams.List(ctx, accountID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/account/account_test.go b/internal/sdkprovider/service/account/account_test.go index de83f1848..c183e0abe 100644 --- a/internal/sdkprovider/service/account/account_test.go +++ b/internal/sdkprovider/service/account/account_test.go @@ -1,11 +1,12 @@ package account_test import ( + "context" "fmt" "log" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -76,13 +77,15 @@ data "aiven_project" "pr" { func testAccCheckAivenAccountResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each account is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_account" { continue } - r, err := c.Accounts.List() + r, err := c.Accounts.List(ctx) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/account/sweep.go b/internal/sdkprovider/service/account/sweep.go index 1cb92e6e6..f47c2bd1c 100644 --- a/internal/sdkprovider/service/account/sweep.go +++ b/internal/sdkprovider/service/account/sweep.go @@ -3,48 +3,57 @@ package account import ( + "context" "fmt" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/aiven/terraform-provider-aiven/internal/sweep" ) func init() { + ctx := context.Background() + + client, err := sweep.SharedClient() + if err != nil { + panic(fmt.Sprintf("error getting client: %s", err)) + } + resource.AddTestSweepers("aiven_account_team_member", &resource.Sweeper{ Name: "aiven_account_team_member", - F: sweepAccountTeamMembers, + F: sweepAccountTeamMembers(ctx, client), Dependencies: []string{"aiven_account_authentication"}, }) resource.AddTestSweepers("aiven_account_team_project", &resource.Sweeper{ Name: "aiven_account_team_project", - F: sweepAccountTeamProjects, + F: sweepAccountTeamProjects(ctx, client), Dependencies: []string{"aiven_account_authentication"}, }) resource.AddTestSweepers("aiven_account_team", &resource.Sweeper{ Name: "aiven_account_team", - F: sweepAccountTeams, + F: sweepAccountTeams(ctx, client), Dependencies: []string{"aiven_account_team_member", "aiven_account_authentication"}, }) resource.AddTestSweepers("aiven_account", &resource.Sweeper{ Name: "aiven_account", - F: sweepAccounts, + F: sweepAccounts(ctx, client), Dependencies: []string{"aiven_project", "aiven_account_team", "aiven_account_team_project", "aiven_account_authentication"}, }) resource.AddTestSweepers("aiven_account_authentication", &resource.Sweeper{ Name: "aiven_account_authentication", - F: sweepAccountAuthentications, + F: sweepAccountAuthentications(ctx, client), }) } -func listTestAccounts(conn *aiven.Client) ([]aiven.Account, error) { - testAccounts := []aiven.Account{} - r, err := conn.Accounts.List() +func listTestAccounts(ctx context.Context, client *aiven.Client) ([]aiven.Account, error) { + var testAccounts []aiven.Account + + r, err := client.Accounts.List(ctx) if err != nil { return nil, err } @@ -58,187 +67,163 @@ func listTestAccounts(conn *aiven.Client) ([]aiven.Account, error) { return testAccounts, nil } -func sweepAccountAuthentications(region string) error { - client, err := sweep.SharedClient(region) - if err != nil { - return fmt.Errorf("error getting client: %s", err) - } - - conn := client.(*aiven.Client) - accounts, err := listTestAccounts(conn) - - if err != nil { - return fmt.Errorf("error retrieving a list of accounts : %w", err) - } +func sweepAccountAuthentications(ctx context.Context, client *aiven.Client) func(region string) error { + return func(region string) error { + accounts, err := listTestAccounts(ctx, client) - for _, a := range accounts { - rr, err := conn.AccountAuthentications.List(a.Id) if err != nil { - return fmt.Errorf("cannot get account authentications list: %w", err) + return fmt.Errorf("error retrieving a list of accounts : %w", err) } - for _, m := range rr.AuthenticationMethods { - err := conn.AccountAuthentications.Delete(a.Id, m.AuthenticationMethodID) + for _, a := range accounts { + rr, err := client.AccountAuthentications.List(ctx, a.Id) if err != nil { - if strings.Contains(err.Error(), "Internal authentication methods cannot be deleted") { - continue + return fmt.Errorf("cannot get account authentications list: %w", err) + } + + for _, m := range rr.AuthenticationMethods { + err := client.AccountAuthentications.Delete(ctx, a.Id, m.AuthenticationMethodID) + if err != nil { + if strings.Contains(err.Error(), "Internal authentication methods cannot be deleted") { + continue + } + return fmt.Errorf("cannot delete account authentication: %w", err) } - return fmt.Errorf("cannot delete account authentication: %w", err) } } - } - return nil -} - -func sweepAccounts(region string) error { - client, err := sweep.SharedClient(region) - if err != nil { - return fmt.Errorf("error getting client: %w", err) + return nil } +} - conn := client.(*aiven.Client) +func sweepAccounts(ctx context.Context, client *aiven.Client) func(region string) error { + return func(region string) error { + accounts, err := listTestAccounts(ctx, client) + if err != nil { + return fmt.Errorf("error retrieving a list of accounts : %w", err) + } - accounts, err := listTestAccounts(conn) - if err != nil { - return fmt.Errorf("error retrieving a list of accounts : %w", err) - } + for _, a := range accounts { + if err := client.Accounts.Delete(ctx, a.Id); err != nil { + if err.(aiven.Error).Status == 404 { + continue + } - for _, a := range accounts { - if err := conn.Accounts.Delete(a.Id); err != nil { - if err.(aiven.Error).Status == 404 { - continue + return fmt.Errorf("error destroying account %s during sweep: %w", a.Name, err) } - - return fmt.Errorf("error destroying account %s during sweep: %w", a.Name, err) } - } - - return nil -} -func sweepAccountTeams(region string) error { - client, err := sweep.SharedClient(region) - if err != nil { - return fmt.Errorf("error getting client: %w", err) - } - - conn := client.(*aiven.Client) - - accounts, err := listTestAccounts(conn) - if err != nil { - return fmt.Errorf("error retrieving a list of accounts : %w", err) + return nil } +} - for _, a := range accounts { - tr, err := conn.AccountTeams.List(a.Id) +func sweepAccountTeams(ctx context.Context, client *aiven.Client) func(region string) error { + return func(region string) error { + accounts, err := listTestAccounts(ctx, client) if err != nil { - return fmt.Errorf("error retrieving a list of account teams : %w", err) + return fmt.Errorf("error retrieving a list of accounts : %w", err) } - for _, t := range tr.Teams { - if strings.Contains(t.Name, "test-acc-team-") { - err = conn.AccountTeams.Delete(t.AccountId, t.Id) - if err != nil { - return fmt.Errorf("cannot delete account team: %w", err) - } + for _, a := range accounts { + tr, err := client.AccountTeams.List(ctx, a.Id) + if err != nil { + return fmt.Errorf("error retrieving a list of account teams : %w", err) } - } - } - - return nil -} -func sweepAccountTeamMembers(region string) error { - client, err := sweep.SharedClient(region) - if err != nil { - return fmt.Errorf("error getting client: %s", err) - } + for _, t := range tr.Teams { + if strings.Contains(t.Name, "test-acc-team-") { + err = client.AccountTeams.Delete(ctx, t.AccountId, t.Id) + if err != nil { + return fmt.Errorf("cannot delete account team: %w", err) + } + } - conn := client.(*aiven.Client) + } + } - accounts, err := listTestAccounts(conn) - if err != nil { - return fmt.Errorf("error retrieving a list of accounts : %s", err) + return nil } - - for _, a := range accounts { - tr, err := conn.AccountTeams.List(a.Id) +} +func sweepAccountTeamMembers(ctx context.Context, client *aiven.Client) func(region string) error { + return func(region string) error { + accounts, err := listTestAccounts(ctx, client) if err != nil { - return fmt.Errorf("error retrieving a list of account teams : %s", err) + return fmt.Errorf("error retrieving a list of accounts : %s", err) } - for _, t := range tr.Teams { - if strings.Contains(t.Name, "test-acc-team-") { - // delete all account team invitations - mi, err := conn.AccountTeamInvites.List(t.AccountId, t.Id) - if err != nil { - return fmt.Errorf("error retrieving a list of account team invitations : %s", err) - } + for _, a := range accounts { + tr, err := client.AccountTeams.List(ctx, a.Id) + if err != nil { + return fmt.Errorf("error retrieving a list of account teams : %s", err) + } - for _, i := range mi.Invites { - err := conn.AccountTeamInvites.Delete(i.AccountId, i.TeamId, i.UserEmail) + for _, t := range tr.Teams { + if strings.Contains(t.Name, "test-acc-team-") { + // delete all account team invitations + mi, err := client.AccountTeamInvites.List(ctx, t.AccountId, t.Id) if err != nil { - return fmt.Errorf("cannot delete account team invitation : %s", err) + return fmt.Errorf("error retrieving a list of account team invitations : %s", err) } - } - // delete all account team members - mr, err := conn.AccountTeamMembers.List(t.AccountId, t.Id) - if err != nil { - return fmt.Errorf("error retrieving a list of account team members : %s", err) - } + for _, i := range mi.Invites { + err := client.AccountTeamInvites.Delete(ctx, i.AccountId, i.TeamId, i.UserEmail) + if err != nil { + return fmt.Errorf("cannot delete account team invitation : %s", err) + } + } - for _, m := range mr.Members { - err := conn.AccountTeamMembers.Delete(t.AccountId, t.Id, m.UserId) + // delete all account team members + mr, err := client.AccountTeamMembers.List(ctx, t.AccountId, t.Id) if err != nil { - return fmt.Errorf("cannot delete account team member : %s", err) + return fmt.Errorf("error retrieving a list of account team members : %s", err) + } + + for _, m := range mr.Members { + err := client.AccountTeamMembers.Delete(ctx, t.AccountId, t.Id, m.UserId) + if err != nil { + return fmt.Errorf("cannot delete account team member : %s", err) + } } } - } + } } - } - return nil -} - -func sweepAccountTeamProjects(region string) error { - client, err := sweep.SharedClient(region) - if err != nil { - return fmt.Errorf("error getting client: %s", err) - } - - conn := client.(*aiven.Client) - - accounts, err := listTestAccounts(conn) - if err != nil { - return fmt.Errorf("error retrieving a list of accounts : %s", err) + return nil } +} - for _, a := range accounts { - tr, err := conn.AccountTeams.List(a.Id) +func sweepAccountTeamProjects(ctx context.Context, client *aiven.Client) func(region string) error { + return func(region string) error { + accounts, err := listTestAccounts(ctx, client) if err != nil { - return fmt.Errorf("error retrieving a list of account teams : %s", err) + return fmt.Errorf("error retrieving a list of accounts : %s", err) } - for _, t := range tr.Teams { - if strings.Contains(t.Name, "test-acc-team-") { - pr, err := conn.AccountTeamProjects.List(t.AccountId, t.Id) - if err != nil { - return fmt.Errorf("error retrieving a list of account team projects : %s", err) - } + for _, a := range accounts { + tr, err := client.AccountTeams.List(ctx, a.Id) + if err != nil { + return fmt.Errorf("error retrieving a list of account teams : %s", err) + } - for _, p := range pr.Projects { - err := conn.AccountTeamProjects.Delete(t.AccountId, t.Id, p.ProjectName) + for _, t := range tr.Teams { + if strings.Contains(t.Name, "test-acc-team-") { + pr, err := client.AccountTeamProjects.List(ctx, t.AccountId, t.Id) if err != nil { - return fmt.Errorf("cannot delete account team project : %s", err) + return fmt.Errorf("error retrieving a list of account team projects : %s", err) + } + + for _, p := range pr.Projects { + err := client.AccountTeamProjects.Delete(ctx, t.AccountId, t.Id, p.ProjectName) + if err != nil { + return fmt.Errorf("cannot delete account team project : %s", err) + } } } - } + } } - } - return nil + return nil + } } diff --git a/internal/sdkprovider/service/cassandra/cassandra_user_test.go b/internal/sdkprovider/service/cassandra/cassandra_user_test.go index 911597032..9bbaeefb3 100644 --- a/internal/sdkprovider/service/cassandra/cassandra_user_test.go +++ b/internal/sdkprovider/service/cassandra/cassandra_user_test.go @@ -1,11 +1,12 @@ package cassandra_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -40,6 +41,8 @@ func TestAccAivenCassandraUser_basic(t *testing.T) { func testAccCheckAivenCassandraUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_cassandra_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_cassandra_user" { @@ -51,7 +54,7 @@ func testAccCheckAivenCassandraUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_database.go b/internal/sdkprovider/service/clickhouse/clickhouse_database.go index 2870c386f..9819def4e 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_database.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_database.go @@ -3,7 +3,7 @@ package clickhouse import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -51,7 +51,7 @@ func resourceClickhouseDatabaseCreate(ctx context.Context, d *schema.ResourceDat serviceName := d.Get("service_name").(string) databaseName := d.Get("name").(string) - err := client.ClickhouseDatabase.Create(projectName, serviceName, databaseName) + err := client.ClickhouseDatabase.Create(ctx, projectName, serviceName, databaseName) if err != nil { return diag.FromErr(err) } @@ -61,7 +61,7 @@ func resourceClickhouseDatabaseCreate(ctx context.Context, d *schema.ResourceDat return resourceClickhouseDatabaseRead(ctx, d, m) } -func resourceClickhouseDatabaseRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseDatabaseRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, databaseName, err := schemautil.SplitResourceID3(d.Id()) @@ -69,7 +69,7 @@ func resourceClickhouseDatabaseRead(_ context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - database, err := client.ClickhouseDatabase.Get(projectName, serviceName, databaseName) + database, err := client.ClickhouseDatabase.Get(ctx, projectName, serviceName, databaseName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -81,7 +81,7 @@ func resourceClickhouseDatabaseRead(_ context.Context, d *schema.ResourceData, m return nil } -func resourceClickhouseDatabaseDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseDatabaseDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, databaseName, err := schemautil.SplitResourceID3(d.Id()) @@ -93,7 +93,7 @@ func resourceClickhouseDatabaseDelete(_ context.Context, d *schema.ResourceData, return diag.Errorf("cannot delete a database termination_protection is enabled") } - err = client.ClickhouseDatabase.Delete(projectName, serviceName, databaseName) + err = client.ClickhouseDatabase.Delete(ctx, projectName, serviceName, databaseName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_database_data_source.go b/internal/sdkprovider/service/clickhouse/clickhouse_database_data_source.go index 5f063b9db..dd47b3fe6 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_database_data_source.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_database_data_source.go @@ -3,7 +3,7 @@ package clickhouse import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceClickhouseDatabaseRead(ctx context.Context, d *schema.ResourceDat serviceName := d.Get("service_name").(string) databaseName := d.Get("name").(string) - r, err := client.ClickhouseDatabase.List(projectName, serviceName) + r, err := client.ClickhouseDatabase.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_grant.go b/internal/sdkprovider/service/clickhouse/clickhouse_grant.go index e9874c441..3453e57e2 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_grant.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_grant.go @@ -4,7 +4,7 @@ import ( "context" "regexp" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -117,12 +117,12 @@ func resourceClickhouseGrantCreate(ctx context.Context, d *schema.ResourceData, projectName := d.Get("project").(string) for _, grant := range readPrivilegeGrantsFromSchema(d) { - if err := CreatePrivilegeGrant(client, projectName, serviceName, grant); err != nil { + if err := CreatePrivilegeGrant(ctx, client, projectName, serviceName, grant); err != nil { return diag.FromErr(err) } } for _, grant := range readRoleGrantsFromSchema(d) { - if err := CreateRoleGrant(client, projectName, serviceName, grant); err != nil { + if err := CreateRoleGrant(ctx, client, projectName, serviceName, grant); err != nil { return diag.FromErr(err) } } @@ -157,7 +157,7 @@ func setUserOrRole(d *schema.ResourceData, granteeType, userOrRole string) error return nil } -func resourceClickhouseGrantRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseGrantRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, granteeType, userOrRole, err := schemautil.SplitResourceID4(d.Id()) @@ -177,7 +177,7 @@ func resourceClickhouseGrantRead(_ context.Context, d *schema.ResourceData, m in grantee := Grantee{User: d.Get("user").(string), Role: d.Get("role").(string)} - privilegeGrants, err := ReadPrivilegeGrants(client, projectName, serviceName, grantee) + privilegeGrants, err := ReadPrivilegeGrants(ctx, client, projectName, serviceName, grantee) if err != nil { return diag.FromErr(err) } @@ -185,7 +185,7 @@ func resourceClickhouseGrantRead(_ context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - roleGrants, err := ReadRoleGrants(client, projectName, serviceName, grantee) + roleGrants, err := ReadRoleGrants(ctx, client, projectName, serviceName, grantee) if err != nil { return diag.FromErr(err) } @@ -195,20 +195,20 @@ func resourceClickhouseGrantRead(_ context.Context, d *schema.ResourceData, m in return nil } -func resourceClickhouseGrantDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseGrantDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName := d.Get("project").(string) serviceName := d.Get("service_name").(string) for _, grant := range readPrivilegeGrantsFromSchema(d) { - if err := RevokePrivilegeGrant(client, projectName, serviceName, grant); err != nil { + if err := RevokePrivilegeGrant(ctx, client, projectName, serviceName, grant); err != nil { return diag.FromErr(err) } } for _, grant := range readRoleGrantsFromSchema(d) { - if err := RevokeRoleGrant(client, projectName, serviceName, grant); err != nil { + if err := RevokeRoleGrant(ctx, client, projectName, serviceName, grant); err != nil { return diag.FromErr(err) } } diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_grant_test.go b/internal/sdkprovider/service/clickhouse/clickhouse_grant_test.go index 5420871b6..7f9edf51b 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_grant_test.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_grant_test.go @@ -1,11 +1,12 @@ package clickhouse_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -95,6 +96,8 @@ resource "aiven_clickhouse_grant" "foo-user-grant" { func testAccCheckAivenClickhouseGrantResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_clickhouse_role is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_clickhouse_grant" { @@ -114,7 +117,13 @@ func testAccCheckAivenClickhouseGrantResourceDestroy(s *terraform.State) error { grantee.User = granteeName } - if privilegeGrants, err := clickhouse2.ReadPrivilegeGrants(c, projectName, serviceName, grantee); err != nil { + if privilegeGrants, err := clickhouse2.ReadPrivilegeGrants( + ctx, + c, + projectName, + serviceName, + grantee, + ); err != nil { if aiven.IsNotFound(err) { continue } @@ -123,7 +132,7 @@ func testAccCheckAivenClickhouseGrantResourceDestroy(s *terraform.State) error { return fmt.Errorf("'%s' still has privilege grants exists", granteeName) } - if roleGrants, err := clickhouse2.ReadRoleGrants(c, projectName, serviceName, grantee); err != nil { + if roleGrants, err := clickhouse2.ReadRoleGrants(ctx, c, projectName, serviceName, grantee); err != nil { if aiven.IsNotFound(err) { continue } diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_role.go b/internal/sdkprovider/service/clickhouse/clickhouse_role.go index 2c5b5a481..63916aa00 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_role.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_role.go @@ -3,7 +3,7 @@ package clickhouse import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -45,7 +45,7 @@ func resourceClickhouseRoleCreate(ctx context.Context, d *schema.ResourceData, m serviceName := d.Get("service_name").(string) roleName := d.Get("role").(string) - if err := CreateRole(client, projectName, serviceName, roleName); err != nil { + if err := CreateRole(ctx, client, projectName, serviceName, roleName); err != nil { return diag.FromErr(err) } @@ -54,7 +54,7 @@ func resourceClickhouseRoleCreate(ctx context.Context, d *schema.ResourceData, m return resourceClickhouseRoleRead(ctx, d, m) } -func resourceClickhouseRoleRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseRoleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, roleName, err := schemautil.SplitResourceID3(d.Id()) @@ -62,7 +62,7 @@ func resourceClickhouseRoleRead(_ context.Context, d *schema.ResourceData, m int return diag.FromErr(err) } - if exists, err := RoleExists(client, projectName, serviceName, roleName); err != nil { + if exists, err := RoleExists(ctx, client, projectName, serviceName, roleName); err != nil { return diag.FromErr(err) } else if !exists { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) @@ -80,7 +80,7 @@ func resourceClickhouseRoleRead(_ context.Context, d *schema.ResourceData, m int return nil } -func resourceClickhouseRoleDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseRoleDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, roleName, err := schemautil.SplitResourceID3(d.Id()) @@ -88,7 +88,7 @@ func resourceClickhouseRoleDelete(_ context.Context, d *schema.ResourceData, m i return diag.FromErr(err) } - if err := DropRole(client, projectName, serviceName, roleName); err != nil { + if err := DropRole(ctx, client, projectName, serviceName, roleName); err != nil { return diag.FromErr(err) } return nil diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_role_test.go b/internal/sdkprovider/service/clickhouse/clickhouse_role_test.go index af187469e..a778ad1ed 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_role_test.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_role_test.go @@ -1,11 +1,12 @@ package clickhouse_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -56,6 +57,8 @@ resource "aiven_clickhouse_role" "foo" { func testAccCheckAivenClickhouseRoleResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_clickhouse_role is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_clickhouse_role" { @@ -67,7 +70,7 @@ func testAccCheckAivenClickhouseRoleResourceDestroy(s *terraform.State) error { return err } - if exists, err := clickhouse.RoleExists(c, projectName, serviceName, roleName); err != nil { + if exists, err := clickhouse.RoleExists(ctx, c, projectName, serviceName, roleName); err != nil { if aiven.IsNotFound(err) { continue } diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_user.go b/internal/sdkprovider/service/clickhouse/clickhouse_user.go index 2a3663a71..4b15f892f 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_user.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_user.go @@ -3,7 +3,7 @@ package clickhouse import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -62,6 +62,7 @@ func resourceClickhouseUserCreate(ctx context.Context, d *schema.ResourceData, m serviceName := d.Get("service_name").(string) username := d.Get("username").(string) u, err := client.ClickhouseUser.Create( + ctx, projectName, serviceName, username, @@ -79,7 +80,7 @@ func resourceClickhouseUserCreate(ctx context.Context, d *schema.ResourceData, m return resourceClickhouseUserRead(ctx, d, m) } -func resourceClickhouseUserRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, uuid, err := schemautil.SplitResourceID3(d.Id()) @@ -87,7 +88,7 @@ func resourceClickhouseUserRead(_ context.Context, d *schema.ResourceData, m int return diag.FromErr(err) } - user, err := client.ClickhouseUser.Get(projectName, serviceName, uuid) + user, err := client.ClickhouseUser.Get(ctx, projectName, serviceName, uuid) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -111,7 +112,7 @@ func resourceClickhouseUserRead(_ context.Context, d *schema.ResourceData, m int return nil } -func resourceClickhouseUserDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceClickhouseUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, uuid, err := schemautil.SplitResourceID3(d.Id()) @@ -119,7 +120,7 @@ func resourceClickhouseUserDelete(_ context.Context, d *schema.ResourceData, m i return diag.FromErr(err) } - err = client.ClickhouseUser.Delete(projectName, serviceName, uuid) + err = client.ClickhouseUser.Delete(ctx, projectName, serviceName, uuid) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_user_data_source.go b/internal/sdkprovider/service/clickhouse/clickhouse_user_data_source.go index 122025993..548b16aea 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_user_data_source.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_user_data_source.go @@ -3,7 +3,7 @@ package clickhouse import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceClickhouseUserRead(ctx context.Context, d *schema.ResourceData, m serviceName := d.Get("service_name").(string) userName := d.Get("username").(string) - list, err := client.ClickhouseUser.List(projectName, serviceName) + list, err := client.ClickhouseUser.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/clickhouse/clickhouse_user_test.go b/internal/sdkprovider/service/clickhouse/clickhouse_user_test.go index 1fc97a044..7ac61cf23 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse_user_test.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse_user_test.go @@ -1,12 +1,13 @@ package clickhouse_test import ( + "context" "fmt" "log" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -43,6 +44,8 @@ func TestAccAivenClickhouseUser_basic(t *testing.T) { func testAccCheckAivenClickhouseUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_clickhouse_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_clickhouse_user" { @@ -54,7 +57,7 @@ func testAccCheckAivenClickhouseUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ClickhouseUser.Get(projectName, serviceName, uuid) + p, err := c.ClickhouseUser.Get(ctx, projectName, serviceName, uuid) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/clickhouse/grant.go b/internal/sdkprovider/service/clickhouse/grant.go index ce11bb6a3..bd0590d69 100644 --- a/internal/sdkprovider/service/clickhouse/grant.go +++ b/internal/sdkprovider/service/clickhouse/grant.go @@ -1,12 +1,13 @@ package clickhouse import ( + "context" "encoding/json" "fmt" "log" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" ) type Grantee struct { @@ -39,27 +40,45 @@ func userOrRole(g Grantee) string { return g.Role } -func CreateRoleGrant(client *aiven.Client, projectName, serviceName string, grant RoleGrant) error { +func CreateRoleGrant( + ctx context.Context, + client *aiven.Client, + projectName string, + serviceName string, + grant RoleGrant, +) error { query := createRoleGrantStatement(grant) log.Println("[DEBUG] Clickhouse: create role grant query: ", query) - _, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + _, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) return err } -func RevokeRoleGrant(client *aiven.Client, projectName, serviceName string, grant RoleGrant) error { +func RevokeRoleGrant( + ctx context.Context, + client *aiven.Client, + projectName string, + serviceName string, + grant RoleGrant, +) error { query := revokeRoleGrantStatement(grant) log.Println("[DEBUG] privilege revocation query: ", query) - _, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + _, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) return err } -func ReadRoleGrants(client *aiven.Client, projectName, serviceName string, grantee Grantee) ([]RoleGrant, error) { +func ReadRoleGrants( + ctx context.Context, + client *aiven.Client, + projectName string, + serviceName string, + grantee Grantee, +) ([]RoleGrant, error) { query := readRoleGrantsStatement() log.Println("[DEBUG] Clickhouse: read role grant query: ", query) - r, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + r, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) if err != nil { return nil, err } @@ -79,19 +98,31 @@ func ReadRoleGrants(client *aiven.Client, projectName, serviceName string, grant return res, err } -func CreatePrivilegeGrant(client *aiven.Client, projectName, serviceName string, grant PrivilegeGrant) error { +func CreatePrivilegeGrant( + ctx context.Context, + client *aiven.Client, + projectName string, + serviceName string, + grant PrivilegeGrant, +) error { query := createPrivilegeGrantStatement(grant) log.Println("[DEBUG] Clickhouse: create privilege grant query: ", query) - _, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + _, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) return err } -func ReadPrivilegeGrants(client *aiven.Client, projectName, serviceName string, grantee Grantee) ([]PrivilegeGrant, error) { +func ReadPrivilegeGrants( + ctx context.Context, + client *aiven.Client, + projectName string, + serviceName string, + grantee Grantee, +) ([]PrivilegeGrant, error) { query := readPrivilegeGrantsStatement() log.Println("[DEBUG] Clickhouse: read privilege grant query: ", query) - r, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + r, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) if err != nil { return nil, err } @@ -110,11 +141,17 @@ func ReadPrivilegeGrants(client *aiven.Client, projectName, serviceName string, return res, err } -func RevokePrivilegeGrant(client *aiven.Client, projectName, serviceName string, grant PrivilegeGrant) error { +func RevokePrivilegeGrant( + ctx context.Context, + client *aiven.Client, + projectName string, + serviceName string, + grant PrivilegeGrant, +) error { query := revokePrivilegeGrantStatement(grant) log.Println("[DEBUG] privilege revocation query: ", query) - _, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + _, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) return err } diff --git a/internal/sdkprovider/service/clickhouse/role.go b/internal/sdkprovider/service/clickhouse/role.go index 31af38144..85980c4ad 100644 --- a/internal/sdkprovider/service/clickhouse/role.go +++ b/internal/sdkprovider/service/clickhouse/role.go @@ -1,11 +1,12 @@ package clickhouse import ( + "context" "fmt" "log" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" ) func isUnknownRole(err error) bool { @@ -16,22 +17,22 @@ func isUnknownRole(err error) bool { return strings.Contains(aivenError.Message, "Code: 511") } -func CreateRole(client *aiven.Client, projectName, serviceName, roleName string) error { +func CreateRole(ctx context.Context, client *aiven.Client, projectName, serviceName, roleName string) error { query := createRoleStatement(roleName) log.Println("[DEBUG] Clickhouse: create role query: ", query) // TODO inspect result? - _, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + _, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) return err } -func RoleExists(client *aiven.Client, projectName, serviceName, roleName string) (bool, error) { +func RoleExists(ctx context.Context, client *aiven.Client, projectName, serviceName, roleName string) (bool, error) { query := showCreateRoleStatement(roleName) log.Println("[DEBUG] Clickhouse: role exists query: ", query) - r, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + r, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) if err != nil { if isUnknownRole(err) { return false, nil @@ -41,12 +42,12 @@ func RoleExists(client *aiven.Client, projectName, serviceName, roleName string) return len(r.Data) > 0, nil } -func DropRole(client *aiven.Client, projectName, serviceName, roleName string) error { +func DropRole(ctx context.Context, client *aiven.Client, projectName, serviceName, roleName string) error { query := dropRoleStatement(roleName) log.Println("[DEBUG] Clickhouse: drop role query: ", query) - _, err := client.ClickHouseQuery.Query(projectName, serviceName, defaultDatabase, query) + _, err := client.ClickHouseQuery.Query(ctx, projectName, serviceName, defaultDatabase, query) if err != nil && isUnknownRole(err) { return nil } diff --git a/internal/sdkprovider/service/connectionpool/connection_pool.go b/internal/sdkprovider/service/connectionpool/connection_pool.go index d8f225e94..ab839986e 100644 --- a/internal/sdkprovider/service/connectionpool/connection_pool.go +++ b/internal/sdkprovider/service/connectionpool/connection_pool.go @@ -3,7 +3,7 @@ package connectionpool import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -77,6 +77,7 @@ func resourceConnectionPoolCreate(ctx context.Context, d *schema.ResourceData, m serviceName := d.Get("service_name").(string) poolName := d.Get("pool_name").(string) _, err := client.ConnectionPools.Create( + ctx, project, serviceName, aiven.CreateConnectionPoolRequest{ @@ -96,7 +97,7 @@ func resourceConnectionPoolCreate(ctx context.Context, d *schema.ResourceData, m return resourceConnectionPoolRead(ctx, d, m) } -func resourceConnectionPoolRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceConnectionPoolRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, poolName, err := schemautil.SplitResourceID3(d.Id()) @@ -104,7 +105,7 @@ func resourceConnectionPoolRead(_ context.Context, d *schema.ResourceData, m int return diag.FromErr(err) } - pool, err := client.ConnectionPools.Get(project, serviceName, poolName) + pool, err := client.ConnectionPools.Get(ctx, project, serviceName, poolName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -126,6 +127,7 @@ func resourceConnectionPoolUpdate(ctx context.Context, d *schema.ResourceData, m } _, err = client.ConnectionPools.Update( + ctx, project, serviceName, poolName, @@ -143,7 +145,7 @@ func resourceConnectionPoolUpdate(ctx context.Context, d *schema.ResourceData, m return resourceConnectionPoolRead(ctx, d, m) } -func resourceConnectionPoolDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceConnectionPoolDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, poolName, err := schemautil.SplitResourceID3(d.Id()) @@ -151,7 +153,7 @@ func resourceConnectionPoolDelete(_ context.Context, d *schema.ResourceData, m i return diag.FromErr(err) } - err = client.ConnectionPools.Delete(projectName, serviceName, poolName) + err = client.ConnectionPools.Delete(ctx, projectName, serviceName, poolName) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/connectionpool/connection_pool_data_source.go b/internal/sdkprovider/service/connectionpool/connection_pool_data_source.go index c2fc12a52..2a04c0070 100644 --- a/internal/sdkprovider/service/connectionpool/connection_pool_data_source.go +++ b/internal/sdkprovider/service/connectionpool/connection_pool_data_source.go @@ -3,7 +3,7 @@ package connectionpool import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceConnectionPoolRead(ctx context.Context, d *schema.ResourceData, m serviceName := d.Get("service_name").(string) poolName := d.Get("pool_name").(string) - pools, err := client.ConnectionPools.List(projectName, serviceName) + pools, err := client.ConnectionPools.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/connectionpool/connection_pool_test.go b/internal/sdkprovider/service/connectionpool/connection_pool_test.go index 39f55bf96..08de235ac 100644 --- a/internal/sdkprovider/service/connectionpool/connection_pool_test.go +++ b/internal/sdkprovider/service/connectionpool/connection_pool_test.go @@ -1,11 +1,12 @@ package connectionpool_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -181,6 +182,8 @@ func testAccCheckAivenConnectionPoolAttributes(n string) resource.TestCheckFunc func testAccCheckAivenConnectionPoolResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each connection pool is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_connection_pool" { @@ -192,7 +195,7 @@ func testAccCheckAivenConnectionPoolResourceDestroy(s *terraform.State) error { return err } - pool, err := c.ConnectionPools.Get(projectName, serviceName, databaseName) + pool, err := c.ConnectionPools.Get(ctx, projectName, serviceName, databaseName) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/flink/flink_application.go b/internal/sdkprovider/service/flink/flink_application.go index aff02e496..9a7d99c94 100644 --- a/internal/sdkprovider/service/flink/flink_application.go +++ b/internal/sdkprovider/service/flink/flink_application.go @@ -3,7 +3,7 @@ package flink import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -71,7 +71,7 @@ func ResourceFlinkApplication() *schema.Resource { } // resourceFlinkApplicationRead is the read function for the Flink Application resource. -func resourceFlinkApplicationRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceFlinkApplicationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, ID, err := schemautil.SplitResourceID3(d.Id()) @@ -79,7 +79,7 @@ func resourceFlinkApplicationRead(_ context.Context, d *schema.ResourceData, m i return diag.FromErr(err) } - r, err := client.FlinkApplications.Get(project, serviceName, ID) + r, err := client.FlinkApplications.Get(ctx, project, serviceName, ID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -126,7 +126,7 @@ func resourceFlinkApplicationCreate(ctx context.Context, d *schema.ResourceData, project := d.Get("project").(string) serviceName := d.Get("service_name").(string) - r, err := client.FlinkApplications.Create(project, serviceName, aiven.CreateFlinkApplicationRequest{ + r, err := client.FlinkApplications.Create(ctx, project, serviceName, aiven.CreateFlinkApplicationRequest{ Name: d.Get("name").(string), }) if err != nil { @@ -146,7 +146,7 @@ func resourceFlinkApplicationUpdate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - _, err = client.FlinkApplications.Update(project, serviceName, ID, aiven.UpdateFlinkApplicationRequest{ + _, err = client.FlinkApplications.Update(ctx, project, serviceName, ID, aiven.UpdateFlinkApplicationRequest{ Name: d.Get("name").(string), }) if err != nil { @@ -157,7 +157,7 @@ func resourceFlinkApplicationUpdate(ctx context.Context, d *schema.ResourceData, } // resourceFlinkApplicationDelete is the delete function for the Flink Application resource. -func resourceFlinkApplicationDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceFlinkApplicationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, ID, err := schemautil.SplitResourceID3(d.Id()) @@ -165,7 +165,7 @@ func resourceFlinkApplicationDelete(_ context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - _, err = client.FlinkApplications.Delete(project, serviceName, ID) + _, err = client.FlinkApplications.Delete(ctx, project, serviceName, ID) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/flink/flink_application_data_source.go b/internal/sdkprovider/service/flink/flink_application_data_source.go index 39533663b..9a8ede37e 100644 --- a/internal/sdkprovider/service/flink/flink_application_data_source.go +++ b/internal/sdkprovider/service/flink/flink_application_data_source.go @@ -3,7 +3,7 @@ package flink import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -25,7 +25,7 @@ func datasourceFlinkApplicationRead(ctx context.Context, d *schema.ResourceData, serviceName := d.Get("service_name").(string) applicationName := d.Get("name").(string) - a, err := client.FlinkApplications.List(project, serviceName) + a, err := client.FlinkApplications.List(ctx, project, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/flink/flink_application_deployment.go b/internal/sdkprovider/service/flink/flink_application_deployment.go index dd4234e0c..b398f8661 100644 --- a/internal/sdkprovider/service/flink/flink_application_deployment.go +++ b/internal/sdkprovider/service/flink/flink_application_deployment.go @@ -5,7 +5,7 @@ import ( "context" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -112,7 +112,7 @@ func resourceFlinkApplicationDeploymentCreate( req.VersionID = v.(string) } - r, err := client.FlinkApplicationDeployments.Create(project, serviceName, applicationID, req) + r, err := client.FlinkApplicationDeployments.Create(ctx, project, serviceName, applicationID, req) if err != nil { return diag.Errorf("cannot create Flink Application Deployment: %v", err) } @@ -137,7 +137,7 @@ func resourceFlinkApplicationDeploymentDelete( return diag.Errorf("cannot read Flink Application Deployment resource ID: %v", err) } - _, err = client.FlinkApplicationDeployments.Cancel(project, serviceName, applicationID, deploymentID) + _, err = client.FlinkApplicationDeployments.Cancel(ctx, project, serviceName, applicationID, deploymentID) if err != nil { return diag.Errorf("error cancelling Flink Application Deployment: %v", err) } @@ -151,7 +151,7 @@ func resourceFlinkApplicationDeploymentDelete( "CANCELED", }, Refresh: func() (interface{}, string, error) { - r, err := client.FlinkApplicationDeployments.Get(project, serviceName, applicationID, deploymentID) + r, err := client.FlinkApplicationDeployments.Get(ctx, project, serviceName, applicationID, deploymentID) if err != nil { return nil, "", err } @@ -167,7 +167,7 @@ func resourceFlinkApplicationDeploymentDelete( return diag.Errorf("error waiting for Flink Application Deployment to become canceled: %s", err) } - _, err = client.FlinkApplicationDeployments.Delete(project, serviceName, applicationID, deploymentID) + _, err = client.FlinkApplicationDeployments.Delete(ctx, project, serviceName, applicationID, deploymentID) if err != nil { return diag.Errorf("error deleting Flink Application Deployment: %v", err) } @@ -176,7 +176,7 @@ func resourceFlinkApplicationDeploymentDelete( } // resourceFlinkApplicationDeploymentRead reads an existing Flink Application Deployment resource. -func resourceFlinkApplicationDeploymentRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceFlinkApplicationDeploymentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, applicationID, deploymentID, err := schemautil.SplitResourceID4(d.Id()) @@ -184,7 +184,7 @@ func resourceFlinkApplicationDeploymentRead(_ context.Context, d *schema.Resourc return diag.Errorf("cannot read Flink Application Deployment resource ID: %v", err) } - r, err := client.FlinkApplicationDeployments.Get(project, serviceName, applicationID, deploymentID) + r, err := client.FlinkApplicationDeployments.Get(ctx, project, serviceName, applicationID, deploymentID) if err != nil { return diag.Errorf("cannot get Flink Application Deployment: %v", err) } diff --git a/internal/sdkprovider/service/flink/flink_application_version.go b/internal/sdkprovider/service/flink/flink_application_version.go index 3cfda9118..9a6405697 100644 --- a/internal/sdkprovider/service/flink/flink_application_version.go +++ b/internal/sdkprovider/service/flink/flink_application_version.go @@ -3,7 +3,7 @@ package flink import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -186,7 +186,7 @@ func resourceFlinkApplicationVersionCreate(ctx context.Context, d *schema.Resour sinks = expandFlinkApplicationVersionSourcesOrSinks(d.Get("sink").(*schema.Set).List()) } - r, err := client.FlinkApplicationVersions.Create(project, serviceName, applicationID, aiven.GenericFlinkApplicationVersionRequest{ + r, err := client.FlinkApplicationVersions.Create(ctx, project, serviceName, applicationID, aiven.GenericFlinkApplicationVersionRequest{ Statement: d.Get("statement").(string), Sources: sources, Sinks: sinks, @@ -215,7 +215,7 @@ func expandFlinkApplicationVersionSourcesOrSinks(sources []interface{}) []aiven. } // resourceFlinkApplicationVersionDelete is the delete function for the Flink Application Version resource. -func resourceFlinkApplicationVersionDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceFlinkApplicationVersionDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, applicationID, version, err := schemautil.SplitResourceID4(d.Id()) @@ -223,7 +223,7 @@ func resourceFlinkApplicationVersionDelete(_ context.Context, d *schema.Resource return diag.Errorf("cannot read Flink Application Version resource ID: %v", err) } - _, err = client.FlinkApplicationVersions.Delete(project, serviceName, applicationID, version) + _, err = client.FlinkApplicationVersions.Delete(ctx, project, serviceName, applicationID, version) if err != nil { return diag.Errorf("error deleting Flink Application Version: %v", err) } @@ -232,7 +232,7 @@ func resourceFlinkApplicationVersionDelete(_ context.Context, d *schema.Resource } // resourceFlinkApplicationVersionRead is the read function for the Flink Application Version resource. -func resourceFlinkApplicationVersionRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceFlinkApplicationVersionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, applicationID, version, err := schemautil.SplitResourceID4(d.Id()) @@ -240,7 +240,7 @@ func resourceFlinkApplicationVersionRead(_ context.Context, d *schema.ResourceDa return diag.Errorf("cannot read Flink Application Version resource ID: %v", err) } - r, err := client.FlinkApplicationVersions.Get(project, serviceName, applicationID, version) + r, err := client.FlinkApplicationVersions.Get(ctx, project, serviceName, applicationID, version) if err != nil { return diag.Errorf("cannot get Flink Application Version: %v", err) } diff --git a/internal/sdkprovider/service/flink/flink_application_version_data_source.go b/internal/sdkprovider/service/flink/flink_application_version_data_source.go index fd4654daf..429df7161 100644 --- a/internal/sdkprovider/service/flink/flink_application_version_data_source.go +++ b/internal/sdkprovider/service/flink/flink_application_version_data_source.go @@ -3,7 +3,7 @@ package flink import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceFlinkApplicationVersionRead(ctx context.Context, d *schema.Resour appID := d.Get("application_id").(string) versionID := d.Get("application_version_id").(string) - _, err := client.FlinkApplicationVersions.Get(project, serviceName, appID, versionID) + _, err := client.FlinkApplicationVersions.Get(ctx, project, serviceName, appID, versionID) if err != nil { if aiven.IsNotFound(err) { return diag.Errorf("flink application version %s not found", versionID) diff --git a/internal/sdkprovider/service/flink/flink_application_version_test.go b/internal/sdkprovider/service/flink/flink_application_version_test.go index c44041608..abde606db 100644 --- a/internal/sdkprovider/service/flink/flink_application_version_test.go +++ b/internal/sdkprovider/service/flink/flink_application_version_test.go @@ -1,11 +1,12 @@ package flink_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -52,6 +53,8 @@ func TestAccAivenFlinkApplicationVersion_basic(t *testing.T) { func testAccCheckAivenFlinkDestroy(s *terraform.State) error { client := acc.GetTestAivenClient() + ctx := context.Background() + for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_flink_application_version" { continue @@ -61,7 +64,8 @@ func testAccCheckAivenFlinkDestroy(s *terraform.State) error { if err != nil { return err } - v, err := client.FlinkApplicationVersions.Get(project, serviceName, applicationID, version) + + v, err := client.FlinkApplicationVersions.Get(ctx, project, serviceName, applicationID, version) if err != nil && !aiven.IsNotFound(err) { return err } diff --git a/internal/sdkprovider/service/influxdb/influxdb_database.go b/internal/sdkprovider/service/influxdb/influxdb_database.go index 7275a68c1..22f111b70 100644 --- a/internal/sdkprovider/service/influxdb/influxdb_database.go +++ b/internal/sdkprovider/service/influxdb/influxdb_database.go @@ -3,7 +3,7 @@ package influxdb import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -51,6 +51,7 @@ func resourceInfluxDBDatabaseCreate(ctx context.Context, d *schema.ResourceData, serviceName := d.Get("service_name").(string) databaseName := d.Get("database_name").(string) _, err := client.Databases.Create( + ctx, projectName, serviceName, aiven.CreateDatabaseRequest{ @@ -72,7 +73,7 @@ func resourceInfluxDBDatabaseUpdate(ctx context.Context, d *schema.ResourceData, return resourceInfluxDBDatabaseRead(ctx, d, m) } -func resourceInfluxDBDatabaseRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceInfluxDBDatabaseRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, databaseName, err := schemautil.SplitResourceID3(d.Id()) @@ -80,7 +81,7 @@ func resourceInfluxDBDatabaseRead(_ context.Context, d *schema.ResourceData, m i return diag.FromErr(err) } - database, err := client.Databases.Get(projectName, serviceName, databaseName) + database, err := client.Databases.Get(ctx, projectName, serviceName, databaseName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -111,6 +112,7 @@ func resourceInfluxDBDatabaseDelete(ctx context.Context, d *schema.ResourceData, } waiter := schemautil.DatabaseDeleteWaiter{ + Context: ctx, Client: client, ProjectName: projectName, ServiceName: serviceName, diff --git a/internal/sdkprovider/service/influxdb/influxdb_database_data_source.go b/internal/sdkprovider/service/influxdb/influxdb_database_data_source.go index 98c862ce3..09d68bf04 100644 --- a/internal/sdkprovider/service/influxdb/influxdb_database_data_source.go +++ b/internal/sdkprovider/service/influxdb/influxdb_database_data_source.go @@ -3,7 +3,7 @@ package influxdb import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceDatabaseRead(ctx context.Context, d *schema.ResourceData, m inter serviceName := d.Get("service_name").(string) databaseName := d.Get("database_name").(string) - databases, err := client.Databases.List(projectName, serviceName) + databases, err := client.Databases.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/influxdb/influxdb_database_test.go b/internal/sdkprovider/service/influxdb/influxdb_database_test.go index c2b0aac5f..d453d9416 100644 --- a/internal/sdkprovider/service/influxdb/influxdb_database_test.go +++ b/internal/sdkprovider/service/influxdb/influxdb_database_test.go @@ -1,13 +1,14 @@ package influxdb_test import ( + "context" "errors" "fmt" "os" "strings" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -89,6 +90,8 @@ func TestAccAivenInfluxDBDatabase_basic(t *testing.T) { func testAccCheckAivenInfluxDBDatabaseResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each database is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_influxdb_database" { @@ -100,7 +103,7 @@ func testAccCheckAivenInfluxDBDatabaseResourceDestroy(s *terraform.State) error return err } - db, err := c.Databases.Get(projectName, serviceName, databaseName) + db, err := c.Databases.Get(ctx, projectName, serviceName, databaseName) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/influxdb/influxdb_user_test.go b/internal/sdkprovider/service/influxdb/influxdb_user_test.go index fbfd42235..2d56b9c76 100644 --- a/internal/sdkprovider/service/influxdb/influxdb_user_test.go +++ b/internal/sdkprovider/service/influxdb/influxdb_user_test.go @@ -1,11 +1,12 @@ package influxdb_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -40,6 +41,8 @@ func TestAccAivenInfluxDBUser_basic(t *testing.T) { func testAccCheckAivenInfluxDBUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_influxdb_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_influxdb_user" { @@ -51,7 +54,7 @@ func testAccCheckAivenInfluxDBUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/kafka/kafka.go b/internal/sdkprovider/service/kafka/kafka.go index 37e1f4903..094efcb0d 100644 --- a/internal/sdkprovider/service/kafka/kafka.go +++ b/internal/sdkprovider/service/kafka/kafka.go @@ -4,7 +4,7 @@ import ( "context" "strconv" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -118,7 +118,7 @@ func ResourceKafka() *schema.Resource { serviceName := d.Get("service_name").(string) client := m.(*aiven.Client) - kafka, err := client.Services.Get(project, serviceName) + kafka, err := client.Services.Get(ctx, project, serviceName) if err != nil { return false } @@ -156,7 +156,7 @@ func resourceKafkaCreate(ctx context.Context, d *schema.ResourceData, m interfac defaultSchemaRegistryACLSubject = "default-sr-admin-subject" ) - if err := client.KafkaACLs.Delete(project, serviceName, defaultACLId); err != nil && !aiven.IsNotFound(err) { + if err := client.KafkaACLs.Delete(ctx, project, serviceName, defaultACLId); err != nil && !aiven.IsNotFound(err) { return diag.Errorf("cannot delete default wildcard kafka acl: %s", err) } @@ -165,7 +165,7 @@ func resourceKafkaCreate(ctx context.Context, d *schema.ResourceData, m interfac defaultSchemaRegistryACLSubject, } for _, acl := range defaultSchemaACLLs { - if err := client.KafkaSchemaRegistryACLs.Delete(project, serviceName, acl); err != nil && !aiven.IsNotFound(err) { + if err := client.KafkaSchemaRegistryACLs.Delete(ctx, project, serviceName, acl); err != nil && !aiven.IsNotFound(err) { return diag.Errorf("cannot delete `%s` kafka ACL for Schema Registry: %s", acl, err) } } @@ -182,7 +182,7 @@ func resourceKafkaRead(ctx context.Context, d *schema.ResourceData, m interface{ return diag.FromErr(err) } - kafka, err := client.Services.Get(project, service) + kafka, err := client.Services.Get(ctx, project, service) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } diff --git a/internal/sdkprovider/service/kafka/kafka_acl.go b/internal/sdkprovider/service/kafka/kafka_acl.go index 40d36c2bf..598e5b039 100644 --- a/internal/sdkprovider/service/kafka/kafka_acl.go +++ b/internal/sdkprovider/service/kafka/kafka_acl.go @@ -3,7 +3,7 @@ package kafka import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -66,6 +66,7 @@ func resourceKafkaACLCreate(ctx context.Context, d *schema.ResourceData, m inter serviceName := d.Get("service_name").(string) acl, err := client.KafkaACLs.Create( + ctx, project, serviceName, aiven.CreateKafkaACLRequest{ @@ -83,7 +84,7 @@ func resourceKafkaACLCreate(ctx context.Context, d *schema.ResourceData, m inter return resourceKafkaACLRead(ctx, d, m) } -func resourceKafkaACLRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaACLRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, aclID, err := schemautil.SplitResourceID3(d.Id()) @@ -91,7 +92,7 @@ func resourceKafkaACLRead(_ context.Context, d *schema.ResourceData, m interface return diag.FromErr(err) } - acl, err := kafkaACLCache{}.Read(project, serviceName, aclID, client) + acl, err := kafkaACLCache{}.Read(ctx, project, serviceName, aclID, client) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -104,7 +105,7 @@ func resourceKafkaACLRead(_ context.Context, d *schema.ResourceData, m interface return nil } -func resourceKafkaACLDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaACLDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, aclID, err := schemautil.SplitResourceID3(d.Id()) @@ -112,7 +113,7 @@ func resourceKafkaACLDelete(_ context.Context, d *schema.ResourceData, m interfa return diag.FromErr(err) } - err = client.KafkaACLs.Delete(projectName, serviceName, aclID) + err = client.KafkaACLs.Delete(ctx, projectName, serviceName, aclID) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafka/kafka_acl_cache.go b/internal/sdkprovider/service/kafka/kafka_acl_cache.go index ea3d2b716..c7fe48cca 100644 --- a/internal/sdkprovider/service/kafka/kafka_acl_cache.go +++ b/internal/sdkprovider/service/kafka/kafka_acl_cache.go @@ -1,11 +1,12 @@ package kafka import ( + "context" "fmt" "log" "sync" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" ) var ( @@ -19,12 +20,18 @@ type kafkaACLCache struct { // Read populates the cache if it doesn't exist, and reads the required acl. An aiven.Error with status // 404 is returned upon cache miss -func (a kafkaACLCache) Read(project, service, aclID string, client *aiven.Client) (acl aiven.KafkaACL, err error) { +func (a kafkaACLCache) Read( + ctx context.Context, + project string, + service string, + aclID string, + client *aiven.Client, +) (acl aiven.KafkaACL, err error) { aclCacheLock.Lock() defer aclCacheLock.Unlock() if _, ok := acls[project+service]; !ok { - if err = a.populateACLCache(project, service, client); err != nil { - return + if err = a.populateACLCache(ctx, project, service, client); err != nil { + return acl, err } } if cachedService, ok := acls[project+service]; ok { @@ -32,7 +39,7 @@ func (a kafkaACLCache) Read(project, service, aclID string, client *aiven.Client // cache miss, try to get the ACL from the Aiven API instead log.Printf("Cache miss on ACL: %s, going live to Aiven API", aclID) var liveACL *aiven.KafkaACL - if liveACL, err = client.KafkaACLs.Get(project, service, aclID); err == nil { + if liveACL, err = client.KafkaACLs.Get(ctx, project, service, aclID); err == nil { acl = *liveACL } } @@ -45,7 +52,7 @@ func (a kafkaACLCache) Read(project, service, aclID string, client *aiven.Client } } - return + return acl, err } // write writes the specified ACL to the cache @@ -61,17 +68,10 @@ func (a kafkaACLCache) write(project, service string, acl *aiven.KafkaACL) (err return } -// Refresh refreshes the ACL cache -func (a kafkaACLCache) Refresh(project, service string, client *aiven.Client) error { - aclCacheLock.Lock() - defer aclCacheLock.Unlock() - return a.populateACLCache(project, service, client) -} - // populateACLCache makes a call to Aiven to list kafka ACLs, and upserts into the cache -func (a kafkaACLCache) populateACLCache(project, service string, client *aiven.Client) (err error) { +func (a kafkaACLCache) populateACLCache(ctx context.Context, project, service string, client *aiven.Client) (err error) { var acls []*aiven.KafkaACL - if acls, err = client.KafkaACLs.List(project, service); err == nil { + if acls, err = client.KafkaACLs.List(ctx, project, service); err == nil { for _, acl := range acls { err := a.write(project, service, acl) if err != nil { diff --git a/internal/sdkprovider/service/kafka/kafka_acl_data_source.go b/internal/sdkprovider/service/kafka/kafka_acl_data_source.go index 0ffc19f2b..4fc3362d3 100644 --- a/internal/sdkprovider/service/kafka/kafka_acl_data_source.go +++ b/internal/sdkprovider/service/kafka/kafka_acl_data_source.go @@ -3,7 +3,7 @@ package kafka import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -29,7 +29,7 @@ func datasourceKafkaACLRead(ctx context.Context, d *schema.ResourceData, m inter userName := d.Get("username").(string) permission := d.Get("permission").(string) - acls, err := client.KafkaACLs.List(projectName, serviceName) + acls, err := client.KafkaACLs.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafka/kafka_acl_test.go b/internal/sdkprovider/service/kafka/kafka_acl_test.go index 6cb92cc82..fae35f77c 100644 --- a/internal/sdkprovider/service/kafka/kafka_acl_test.go +++ b/internal/sdkprovider/service/kafka/kafka_acl_test.go @@ -1,13 +1,14 @@ package kafka_test import ( + "context" "fmt" "log" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -243,6 +244,8 @@ data "aiven_kafka_acl" "acl" { func testAccCheckAivenKafkaACLResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each kafka ACL is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_kafka_acl" { @@ -254,7 +257,7 @@ func testAccCheckAivenKafkaACLResourceDestroy(s *terraform.State) error { return err } - p, err := c.KafkaACLs.Get(project, serviceName, aclID) + p, err := c.KafkaACLs.Get(ctx, project, serviceName, aclID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/kafka/kafka_connector.go b/internal/sdkprovider/service/kafka/kafka_connector.go index 1a9cc6647..86cfbb888 100644 --- a/internal/sdkprovider/service/kafka/kafka_connector.go +++ b/internal/sdkprovider/service/kafka/kafka_connector.go @@ -6,7 +6,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -159,7 +159,7 @@ func resourceKafkaConnectorRead(ctx context.Context, d *schema.ResourceData, m i Pending: []string{"IN_PROGRESS"}, Target: []string{"OK"}, Refresh: func() (interface{}, string, error) { - list, err := m.(*aiven.Client).KafkaConnectors.List(project, serviceName) + list, err := m.(*aiven.Client).KafkaConnectors.List(ctx, project, serviceName) if err != nil { log.Printf("[DEBUG] Kafka Connectors list waiter err %s", err.Error()) if aiven.IsNotFound(err) { @@ -243,7 +243,7 @@ func resourceKafkaConnectorCreate(ctx context.Context, d *schema.ResourceData, m // Since the aiven.Client has own retries for various scenarios // we retry here 404 only err := retry.RetryContext(ctx, time.Minute, func() *retry.RetryError { - err := m.(*aiven.Client).KafkaConnectors.Create(project, serviceName, config) + err := m.(*aiven.Client).KafkaConnectors.Create(ctx, project, serviceName, config) if err != nil { return &retry.RetryError{ Err: err, @@ -263,13 +263,13 @@ func resourceKafkaConnectorCreate(ctx context.Context, d *schema.ResourceData, m return resourceKafkaConnectorRead(ctx, d, m) } -func resourceKafkaConnectorDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaConnectorDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { project, service, name, err := schemautil.SplitResourceID3(d.Id()) if err != nil { return diag.FromErr(err) } - err = m.(*aiven.Client).KafkaConnectors.Delete(project, service, name) + err = m.(*aiven.Client).KafkaConnectors.Delete(ctx, project, service, name) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } @@ -288,7 +288,7 @@ func resourceKafkaTConnectorUpdate(ctx context.Context, d *schema.ResourceData, config[k] = cS.(string) } - _, err = m.(*aiven.Client).KafkaConnectors.Update(project, serviceName, connectorName, config) + _, err = m.(*aiven.Client).KafkaConnectors.Update(ctx, project, serviceName, connectorName, config) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafka/kafka_connector_data_source.go b/internal/sdkprovider/service/kafka/kafka_connector_data_source.go index a25813ffa..20c1b3b0f 100644 --- a/internal/sdkprovider/service/kafka/kafka_connector_data_source.go +++ b/internal/sdkprovider/service/kafka/kafka_connector_data_source.go @@ -3,7 +3,7 @@ package kafka import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -24,7 +24,7 @@ func datasourceKafkaConnectorRead(ctx context.Context, d *schema.ResourceData, m serviceName := d.Get("service_name").(string) connectorName := d.Get("connector_name").(string) - cons, err := m.(*aiven.Client).KafkaConnectors.List(projectName, serviceName) + cons, err := m.(*aiven.Client).KafkaConnectors.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafka/kafka_connector_test.go b/internal/sdkprovider/service/kafka/kafka_connector_test.go index 9bd08555a..286571b08 100644 --- a/internal/sdkprovider/service/kafka/kafka_connector_test.go +++ b/internal/sdkprovider/service/kafka/kafka_connector_test.go @@ -1,12 +1,13 @@ package kafka_test import ( + "context" "fmt" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -70,6 +71,8 @@ func TestAccAivenKafkaConnector_mogosink(t *testing.T) { func testAccCheckAivenKafkaConnectorResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_kafka_connector is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_kafka" { @@ -81,7 +84,7 @@ func testAccCheckAivenKafkaConnectorResourceDestroy(s *terraform.State) error { return err } - _, err = c.Services.Get(projectName, serviceName) + _, err = c.Services.Get(ctx, projectName, serviceName) if err != nil { if err.(aiven.Error).Status == 404 { return nil @@ -90,7 +93,7 @@ func testAccCheckAivenKafkaConnectorResourceDestroy(s *terraform.State) error { return err } - list, err := c.KafkaConnectors.List(projectName, serviceName) + list, err := c.KafkaConnectors.List(ctx, projectName, serviceName) if err != nil { if err.(aiven.Error).Status == 404 { return nil @@ -100,7 +103,7 @@ func testAccCheckAivenKafkaConnectorResourceDestroy(s *terraform.State) error { } for _, connector := range list.Connectors { - res, err := c.KafkaConnectors.GetByName(projectName, serviceName, connector.Name) + res, err := c.KafkaConnectors.GetByName(ctx, projectName, serviceName, connector.Name) if err != nil { if err.(aiven.Error).Status == 404 { return nil diff --git a/internal/sdkprovider/service/kafka/kafka_test.go b/internal/sdkprovider/service/kafka/kafka_test.go index 9b5ddcd6a..4e85d7810 100644 --- a/internal/sdkprovider/service/kafka/kafka_test.go +++ b/internal/sdkprovider/service/kafka/kafka_test.go @@ -1,12 +1,13 @@ package kafka_test import ( + "context" "fmt" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -77,7 +78,10 @@ func TestAccAiven_kafka(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "service_uri"), func(state *terraform.State) error { c := acc.GetTestAivenClient() - a, err := c.KafkaACLs.List(os.Getenv("AIVEN_PROJECT_NAME"), rName2) + + ctx := context.Background() + + a, err := c.KafkaACLs.List(ctx, os.Getenv("AIVEN_PROJECT_NAME"), rName2) if err != nil && !aiven.IsNotFound(err) { return fmt.Errorf("cannot get a list of kafka ACLs: %s", err) } @@ -86,7 +90,7 @@ func TestAccAiven_kafka(t *testing.T) { return fmt.Errorf("list of ACLs should be empty") } - s, err := c.KafkaSchemaRegistryACLs.List(os.Getenv("AIVEN_PROJECT_NAME"), rName2) + s, err := c.KafkaSchemaRegistryACLs.List(ctx, os.Getenv("AIVEN_PROJECT_NAME"), rName2) if err != nil && !aiven.IsNotFound(err) { return fmt.Errorf("cannot get a list of Kafka Schema ACLs: %s", err) } diff --git a/internal/sdkprovider/service/kafka/kafka_user_test.go b/internal/sdkprovider/service/kafka/kafka_user_test.go index 30484f03d..820976731 100644 --- a/internal/sdkprovider/service/kafka/kafka_user_test.go +++ b/internal/sdkprovider/service/kafka/kafka_user_test.go @@ -1,11 +1,12 @@ package kafka_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -40,6 +41,8 @@ func TestAccAivenKafkaUser_basic(t *testing.T) { func testAccCheckAivenKafkaUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_kafka_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_kafka_user" { @@ -51,7 +54,7 @@ func testAccCheckAivenKafkaUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/kafka/mirrormaker_replication_flow.go b/internal/sdkprovider/service/kafka/mirrormaker_replication_flow.go index 05d45e13e..f3a565d29 100644 --- a/internal/sdkprovider/service/kafka/mirrormaker_replication_flow.go +++ b/internal/sdkprovider/service/kafka/mirrormaker_replication_flow.go @@ -3,7 +3,7 @@ package kafka import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -119,7 +119,7 @@ func resourceMirrorMakerReplicationFlowCreate(ctx context.Context, d *schema.Res sourceCluster := d.Get("source_cluster").(string) targetCluster := d.Get("target_cluster").(string) - err := client.KafkaMirrorMakerReplicationFlow.Create(project, serviceName, aiven.MirrorMakerReplicationFlowRequest{ + err := client.KafkaMirrorMakerReplicationFlow.Create(ctx, project, serviceName, aiven.MirrorMakerReplicationFlowRequest{ ReplicationFlow: aiven.ReplicationFlow{ Enabled: enable, SourceCluster: sourceCluster, @@ -142,7 +142,7 @@ func resourceMirrorMakerReplicationFlowCreate(ctx context.Context, d *schema.Res return resourceMirrorMakerReplicationFlowRead(ctx, d, m) } -func resourceMirrorMakerReplicationFlowRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceMirrorMakerReplicationFlowRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, sourceCluster, targetCluster, err := schemautil.SplitResourceID4(d.Id()) @@ -150,7 +150,7 @@ func resourceMirrorMakerReplicationFlowRead(_ context.Context, d *schema.Resourc return diag.FromErr(err) } - replicationFlow, err := client.KafkaMirrorMakerReplicationFlow.Get(project, serviceName, sourceCluster, targetCluster) + replicationFlow, err := client.KafkaMirrorMakerReplicationFlow.Get(ctx, project, serviceName, sourceCluster, targetCluster) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -201,6 +201,7 @@ func resourceMirrorMakerReplicationFlowUpdate(ctx context.Context, d *schema.Res } _, err = client.KafkaMirrorMakerReplicationFlow.Update( + ctx, project, serviceName, sourceCluster, @@ -225,7 +226,7 @@ func resourceMirrorMakerReplicationFlowUpdate(ctx context.Context, d *schema.Res return resourceMirrorMakerReplicationFlowRead(ctx, d, m) } -func resourceMirrorMakerReplicationFlowDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceMirrorMakerReplicationFlowDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, sourceCluster, targetCluster, err := schemautil.SplitResourceID4(d.Id()) @@ -233,7 +234,7 @@ func resourceMirrorMakerReplicationFlowDelete(_ context.Context, d *schema.Resou return diag.FromErr(err) } - err = client.KafkaMirrorMakerReplicationFlow.Delete(project, serviceName, sourceCluster, targetCluster) + err = client.KafkaMirrorMakerReplicationFlow.Delete(ctx, project, serviceName, sourceCluster, targetCluster) if err != nil { diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafka/mirrormaker_replication_flow_test.go b/internal/sdkprovider/service/kafka/mirrormaker_replication_flow_test.go index 3c9457e18..c3501078a 100644 --- a/internal/sdkprovider/service/kafka/mirrormaker_replication_flow_test.go +++ b/internal/sdkprovider/service/kafka/mirrormaker_replication_flow_test.go @@ -1,12 +1,13 @@ package kafka_test import ( + "context" "fmt" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -43,6 +44,8 @@ func TestAccAivenMirrorMakerReplicationFlow_basic(t *testing.T) { func testAccCheckAivenMirrorMakerReplicationFlowResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each kafka mirror maker // replication flow is destroyed for _, rs := range s.RootModule().Resources { @@ -55,7 +58,7 @@ func testAccCheckAivenMirrorMakerReplicationFlowResourceDestroy(s *terraform.Sta return err } - s, err := c.Services.Get(project, serviceName) + s, err := c.Services.Get(ctx, project, serviceName) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -64,7 +67,7 @@ func testAccCheckAivenMirrorMakerReplicationFlowResourceDestroy(s *terraform.Sta } if s.Type == "kafka_mirrormaker" { - f, err := c.KafkaMirrorMakerReplicationFlow.Get(project, serviceName, sourceCluster, targetCluster) + f, err := c.KafkaMirrorMakerReplicationFlow.Get(ctx, project, serviceName, sourceCluster, targetCluster) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema.go b/internal/sdkprovider/service/kafkaschema/kafka_schema.go index d652f3b8f..956685868 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema.go @@ -6,7 +6,7 @@ import ( "fmt" "reflect" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" @@ -103,10 +103,16 @@ func ResourceKafkaSchema() *schema.Resource { } } -func kafkaSchemaSubjectGetLastVersion(m interface{}, project, serviceName, subjectName string) (int, error) { +func kafkaSchemaSubjectGetLastVersion( + ctx context.Context, + m interface{}, + project string, + serviceName string, + subjectName string, +) (int, error) { client := m.(*aiven.Client) - r, err := client.KafkaSubjectSchemas.GetVersions(project, serviceName, subjectName) + r, err := client.KafkaSubjectSchemas.GetVersions(ctx, project, serviceName, subjectName) if err != nil { return 0, err } @@ -134,6 +140,7 @@ func resourceKafkaSchemaCreate(ctx context.Context, d *schema.ResourceData, m in // create Kafka Schema Subject _, err := client.KafkaSubjectSchemas.Add( + ctx, project, serviceName, subjectName, @@ -149,6 +156,7 @@ func resourceKafkaSchemaCreate(ctx context.Context, d *schema.ResourceData, m in // set compatibility level if defined for a newly created Kafka Schema Subject if compatibility, ok := d.GetOk("compatibility_level"); ok { _, err := client.KafkaSubjectSchemas.UpdateConfiguration( + ctx, project, serviceName, subjectName, @@ -159,7 +167,7 @@ func resourceKafkaSchemaCreate(ctx context.Context, d *schema.ResourceData, m in } } - version, err := kafkaSchemaSubjectGetLastVersion(m, project, serviceName, subjectName) + version, err := kafkaSchemaSubjectGetLastVersion(ctx, m, project, serviceName, subjectName) if err != nil { return diag.Errorf("unable to get last version: %s", err) } @@ -184,6 +192,7 @@ func resourceKafkaSchemaUpdate(ctx context.Context, d *schema.ResourceData, m in if d.HasChange("schema") { _, err := client.KafkaSubjectSchemas.Add( + ctx, project, serviceName, subjectName, @@ -200,6 +209,7 @@ func resourceKafkaSchemaUpdate(ctx context.Context, d *schema.ResourceData, m in // if compatibility_level has changed and the new value is not empty if compatibility, ok := d.GetOk("compatibility_level"); ok { _, err = client.KafkaSubjectSchemas.UpdateConfiguration( + ctx, project, serviceName, subjectName, @@ -212,7 +222,7 @@ func resourceKafkaSchemaUpdate(ctx context.Context, d *schema.ResourceData, m in return resourceKafkaSchemaRead(ctx, d, m) } -func resourceKafkaSchemaRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaSchemaRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { project, serviceName, subjectName, err := schemautil.SplitResourceID3(d.Id()) if err != nil { return diag.FromErr(err) @@ -220,12 +230,12 @@ func resourceKafkaSchemaRead(_ context.Context, d *schema.ResourceData, m interf client := m.(*aiven.Client) - version, err := kafkaSchemaSubjectGetLastVersion(m, project, serviceName, subjectName) + version, err := kafkaSchemaSubjectGetLastVersion(ctx, m, project, serviceName, subjectName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } - r, err := client.KafkaSubjectSchemas.Get(project, serviceName, subjectName, version) + r, err := client.KafkaSubjectSchemas.Get(ctx, project, serviceName, subjectName, version) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -246,7 +256,7 @@ func resourceKafkaSchemaRead(_ context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } - c, err := client.KafkaSubjectSchemas.GetConfiguration(project, serviceName, subjectName) + c, err := client.KafkaSubjectSchemas.GetConfiguration(ctx, project, serviceName, subjectName) if err != nil { if !aiven.IsNotFound(err) { return diag.FromErr(err) @@ -260,13 +270,13 @@ func resourceKafkaSchemaRead(_ context.Context, d *schema.ResourceData, m interf return nil } -func resourceKafkaSchemaDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaSchemaDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { project, serviceName, schemaName, err := schemautil.SplitResourceID3(d.Id()) if err != nil { return diag.FromErr(err) } - err = m.(*aiven.Client).KafkaSubjectSchemas.Delete(project, serviceName, schemaName) + err = m.(*aiven.Client).KafkaSubjectSchemas.Delete(ctx, project, serviceName, schemaName) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } @@ -274,7 +284,7 @@ func resourceKafkaSchemaDelete(_ context.Context, d *schema.ResourceData, m inte return nil } -func resourceKafkaSchemaCustomizeDiff(_ context.Context, d *schema.ResourceDiff, m interface{}) error { +func resourceKafkaSchemaCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, m interface{}) error { client := m.(*aiven.Client) // no previous version: allow the diff, nothing to check compatibility against @@ -283,6 +293,7 @@ func resourceKafkaSchemaCustomizeDiff(_ context.Context, d *schema.ResourceDiff, } if compatible, err := client.KafkaSubjectSchemas.Validate( + ctx, d.Get("project").(string), d.Get("service_name").(string), d.Get("subject_name").(string), diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration.go b/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration.go index 6ad24ffe5..271287500 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration.go @@ -3,7 +3,7 @@ package kafkaschema import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -62,6 +62,7 @@ func resourceKafkaSchemaConfigurationUpdate(ctx context.Context, d *schema.Resou } _, err = m.(*aiven.Client).KafkaGlobalSchemaConfig.Update( + ctx, project, serviceName, aiven.KafkaSchemaConfig{ @@ -80,6 +81,7 @@ func resourceKafkaSchemaConfigurationCreate(ctx context.Context, d *schema.Resou serviceName := d.Get("service_name").(string) _, err := m.(*aiven.Client).KafkaGlobalSchemaConfig.Update( + ctx, project, serviceName, aiven.KafkaSchemaConfig{ @@ -94,13 +96,13 @@ func resourceKafkaSchemaConfigurationCreate(ctx context.Context, d *schema.Resou return resourceKafkaSchemaConfigurationRead(ctx, d, m) } -func resourceKafkaSchemaConfigurationRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaSchemaConfigurationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { project, serviceName, err := schemautil.SplitResourceID2(d.Id()) if err != nil { return diag.FromErr(err) } - r, err := m.(*aiven.Client).KafkaGlobalSchemaConfig.Get(project, serviceName) + r, err := m.(*aiven.Client).KafkaGlobalSchemaConfig.Get(ctx, project, serviceName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -120,13 +122,14 @@ func resourceKafkaSchemaConfigurationRead(_ context.Context, d *schema.ResourceD // resourceKafkaSchemaConfigurationDelete Kafka Schemas configuration cannot be deleted, therefore // on delete event configuration will be set to the default setting -func resourceKafkaSchemaConfigurationDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaSchemaConfigurationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { project, serviceName, err := schemautil.SplitResourceID2(d.Id()) if err != nil { return diag.FromErr(err) } _, err = m.(*aiven.Client).KafkaGlobalSchemaConfig.Update( + ctx, project, serviceName, aiven.KafkaSchemaConfig{ diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration_data_source.go b/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration_data_source.go index 3c08e3837..2dccc57a9 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration_data_source.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema_configuration_data_source.go @@ -3,7 +3,7 @@ package kafkaschema import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -23,7 +23,7 @@ func datasourceKafkaSchemasConfigurationRead(ctx context.Context, d *schema.Reso projectName := d.Get("project").(string) serviceName := d.Get("service_name").(string) - _, err := m.(*aiven.Client).KafkaGlobalSchemaConfig.Get(projectName, serviceName) + _, err := m.(*aiven.Client).KafkaGlobalSchemaConfig.Get(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema_data_source.go b/internal/sdkprovider/service/kafkaschema/kafka_schema_data_source.go index 46915e347..618eda75f 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema_data_source.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema_data_source.go @@ -3,7 +3,7 @@ package kafkaschema import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -24,7 +24,7 @@ func datasourceKafkaSchemaRead(ctx context.Context, d *schema.ResourceData, m in serviceName := d.Get("service_name").(string) subjectName := d.Get("subject_name").(string) - subjects, err := m.(*aiven.Client).KafkaSubjectSchemas.List(projectName, serviceName) + subjects, err := m.(*aiven.Client).KafkaSubjectSchemas.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl.go b/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl.go index da4ebc11d..9d4c22011 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl.go @@ -3,7 +3,7 @@ package kafkaschema import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -66,6 +66,7 @@ func resourceKafkaSchemaRegistryACLCreate(ctx context.Context, d *schema.Resourc serviceName := d.Get("service_name").(string) acl, err := client.KafkaSchemaRegistryACLs.Create( + ctx, project, serviceName, aiven.CreateKafkaSchemaRegistryACLRequest{ @@ -83,7 +84,7 @@ func resourceKafkaSchemaRegistryACLCreate(ctx context.Context, d *schema.Resourc return resourceKafkaSchemaRegistryACLRead(ctx, d, m) } -func resourceKafkaSchemaRegistryACLRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaSchemaRegistryACLRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, aclID, err := schemautil.SplitResourceID3(d.Id()) @@ -91,7 +92,7 @@ func resourceKafkaSchemaRegistryACLRead(_ context.Context, d *schema.ResourceDat return diag.FromErr(err) } - acl, err := client.KafkaSchemaRegistryACLs.Get(project, serviceName, aclID) + acl, err := client.KafkaSchemaRegistryACLs.Get(ctx, project, serviceName, aclID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -104,7 +105,7 @@ func resourceKafkaSchemaRegistryACLRead(_ context.Context, d *schema.ResourceDat return nil } -func resourceKafkaSchemaRegistryACLDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaSchemaRegistryACLDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, aclID, err := schemautil.SplitResourceID3(d.Id()) @@ -112,7 +113,7 @@ func resourceKafkaSchemaRegistryACLDelete(_ context.Context, d *schema.ResourceD return diag.FromErr(err) } - err = client.KafkaSchemaRegistryACLs.Delete(projectName, serviceName, aclID) + err = client.KafkaSchemaRegistryACLs.Delete(ctx, projectName, serviceName, aclID) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_data_source.go b/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_data_source.go index 1e53e54a3..dbf8c4258 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_data_source.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_data_source.go @@ -3,7 +3,7 @@ package kafkaschema import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -29,7 +29,7 @@ func datasourceKafkaSchemaRegistryACLRead(ctx context.Context, d *schema.Resourc userName := d.Get("username").(string) permission := d.Get("permission").(string) - acls, err := client.KafkaSchemaRegistryACLs.List(projectName, serviceName) + acls, err := client.KafkaSchemaRegistryACLs.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_test.go b/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_test.go index b7e71ccbf..0145c0b7c 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_test.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema_registry_acl_test.go @@ -1,13 +1,14 @@ package kafkaschema_test import ( + "context" "fmt" "log" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -243,6 +244,8 @@ data "aiven_kafka_schema_registry_acl" "acl" { func testAccCheckAivenKafkaSchemaRegistryACLResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each kafka ACL is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_kafka_schema_registry_acl" { @@ -254,7 +257,7 @@ func testAccCheckAivenKafkaSchemaRegistryACLResourceDestroy(s *terraform.State) return err } - p, err := c.KafkaSchemaRegistryACLs.Get(project, serviceName, aclID) + p, err := c.KafkaSchemaRegistryACLs.Get(ctx, project, serviceName, aclID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/kafkaschema/kafka_schema_test.go b/internal/sdkprovider/service/kafkaschema/kafka_schema_test.go index 2124a2725..7d3725b2e 100644 --- a/internal/sdkprovider/service/kafkaschema/kafka_schema_test.go +++ b/internal/sdkprovider/service/kafkaschema/kafka_schema_test.go @@ -1,12 +1,13 @@ package kafkaschema_test import ( + "context" "fmt" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -156,6 +157,8 @@ func TestAccAivenKafkaSchema_basic(t *testing.T) { func testAccCheckAivenKafkaSchemaResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_kafka_schema is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_kafka" { @@ -167,7 +170,7 @@ func testAccCheckAivenKafkaSchemaResourceDestroy(s *terraform.State) error { return err } - _, err = c.Services.Get(projectName, serviceName) + _, err = c.Services.Get(ctx, projectName, serviceName) if err != nil { if err.(aiven.Error).Status == 404 { return nil @@ -176,7 +179,7 @@ func testAccCheckAivenKafkaSchemaResourceDestroy(s *terraform.State) error { return err } - schemaList, err := c.KafkaSubjectSchemas.List(projectName, serviceName) + schemaList, err := c.KafkaSubjectSchemas.List(ctx, projectName, serviceName) if err != nil { if err.(aiven.Error).Status == 404 { return nil @@ -186,7 +189,7 @@ func testAccCheckAivenKafkaSchemaResourceDestroy(s *terraform.State) error { } for _, s := range schemaList.KafkaSchemaSubjects.Subjects { - versions, err := c.KafkaSubjectSchemas.GetVersions(projectName, serviceName, s) + versions, err := c.KafkaSubjectSchemas.GetVersions(ctx, projectName, serviceName, s) if err != nil { if err.(aiven.Error).Status == 404 { return nil diff --git a/internal/sdkprovider/service/kafkatopic/kafka_topic.go b/internal/sdkprovider/service/kafkatopic/kafka_topic.go index 3698f451c..3eab1ec1c 100644 --- a/internal/sdkprovider/service/kafkatopic/kafka_topic.go +++ b/internal/sdkprovider/service/kafkatopic/kafka_topic.go @@ -7,7 +7,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -290,6 +290,7 @@ func resourceKafkaTopicCreate(ctx context.Context, d *schema.ResourceData, m int } w := &kafkaTopicCreateWaiter{ + Context: ctx, Client: m.(*aiven.Client), Project: project, ServiceName: serviceName, @@ -452,7 +453,7 @@ func getTopic(ctx context.Context, m interface{}, timeout time.Duration, project return nil, fmt.Errorf("invalid Aiven client") } - w, err := newKafkaTopicAvailabilityWaiter(client, project, serviceName, topicName) + w, err := newKafkaTopicAvailabilityWaiter(ctx, client, project, serviceName, topicName) if err != nil { return nil, err } @@ -470,7 +471,7 @@ func getTopic(ctx context.Context, m interface{}, timeout time.Duration, project return &kt, nil } -func resourceKafkaTopicUpdate(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceKafkaTopicUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) partitions := d.Get("partitions").(int) @@ -480,6 +481,7 @@ func resourceKafkaTopicUpdate(_ context.Context, d *schema.ResourceData, m inter } err = client.KafkaTopics.Update( + ctx, projectName, serviceName, topicName, @@ -510,6 +512,7 @@ func resourceKafkaTopicDelete(ctx context.Context, d *schema.ResourceData, m int } waiter := TopicDeleteWaiter{ + Context: ctx, Client: client, ProjectName: projectName, ServiceName: serviceName, @@ -559,6 +562,7 @@ func flattenKafkaTopicConfig(t *aiven.KafkaTopic) []map[string]interface{} { // TopicDeleteWaiter is used to wait for Kafka Topic to be deleted. type TopicDeleteWaiter struct { + Context context.Context Client *aiven.Client ProjectName string ServiceName string @@ -569,7 +573,7 @@ type TopicDeleteWaiter struct { // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. func (w *TopicDeleteWaiter) RefreshFunc() resource.StateRefreshFunc { return func() (interface{}, string, error) { - err := w.Client.KafkaTopics.Delete(w.ProjectName, w.ServiceName, w.TopicName) + err := w.Client.KafkaTopics.Delete(w.Context, w.ProjectName, w.ServiceName, w.TopicName) if err != nil { if !aiven.IsNotFound(err) { return nil, "REMOVING", nil diff --git a/internal/sdkprovider/service/kafkatopic/kafka_topic_cache.go b/internal/sdkprovider/service/kafkatopic/kafka_topic_cache.go index e2465684e..0c724e2ec 100644 --- a/internal/sdkprovider/service/kafkatopic/kafka_topic_cache.go +++ b/internal/sdkprovider/service/kafkatopic/kafka_topic_cache.go @@ -4,7 +4,7 @@ import ( "log" "sync" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "golang.org/x/exp/slices" ) diff --git a/internal/sdkprovider/service/kafkatopic/kafka_topic_cache_test.go b/internal/sdkprovider/service/kafkatopic/kafka_topic_cache_test.go index 822506221..c21b03040 100644 --- a/internal/sdkprovider/service/kafkatopic/kafka_topic_cache_test.go +++ b/internal/sdkprovider/service/kafkatopic/kafka_topic_cache_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" ) func TestTopicCache_LoadByProjectAndServiceName(t1 *testing.T) { diff --git a/internal/sdkprovider/service/kafkatopic/kafka_topic_create.go b/internal/sdkprovider/service/kafkatopic/kafka_topic_create.go index 21f21e71b..429885bec 100644 --- a/internal/sdkprovider/service/kafkatopic/kafka_topic_create.go +++ b/internal/sdkprovider/service/kafkatopic/kafka_topic_create.go @@ -1,10 +1,11 @@ package kafkatopic import ( + "context" "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -13,6 +14,7 @@ import ( // that prevent creating the topics like all brokers not being online. This // allows retrying the operation until failing it. type kafkaTopicCreateWaiter struct { + Context context.Context Client *aiven.Client Project string ServiceName string @@ -26,6 +28,7 @@ func (w *kafkaTopicCreateWaiter) RefreshFunc() resource.StateRefreshFunc { // Assumes it exists, should prove it doesn't by getting no error return func() (interface{}, string, error) { err := w.Client.KafkaTopics.Create( + w.Context, w.Project, w.ServiceName, w.CreateRequest, diff --git a/internal/sdkprovider/service/kafkatopic/kafka_topic_test.go b/internal/sdkprovider/service/kafkatopic/kafka_topic_test.go index 4c79c7578..6a0d90285 100644 --- a/internal/sdkprovider/service/kafkatopic/kafka_topic_test.go +++ b/internal/sdkprovider/service/kafkatopic/kafka_topic_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -288,6 +288,8 @@ func testAccCheckAivenKafkaTopicAttributes(n string) resource.TestCheckFunc { func testAccCheckAivenKafkaTopicResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each kafka topic is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_kafka_topic" { @@ -299,7 +301,7 @@ func testAccCheckAivenKafkaTopicResourceDestroy(s *terraform.State) error { return err } - _, err = c.Services.Get(project, serviceName) + _, err = c.Services.Get(ctx, project, serviceName) if err != nil { if aiven.IsNotFound(err) { return nil @@ -307,7 +309,7 @@ func testAccCheckAivenKafkaTopicResourceDestroy(s *terraform.State) error { return err } - t, err := c.KafkaTopics.Get(project, serviceName, topicName) + t, err := c.KafkaTopics.Get(ctx, project, serviceName, topicName) if err != nil { if aiven.IsNotFound(err) { return nil @@ -379,12 +381,14 @@ func TestAccAivenKafkaTopic_recreate_missing(t *testing.T) { PreConfig: func() { client := acc.GetTestAivenClient() + ctx := context.Background() + // deletes - err := client.KafkaTopics.Delete(project, kafkaName, topicName) + err := client.KafkaTopics.Delete(ctx, project, kafkaName, topicName) assert.NoError(t, err) // Makes sure topic does not exist - tc, err := client.KafkaTopics.Get(project, kafkaName, topicName) + tc, err := client.KafkaTopics.Get(ctx, project, kafkaName, topicName) assert.Nil(t, tc) assert.True(t, aiven.IsNotFound(err)) @@ -410,7 +414,9 @@ func TestAccAivenKafkaTopic_recreate_missing(t *testing.T) { context.Background(), time.Minute, func() *retry.RetryError { - tc, err := client.KafkaTopics.Get(project, kafkaName, topicName) + ctx := context.Background() + + tc, err := client.KafkaTopics.Get(ctx, project, kafkaName, topicName) if err != nil { return &retry.RetryError{ Err: err, diff --git a/internal/sdkprovider/service/kafkatopic/kafka_topic_wait.go b/internal/sdkprovider/service/kafkatopic/kafka_topic_wait.go index 69cf055c1..7ce0981e5 100644 --- a/internal/sdkprovider/service/kafkatopic/kafka_topic_wait.go +++ b/internal/sdkprovider/service/kafkatopic/kafka_topic_wait.go @@ -1,11 +1,12 @@ package kafkatopic import ( + "context" "fmt" "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "golang.org/x/exp/slices" "golang.org/x/sync/semaphore" @@ -14,6 +15,7 @@ import ( // kafkaTopicAvailabilityWaiter is used to refresh the Aiven Kafka Topic endpoints when // provisioning. type kafkaTopicAvailabilityWaiter struct { + Context context.Context Client *aiven.Client Project string ServiceName string @@ -22,11 +24,18 @@ type kafkaTopicAvailabilityWaiter struct { var kafkaTopicAvailabilitySem = semaphore.NewWeighted(1) -func newKafkaTopicAvailabilityWaiter(client *aiven.Client, project, serviceName, topicName string) (*kafkaTopicAvailabilityWaiter, error) { +func newKafkaTopicAvailabilityWaiter( + ctx context.Context, + client *aiven.Client, + project string, + serviceName string, + topicName string, +) (*kafkaTopicAvailabilityWaiter, error) { if len(project)*len(serviceName)*len(topicName) == 0 { return nil, fmt.Errorf("return invalid input: project=%q, serviceName=%q, topicName=%q", project, serviceName, topicName) } return &kafkaTopicAvailabilityWaiter{ + Context: ctx, Client: client, Project: project, ServiceName: serviceName, @@ -84,7 +93,7 @@ func (w *kafkaTopicAvailabilityWaiter) refresh() error { } log.Printf("[DEBUG] kakfa topic queue : %+v", queue) - v2Topics, err := w.Client.KafkaTopics.V2List(w.Project, w.ServiceName, queue) + v2Topics, err := w.Client.KafkaTopics.V2List(w.Context, w.Project, w.ServiceName, queue) if err != nil { // V2 Kafka Topic endpoint retrieves 404 when one or more topics in the batch // do not exist but does not say which ones are missing. Therefore, we need to @@ -92,7 +101,7 @@ func (w *kafkaTopicAvailabilityWaiter) refresh() error { if aiven.IsNotFound(err) { log.Printf("[DEBUG] v2 list 404 error, queue : %+v, error: %s", queue, err) - list, err := w.Client.KafkaTopics.List(w.Project, w.ServiceName) + list, err := w.Client.KafkaTopics.List(w.Context, w.Project, w.ServiceName) if err != nil { return fmt.Errorf("error calling v1 list for %s/%s: %w", w.Project, w.ServiceName, err) } diff --git a/internal/sdkprovider/service/m3db/m3db_user_test.go b/internal/sdkprovider/service/m3db/m3db_user_test.go index d2de81df3..00ed62793 100644 --- a/internal/sdkprovider/service/m3db/m3db_user_test.go +++ b/internal/sdkprovider/service/m3db/m3db_user_test.go @@ -1,11 +1,12 @@ package m3db_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -40,6 +41,8 @@ func TestAccAivenM3DBUser_basic(t *testing.T) { func testAccCheckAivenM3DBUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_m3db_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_m3db_user" { @@ -51,7 +54,7 @@ func testAccCheckAivenM3DBUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/mysql/mysql_database.go b/internal/sdkprovider/service/mysql/mysql_database.go index db9552652..433fbe7da 100644 --- a/internal/sdkprovider/service/mysql/mysql_database.go +++ b/internal/sdkprovider/service/mysql/mysql_database.go @@ -3,7 +3,7 @@ package mysql import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -51,6 +51,7 @@ func resourceMySQLDatabaseCreate(ctx context.Context, d *schema.ResourceData, m serviceName := d.Get("service_name").(string) databaseName := d.Get("database_name").(string) _, err := client.Databases.Create( + ctx, projectName, serviceName, aiven.CreateDatabaseRequest{ @@ -72,7 +73,7 @@ func resourceMySQLDatabaseUpdate(ctx context.Context, d *schema.ResourceData, m return resourceMySQLDatabaseRead(ctx, d, m) } -func resourceMySQLDatabaseRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceMySQLDatabaseRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, databaseName, err := schemautil.SplitResourceID3(d.Id()) @@ -80,7 +81,7 @@ func resourceMySQLDatabaseRead(_ context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - database, err := client.Databases.Get(projectName, serviceName, databaseName) + database, err := client.Databases.Get(ctx, projectName, serviceName, databaseName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } diff --git a/internal/sdkprovider/service/mysql/mysql_database_data_source.go b/internal/sdkprovider/service/mysql/mysql_database_data_source.go index 70caf9e35..f304b96d2 100644 --- a/internal/sdkprovider/service/mysql/mysql_database_data_source.go +++ b/internal/sdkprovider/service/mysql/mysql_database_data_source.go @@ -3,7 +3,7 @@ package mysql import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceDatabaseRead(ctx context.Context, d *schema.ResourceData, m inter serviceName := d.Get("service_name").(string) databaseName := d.Get("database_name").(string) - databases, err := client.Databases.List(projectName, serviceName) + databases, err := client.Databases.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/mysql/mysql_database_test.go b/internal/sdkprovider/service/mysql/mysql_database_test.go index 5ed5b15d5..e6d4360e7 100644 --- a/internal/sdkprovider/service/mysql/mysql_database_test.go +++ b/internal/sdkprovider/service/mysql/mysql_database_test.go @@ -1,13 +1,14 @@ package mysql_test import ( + "context" "errors" "fmt" "os" "strings" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -89,6 +90,8 @@ func TestAccAivenMySQLDatabase_basic(t *testing.T) { func testAccCheckAivenMySQLDatabaseResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each database is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_mysql_database" { @@ -100,7 +103,7 @@ func testAccCheckAivenMySQLDatabaseResourceDestroy(s *terraform.State) error { return err } - db, err := c.Databases.Get(projectName, serviceName, databaseName) + db, err := c.Databases.Get(ctx, projectName, serviceName, databaseName) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/mysql/mysql_user.go b/internal/sdkprovider/service/mysql/mysql_user.go index d5f9faa0e..bab8ab3ae 100644 --- a/internal/sdkprovider/service/mysql/mysql_user.go +++ b/internal/sdkprovider/service/mysql/mysql_user.go @@ -3,7 +3,7 @@ package mysql import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -82,6 +82,7 @@ func resourceMySQLUserCreate(ctx context.Context, d *schema.ResourceData, m inte serviceName := d.Get("service_name").(string) username := d.Get("username").(string) _, err := client.ServiceUsers.Create( + ctx, projectName, serviceName, aiven.CreateServiceUserRequest{ @@ -94,7 +95,7 @@ func resourceMySQLUserCreate(ctx context.Context, d *schema.ResourceData, m inte } if _, ok := d.GetOk("password"); ok { - _, err := client.ServiceUsers.Update(projectName, serviceName, username, + _, err := client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ NewPassword: schemautil.OptionalStringPointer(d, "password"), }) @@ -116,7 +117,7 @@ func resourceMySQLUserUpdate(ctx context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - _, err = client.ServiceUsers.Update(projectName, serviceName, username, + _, err = client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ Authentication: schemautil.OptionalStringPointer(d, "authentication"), NewPassword: schemautil.OptionalStringPointer(d, "password"), diff --git a/internal/sdkprovider/service/mysql/mysql_user_test.go b/internal/sdkprovider/service/mysql/mysql_user_test.go index 6c8ac4616..e1fdd68ab 100644 --- a/internal/sdkprovider/service/mysql/mysql_user_test.go +++ b/internal/sdkprovider/service/mysql/mysql_user_test.go @@ -1,11 +1,12 @@ package mysql_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -40,6 +41,8 @@ func TestAccAivenMySQLUser_basic(t *testing.T) { func testAccCheckAivenMySQLUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_mysql_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_mysql_user" { @@ -51,7 +54,7 @@ func testAccCheckAivenMySQLUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/opensearch/common.go b/internal/sdkprovider/service/opensearch/common.go index 08179ffd0..f4788e841 100644 --- a/internal/sdkprovider/service/opensearch/common.go +++ b/internal/sdkprovider/service/opensearch/common.go @@ -1,9 +1,10 @@ package opensearch import ( + "context" "sync" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" ) var ( @@ -14,11 +15,17 @@ var ( // GETs the remote config, applies the modifiers and PUTs it again // The Config that is passed to the modifiers is guaranteed to be not nil -func resourceOpenSearchACLModifyRemoteConfig(project, serviceName string, client *aiven.Client, modifiers ...func(*aiven.ElasticSearchACLConfig)) error { +func resourceOpenSearchACLModifyRemoteConfig( + ctx context.Context, + project string, + serviceName string, + client *aiven.Client, + modifiers ...func(*aiven.ElasticSearchACLConfig), +) error { resourceOpenSearchACLModifierMutex.Lock() defer resourceOpenSearchACLModifierMutex.Unlock() - r, err := client.ElasticsearchACLs.Get(project, serviceName) + r, err := client.ElasticsearchACLs.Get(ctx, project, serviceName) if err != nil { return err } @@ -29,6 +36,7 @@ func resourceOpenSearchACLModifyRemoteConfig(project, serviceName string, client } _, err = client.ElasticsearchACLs.Update( + ctx, project, serviceName, aiven.ElasticsearchACLRequest{ElasticSearchACLConfig: config}) @@ -40,20 +48,30 @@ func resourceOpenSearchACLModifyRemoteConfig(project, serviceName string, client // some modifiers -func resourceElasticsearchACLModifierUpdateACLRule(username, index, permission string) func(*aiven.ElasticSearchACLConfig) { +func resourceElasticsearchACLModifierUpdateACLRule( + ctx context.Context, + username string, + index string, + permission string, +) func(*aiven.ElasticSearchACLConfig) { return func(cfg *aiven.ElasticSearchACLConfig) { cfg.Add(resourceOpenSearchACLRuleMkAivenACL(username, index, permission)) // delete the old acl if it's there if prevPerm, ok := resourceElasticsearchACLRuleGetPermissionFromACLResponse(*cfg, username, index); ok && prevPerm != permission { - cfg.Delete(resourceOpenSearchACLRuleMkAivenACL(username, index, prevPerm)) + cfg.Delete(ctx, resourceOpenSearchACLRuleMkAivenACL(username, index, prevPerm)) } } } -func resourceElasticsearchACLModifierDeleteACLRule(username, index, permission string) func(*aiven.ElasticSearchACLConfig) { +func resourceElasticsearchACLModifierDeleteACLRule( + ctx context.Context, + username string, + index string, + permission string, +) func(*aiven.ElasticSearchACLConfig) { return func(cfg *aiven.ElasticSearchACLConfig) { - cfg.Delete(resourceOpenSearchACLRuleMkAivenACL(username, index, permission)) + cfg.Delete(ctx, resourceOpenSearchACLRuleMkAivenACL(username, index, permission)) } } diff --git a/internal/sdkprovider/service/opensearch/opensearch_acl_config.go b/internal/sdkprovider/service/opensearch/opensearch_acl_config.go index d532b712a..304eb6fc6 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_acl_config.go +++ b/internal/sdkprovider/service/opensearch/opensearch_acl_config.go @@ -4,7 +4,7 @@ package opensearch import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -45,7 +45,7 @@ func ResourceOpenSearchACLConfig() *schema.Resource { } } -func resourceOpenSearchACLConfigRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOpenSearchACLConfigRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, err := schemautil.SplitResourceID2(d.Id()) @@ -53,7 +53,7 @@ func resourceOpenSearchACLConfigRead(_ context.Context, d *schema.ResourceData, return diag.FromErr(err) } - r, err := client.ElasticsearchACLs.Get(project, serviceName) + r, err := client.ElasticsearchACLs.Get(ctx, project, serviceName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -80,7 +80,7 @@ func resourceOpenSearchACLConfigUpdate(ctx context.Context, d *schema.ResourceDa serviceName := d.Get("service_name").(string) modifier := resourceElasticsearchACLModifierToggleConfigFields(d.Get("enabled").(bool), d.Get("extended_acl").(bool)) - err := resourceOpenSearchACLModifyRemoteConfig(project, serviceName, client, modifier) + err := resourceOpenSearchACLModifyRemoteConfig(ctx, project, serviceName, client, modifier) if err != nil { return diag.FromErr(err) } @@ -90,14 +90,14 @@ func resourceOpenSearchACLConfigUpdate(ctx context.Context, d *schema.ResourceDa return resourceOpenSearchACLConfigRead(ctx, d, m) } -func resourceOpenSearchACLConfigDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOpenSearchACLConfigDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project := d.Get("project").(string) serviceName := d.Get("service_name").(string) modifier := resourceElasticsearchACLModifierToggleConfigFields(false, false) - err := resourceOpenSearchACLModifyRemoteConfig(project, serviceName, client, modifier) + err := resourceOpenSearchACLModifyRemoteConfig(ctx, project, serviceName, client, modifier) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/opensearch/opensearch_acl_config_data_source.go b/internal/sdkprovider/service/opensearch/opensearch_acl_config_data_source.go index 8724b8429..587fb2ddf 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_acl_config_data_source.go +++ b/internal/sdkprovider/service/opensearch/opensearch_acl_config_data_source.go @@ -3,7 +3,7 @@ package opensearch import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -24,7 +24,7 @@ func datasourceOpenSearchACLConfigRead(ctx context.Context, d *schema.ResourceDa projectName := d.Get("project").(string) serviceName := d.Get("service_name").(string) - acl, err := client.ElasticsearchACLs.Get(projectName, serviceName) + acl, err := client.ElasticsearchACLs.Get(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/opensearch/opensearch_acl_config_test.go b/internal/sdkprovider/service/opensearch/opensearch_acl_config_test.go index 4479fdbf3..0b2130773 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_acl_config_test.go +++ b/internal/sdkprovider/service/opensearch/opensearch_acl_config_test.go @@ -1,11 +1,12 @@ package opensearch_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -68,6 +69,8 @@ resource "aiven_opensearch_acl_config" "foo" { func testAccCheckAivenOpenSearchACLConfigResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each OS ACL Config is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_opensearch_acl_config" { @@ -79,7 +82,7 @@ func testAccCheckAivenOpenSearchACLConfigResourceDestroy(s *terraform.State) err return err } - r, err := c.ElasticsearchACLs.Get(projectName, serviceName) + r, err := c.ElasticsearchACLs.Get(ctx, projectName, serviceName) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/opensearch/opensearch_acl_rule.go b/internal/sdkprovider/service/opensearch/opensearch_acl_rule.go index 5caa40af4..9eadc54ef 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_acl_rule.go +++ b/internal/sdkprovider/service/opensearch/opensearch_acl_rule.go @@ -3,7 +3,7 @@ package opensearch import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -67,7 +67,7 @@ func resourceElasticsearchACLRuleGetPermissionFromACLResponse(cfg aiven.ElasticS return "", false } -func resourceOpenSearchACLRuleRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOpenSearchACLRuleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, username, index, err := schemautil.SplitResourceID4(d.Id()) @@ -75,7 +75,7 @@ func resourceOpenSearchACLRuleRead(_ context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - r, err := client.ElasticsearchACLs.Get(project, serviceName) + r, err := client.ElasticsearchACLs.Get(ctx, project, serviceName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -124,8 +124,8 @@ func resourceOpenSearchACLRuleUpdate(ctx context.Context, d *schema.ResourceData index := d.Get("index").(string) permission := d.Get("permission").(string) - modifier := resourceElasticsearchACLModifierUpdateACLRule(username, index, permission) - err := resourceOpenSearchACLModifyRemoteConfig(project, serviceName, client, modifier) + modifier := resourceElasticsearchACLModifierUpdateACLRule(ctx, username, index, permission) + err := resourceOpenSearchACLModifyRemoteConfig(ctx, project, serviceName, client, modifier) if err != nil { return diag.FromErr(err) } @@ -135,7 +135,7 @@ func resourceOpenSearchACLRuleUpdate(ctx context.Context, d *schema.ResourceData return resourceOpenSearchACLRuleRead(ctx, d, m) } -func resourceOpenSearchACLRuleDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOpenSearchACLRuleDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project := d.Get("project").(string) @@ -144,8 +144,8 @@ func resourceOpenSearchACLRuleDelete(_ context.Context, d *schema.ResourceData, index := d.Get("index").(string) permission := d.Get("permission").(string) - modifier := resourceElasticsearchACLModifierDeleteACLRule(username, index, permission) - err := resourceOpenSearchACLModifyRemoteConfig(project, serviceName, client, modifier) + modifier := resourceElasticsearchACLModifierDeleteACLRule(ctx, username, index, permission) + err := resourceOpenSearchACLModifyRemoteConfig(ctx, project, serviceName, client, modifier) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/opensearch/opensearch_acl_rule_data_source.go b/internal/sdkprovider/service/opensearch/opensearch_acl_rule_data_source.go index da3baec53..e8f87d0cd 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_acl_rule_data_source.go +++ b/internal/sdkprovider/service/opensearch/opensearch_acl_rule_data_source.go @@ -3,7 +3,7 @@ package opensearch import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceOpenSearchACLRuleRead(ctx context.Context, d *schema.ResourceData username := d.Get("username").(string) index := d.Get("index").(string) - r, err := client.ElasticsearchACLs.Get(projectName, serviceName) + r, err := client.ElasticsearchACLs.Get(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/opensearch/opensearch_acl_rule_test.go b/internal/sdkprovider/service/opensearch/opensearch_acl_rule_test.go index c7898f4e7..77b6873bd 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_acl_rule_test.go +++ b/internal/sdkprovider/service/opensearch/opensearch_acl_rule_test.go @@ -1,11 +1,12 @@ package opensearch_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -77,6 +78,8 @@ resource "aiven_opensearch_acl_rule" "foo" { func testAccCheckAivenOpenSearchACLRuleResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each ES ACL is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_opensearch_acl_rule" { @@ -88,7 +91,7 @@ func testAccCheckAivenOpenSearchACLRuleResourceDestroy(s *terraform.State) error return err } - r, err := c.ElasticsearchACLs.Get(projectName, serviceName) + r, err := c.ElasticsearchACLs.Get(ctx, projectName, serviceName) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config.go b/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config.go index e1723b4a9..8b38c7a2f 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config.go +++ b/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config.go @@ -4,7 +4,7 @@ package opensearch import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -70,6 +70,7 @@ func resourceOpenSearchSecurityPluginConfigCreate( serviceName := d.Get("service_name").(string) if _, err := client.OpenSearchSecurityPluginHandler.Enable( + ctx, project, serviceName, aiven.OpenSearchSecurityPluginEnableRequest{ @@ -87,7 +88,7 @@ func resourceOpenSearchSecurityPluginConfigCreate( // resourceOpenSearchSecurityPluginConfigRead reads the OpenSearch Security Plugin config from an existing OpenSearch // service. func resourceOpenSearchSecurityPluginConfigRead( - _ context.Context, + ctx context.Context, d *schema.ResourceData, m any, ) diag.Diagnostics { @@ -98,7 +99,7 @@ func resourceOpenSearchSecurityPluginConfigRead( return diag.FromErr(err) } - r, err := client.OpenSearchSecurityPluginHandler.Get(project, serviceName) + r, err := client.OpenSearchSecurityPluginHandler.Get(ctx, project, serviceName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -142,6 +143,7 @@ func resourceOpenSearchSecurityPluginConfigUpdate( oldAdminPassword, newAdminPassword := d.GetChange("admin_password") if _, err := client.OpenSearchSecurityPluginHandler.UpdatePassword( + ctx, project, serviceName, aiven.OpenSearchSecurityPluginUpdatePasswordRequest{ diff --git a/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config_data_source.go b/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config_data_source.go index 8e250defa..44684a85a 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config_data_source.go +++ b/internal/sdkprovider/service/opensearch/opensearch_security_plugin_config_data_source.go @@ -4,7 +4,7 @@ package opensearch import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -32,7 +32,7 @@ func datasourceOpenSearchSecurityPluginConfigRead(ctx context.Context, d *schema serviceName := d.Get("service_name").(string) - if _, err := client.OpenSearchSecurityPluginHandler.Get(projectName, serviceName); err != nil { + if _, err := client.OpenSearchSecurityPluginHandler.Get(ctx, projectName, serviceName); err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/opensearch/opensearch_user.go b/internal/sdkprovider/service/opensearch/opensearch_user.go index b2998b608..c9e334f87 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_user.go +++ b/internal/sdkprovider/service/opensearch/opensearch_user.go @@ -6,7 +6,7 @@ import ( "errors" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -65,13 +65,13 @@ func ResourceOpenSearchUser() *schema.Resource { // detourSecurityPluginEnabledCheck checks if the OpenSearch Security Plugin is enabled for the OpenSearch service. // If it is enabled, it returns an error, and the resource is not allowed to be created, read or updated. -func detourSecurityPluginEnabledCheck(d *schema.ResourceData, m any) error { +func detourSecurityPluginEnabledCheck(ctx context.Context, d *schema.ResourceData, m any) error { client := m.(*aiven.Client) project := d.Get("project").(string) serviceName := d.Get("service_name").(string) - r, err := client.OpenSearchSecurityPluginHandler.Get(project, serviceName) + r, err := client.OpenSearchSecurityPluginHandler.Get(ctx, project, serviceName) if err == nil && r.SecurityPluginAdminEnabled { return errors.New("when the OpenSearch Security Plugin is enabled, OpenSearch users are being " + "managed by it; delete the aiven_opensearch_user resource(s), and manage the users via the " + @@ -84,7 +84,7 @@ func detourSecurityPluginEnabledCheck(d *schema.ResourceData, m any) error { // resourceOpenSearchUserCreate creates a OpenSearch User. func resourceOpenSearchUserCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { - if err := detourSecurityPluginEnabledCheck(d, m); err != nil { + if err := detourSecurityPluginEnabledCheck(ctx, d, m); err != nil { return diag.FromErr(err) } @@ -111,7 +111,7 @@ func resourceOpenSearchUserRead(ctx context.Context, d *schema.ResourceData, m a } } - if err := detourSecurityPluginEnabledCheck(d, m); err != nil && + if err := detourSecurityPluginEnabledCheck(ctx, d, m); err != nil && strings.Contains(strings.ToLower(e.Summary), errOpenSearchConfiguredDirectly) { return schemautil.ErrorToDiagWarning(err) } @@ -121,7 +121,7 @@ func resourceOpenSearchUserRead(ctx context.Context, d *schema.ResourceData, m a // resourceOpenSearchUserUpdate updates a OpenSearch User. func resourceOpenSearchUserUpdate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { - if err := detourSecurityPluginEnabledCheck(d, m); err != nil { + if err := detourSecurityPluginEnabledCheck(ctx, d, m); err != nil { return diag.FromErr(err) } @@ -129,7 +129,7 @@ func resourceOpenSearchUserUpdate(ctx context.Context, d *schema.ResourceData, m } // resourceOpenSearchUserDelete deletes a OpenSearch User. -func resourceOpenSearchUserDelete(_ context.Context, d *schema.ResourceData, m any) diag.Diagnostics { +func resourceOpenSearchUserDelete(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, username, err := schemautil.SplitResourceID3(d.Id()) @@ -137,7 +137,7 @@ func resourceOpenSearchUserDelete(_ context.Context, d *schema.ResourceData, m a return diag.FromErr(err) } - err = client.ServiceUsers.Delete(projectName, serviceName, username) + err = client.ServiceUsers.Delete(ctx, projectName, serviceName, username) if err != nil && !aiven.IsNotFound(err) { var e aiven.Error diff --git a/internal/sdkprovider/service/opensearch/opensearch_user_test.go b/internal/sdkprovider/service/opensearch/opensearch_user_test.go index faae8b5ed..87da3b0c4 100644 --- a/internal/sdkprovider/service/opensearch/opensearch_user_test.go +++ b/internal/sdkprovider/service/opensearch/opensearch_user_test.go @@ -1,11 +1,12 @@ package opensearch_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -40,6 +41,8 @@ func TestAccAivenOpenSearchUser_basic(t *testing.T) { func testAccCheckAivenOpenSearchUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_opensearch_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_opensearch_user" { @@ -51,7 +54,7 @@ func testAccCheckAivenOpenSearchUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/organization/organization_user.go b/internal/sdkprovider/service/organization/organization_user.go index 058305626..ab9e1d8c8 100644 --- a/internal/sdkprovider/service/organization/organization_user.go +++ b/internal/sdkprovider/service/organization/organization_user.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -72,7 +72,7 @@ func resourceOrganizationUserCreate(ctx context.Context, d *schema.ResourceData, organizationID := d.Get("organization_id").(string) userEmail := d.Get("user_email").(string) - err := client.OrganizationUserInvitations.Invite(organizationID, aiven.OrganizationUserInvitationAddRequest{ + err := client.OrganizationUserInvitations.Invite(ctx, organizationID, aiven.OrganizationUserInvitationAddRequest{ UserEmail: userEmail, }) if err != nil { @@ -93,7 +93,7 @@ func resourceOrganizationUserRead(ctx context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - r, err := client.OrganizationUserInvitations.List(organizationID) + r, err := client.OrganizationUserInvitations.List(ctx, organizationID) if err != nil { return diag.FromErr(err) } @@ -123,7 +123,7 @@ func resourceOrganizationUserRead(ctx context.Context, d *schema.ResourceData, m } if !found { - rm, err := client.OrganizationUser.List(organizationID) + rm, err := client.OrganizationUser.List(ctx, organizationID) if err != nil { return diag.FromErr(err) } @@ -164,7 +164,7 @@ func resourceOrganizationUserRead(ctx context.Context, d *schema.ResourceData, m return nil } -func resourceOrganizationUserDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOrganizationUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) organizationID, userEmail, err := schemautil.SplitResourceID2(d.Id()) @@ -175,7 +175,7 @@ func resourceOrganizationUserDelete(_ context.Context, d *schema.ResourceData, m found := true // delete organization user invitation - err = client.OrganizationUserInvitations.Delete(organizationID, userEmail) + err = client.OrganizationUserInvitations.Delete(ctx, organizationID, userEmail) if err != nil { if !aiven.IsNotFound(err) { return diag.FromErr(err) @@ -184,7 +184,7 @@ func resourceOrganizationUserDelete(_ context.Context, d *schema.ResourceData, m found = false } - r, err := client.OrganizationUser.List(organizationID) + r, err := client.OrganizationUser.List(ctx, organizationID) if err != nil { return diag.FromErr(err) } @@ -198,7 +198,7 @@ func resourceOrganizationUserDelete(_ context.Context, d *schema.ResourceData, m userInfo := u.UserInfo if userInfo.UserEmail == userEmail { - err = client.OrganizationUser.Delete(organizationID, u.UserID) + err = client.OrganizationUser.Delete(ctx, organizationID, u.UserID) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/organization/organization_user_group.go b/internal/sdkprovider/service/organization/organization_user_group.go index 286b50478..71319a9e2 100644 --- a/internal/sdkprovider/service/organization/organization_user_group.go +++ b/internal/sdkprovider/service/organization/organization_user_group.go @@ -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-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -62,6 +62,7 @@ func resourceOrganizationUserGroupCreate(ctx context.Context, d *schema.Resource orgID := d.Get("organization_id").(string) r, err := client.OrganizationUserGroups.Create( + ctx, orgID, aiven.OrganizationUserGroupRequest{ UserGroupName: d.Get("name").(string), @@ -77,7 +78,7 @@ func resourceOrganizationUserGroupCreate(ctx context.Context, d *schema.Resource return resourceOrganizationUserGroupRead(ctx, d, m) } -func resourceOrganizationUserGroupRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOrganizationUserGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) orgID, userGroupID, err := schemautil.SplitResourceID2(d.Id()) @@ -85,7 +86,7 @@ func resourceOrganizationUserGroupRead(_ context.Context, d *schema.ResourceData return diag.FromErr(err) } - r, err := client.OrganizationUserGroups.Get(orgID, userGroupID) + r, err := client.OrganizationUserGroups.Get(ctx, orgID, userGroupID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -114,7 +115,7 @@ func resourceOrganizationUserGroupUpdate(ctx context.Context, d *schema.Resource return diag.FromErr(err) } - _, err = client.OrganizationUserGroups.Update(orgID, userGroupID, aiven.OrganizationUserGroupRequest{ + _, err = client.OrganizationUserGroups.Update(ctx, orgID, userGroupID, aiven.OrganizationUserGroupRequest{ UserGroupName: d.Get("name").(string), Description: d.Get("description").(string), }) @@ -125,7 +126,7 @@ func resourceOrganizationUserGroupUpdate(ctx context.Context, d *schema.Resource return resourceOrganizationUserGroupRead(ctx, d, m) } -func resourceOrganizationUserGroupDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOrganizationUserGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) orgID, userGroupID, err := schemautil.SplitResourceID2(d.Id()) @@ -133,7 +134,7 @@ func resourceOrganizationUserGroupDelete(_ context.Context, d *schema.ResourceDa return diag.FromErr(err) } - if err = client.OrganizationUserGroups.Delete(orgID, userGroupID); err != nil && !aiven.IsNotFound(err) { + if err = client.OrganizationUserGroups.Delete(ctx, orgID, userGroupID); err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/organization/organization_user_group_data_source.go b/internal/sdkprovider/service/organization/organization_user_group_data_source.go index f5cc5bfe9..e582daee4 100644 --- a/internal/sdkprovider/service/organization/organization_user_group_data_source.go +++ b/internal/sdkprovider/service/organization/organization_user_group_data_source.go @@ -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-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceOrganizationUserGroupRead(ctx context.Context, d *schema.Resource name := d.Get("name").(string) client := m.(*aiven.Client) - list, err := client.OrganizationUserGroups.List(organizationID) + list, err := client.OrganizationUserGroups.List(ctx, organizationID) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/organization/organization_user_group_test.go b/internal/sdkprovider/service/organization/organization_user_group_test.go index 34bfc6cfe..9e87927a5 100644 --- a/internal/sdkprovider/service/organization/organization_user_group_test.go +++ b/internal/sdkprovider/service/organization/organization_user_group_test.go @@ -1,11 +1,12 @@ package organization_test import ( + "context" "fmt" "log" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -60,6 +61,8 @@ data "aiven_organization_user_group" "bar" { func testAccCheckAivenOrganizationUserGroupResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each organization user group is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_organization_user_group" { @@ -71,7 +74,7 @@ func testAccCheckAivenOrganizationUserGroupResourceDestroy(s *terraform.State) e return err } - r, err := c.OrganizationUserGroups.Get(orgID, userGroupID) + r, err := c.OrganizationUserGroups.Get(ctx, orgID, userGroupID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/organization/organization_user_test.go b/internal/sdkprovider/service/organization/organization_user_test.go index 31713ce5f..bd3812261 100644 --- a/internal/sdkprovider/service/organization/organization_user_test.go +++ b/internal/sdkprovider/service/organization/organization_user_test.go @@ -1,11 +1,12 @@ package organization_test import ( + "context" "fmt" "log" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -59,6 +60,8 @@ data "aiven_organization_user" "member" { func testAccCheckAivenOrganizationUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_organization_user" { continue @@ -69,7 +72,7 @@ func testAccCheckAivenOrganizationUserResourceDestroy(s *terraform.State) error return err } - r, err := c.Organization.Get(organizationID) + r, err := c.Organization.Get(ctx, organizationID) if err != nil { if err.(aiven.Error).Status != 404 { return err @@ -79,7 +82,7 @@ func testAccCheckAivenOrganizationUserResourceDestroy(s *terraform.State) error } if r.ID == organizationID { - ri, err := c.OrganizationUserInvitations.List(organizationID) + ri, err := c.OrganizationUserInvitations.List(ctx, organizationID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/organization/organizational_unit.go b/internal/sdkprovider/service/organization/organizational_unit.go index edf37764d..b0f78e9de 100644 --- a/internal/sdkprovider/service/organization/organizational_unit.go +++ b/internal/sdkprovider/service/organization/organizational_unit.go @@ -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-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -59,12 +59,13 @@ func resourceOrganizationalUnitCreate(ctx context.Context, d *schema.ResourceDat client := m.(*aiven.Client) name := d.Get("name").(string) - parentID, err := schemautil.NormalizeOrganizationID(client, d.Get("parent_id").(string)) + parentID, err := schemautil.NormalizeOrganizationID(ctx, client, d.Get("parent_id").(string)) if err != nil { return diag.FromErr(err) } r, err := client.Accounts.Create( + ctx, aiven.Account{ Name: name, ParentAccountId: parentID, @@ -79,16 +80,17 @@ func resourceOrganizationalUnitCreate(ctx context.Context, d *schema.ResourceDat return resourceOrganizationalUnitRead(ctx, d, m) } -func resourceOrganizationalUnitRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOrganizationalUnitRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - r, err := client.Accounts.Get(d.Id()) + r, err := client.Accounts.Get(ctx, d.Id()) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } if stateID, _ := d.GetOk("parent_id"); true { idToSet, err := schemautil.DetermineMixedOrganizationConstraintIDToStore( + ctx, client, stateID.(string), r.Account.ParentAccountId, @@ -121,7 +123,7 @@ func resourceOrganizationalUnitRead(_ context.Context, d *schema.ResourceData, m func resourceOrganizationalUnitUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - r, err := client.Accounts.Update(d.Id(), aiven.Account{ + r, err := client.Accounts.Update(ctx, d.Id(), aiven.Account{ Name: d.Get("name").(string), }) if err != nil { @@ -133,10 +135,10 @@ func resourceOrganizationalUnitUpdate(ctx context.Context, d *schema.ResourceDat return resourceOrganizationalUnitRead(ctx, d, m) } -func resourceOrganizationalUnitDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceOrganizationalUnitDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - if err := client.Accounts.Delete(d.Id()); err != nil && !aiven.IsNotFound(err) { + if err := client.Accounts.Delete(ctx, d.Id()); err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/organization/organizational_unit_data_source.go b/internal/sdkprovider/service/organization/organizational_unit_data_source.go index 6580736f0..88c868551 100644 --- a/internal/sdkprovider/service/organization/organizational_unit_data_source.go +++ b/internal/sdkprovider/service/organization/organizational_unit_data_source.go @@ -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-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -24,7 +24,7 @@ func datasourceOrganizationalUnitRead(ctx context.Context, d *schema.ResourceDat name := d.Get("name").(string) - r, err := client.Accounts.List() + r, err := client.Accounts.List(ctx) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/pg/pg.go b/internal/sdkprovider/service/pg/pg.go index 56884eccc..dad48acc5 100644 --- a/internal/sdkprovider/service/pg/pg.go +++ b/internal/sdkprovider/service/pg/pg.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -141,13 +141,13 @@ func resourceServicePGUpdate(ctx context.Context, d *schema.ResourceData, m inte } if userConfig["pg_version"] != nil { - s, err := client.Services.Get(projectName, serviceName) + s, err := client.Services.Get(ctx, projectName, serviceName) if err != nil { return diag.Errorf("cannot get a common: %s", err) } if userConfig["pg_version"].(string) != s.UserConfig["pg_version"].(string) { - t, err := client.ServiceTask.Create(projectName, serviceName, aiven.ServiceTaskRequest{ + t, err := client.ServiceTask.Create(ctx, projectName, serviceName, aiven.ServiceTaskRequest{ TargetVersion: userConfig["pg_version"].(string), TaskType: "upgrade_check", }) @@ -156,6 +156,7 @@ func resourceServicePGUpdate(ctx context.Context, d *schema.ResourceData, m inte } w := &ServiceTaskWaiter{ + Context: ctx, Client: m.(*aiven.Client), Project: projectName, ServiceName: serviceName, @@ -185,6 +186,7 @@ func resourceServicePGUpdate(ctx context.Context, d *schema.ResourceData, m inte // ServiceTaskWaiter is used to refresh the Aiven Service Task endpoints when // provisioning. type ServiceTaskWaiter struct { + Context context.Context Client *aiven.Client Project string ServiceName string @@ -196,6 +198,7 @@ type ServiceTaskWaiter struct { func (w *ServiceTaskWaiter) RefreshFunc() resource.StateRefreshFunc { return func() (interface{}, string, error) { t, err := w.Client.ServiceTask.Get( + w.Context, w.Project, w.ServiceName, w.TaskID, diff --git a/internal/sdkprovider/service/pg/pg_database.go b/internal/sdkprovider/service/pg/pg_database.go index e98a3fea0..bfc18f4ed 100644 --- a/internal/sdkprovider/service/pg/pg_database.go +++ b/internal/sdkprovider/service/pg/pg_database.go @@ -3,7 +3,7 @@ package pg import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -77,6 +77,7 @@ func resourcePGDatabaseCreate(ctx context.Context, d *schema.ResourceData, m int serviceName := d.Get("service_name").(string) databaseName := d.Get("database_name").(string) _, err := client.Databases.Create( + ctx, projectName, serviceName, aiven.CreateDatabaseRequest{ @@ -98,7 +99,7 @@ func resourcePGDatabaseUpdate(ctx context.Context, d *schema.ResourceData, m int return resourcePGDatabaseRead(ctx, d, m) } -func resourcePGDatabaseRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourcePGDatabaseRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, databaseName, err := schemautil.SplitResourceID3(d.Id()) @@ -106,7 +107,7 @@ func resourcePGDatabaseRead(_ context.Context, d *schema.ResourceData, m interfa return diag.FromErr(err) } - database, err := client.Databases.Get(projectName, serviceName, databaseName) + database, err := client.Databases.Get(ctx, projectName, serviceName, databaseName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } diff --git a/internal/sdkprovider/service/pg/pg_database_data_source.go b/internal/sdkprovider/service/pg/pg_database_data_source.go index 59becdc3c..568afa00f 100644 --- a/internal/sdkprovider/service/pg/pg_database_data_source.go +++ b/internal/sdkprovider/service/pg/pg_database_data_source.go @@ -3,7 +3,7 @@ package pg import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceDatabaseRead(ctx context.Context, d *schema.ResourceData, m inter serviceName := d.Get("service_name").(string) databaseName := d.Get("database_name").(string) - databases, err := client.Databases.List(projectName, serviceName) + databases, err := client.Databases.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/pg/pg_database_test.go b/internal/sdkprovider/service/pg/pg_database_test.go index cd21602b4..379893c4b 100644 --- a/internal/sdkprovider/service/pg/pg_database_test.go +++ b/internal/sdkprovider/service/pg/pg_database_test.go @@ -1,13 +1,14 @@ package pg_test import ( + "context" "errors" "fmt" "os" "strings" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -97,6 +98,8 @@ func TestAccAivenPGDatabase_basic(t *testing.T) { func testAccCheckAivenPGDatabaseResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each database is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_pg_database" { @@ -108,7 +111,7 @@ func testAccCheckAivenPGDatabaseResourceDestroy(s *terraform.State) error { return err } - db, err := c.Databases.Get(projectName, serviceName, databaseName) + db, err := c.Databases.Get(ctx, projectName, serviceName, databaseName) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/pg/pg_test.go b/internal/sdkprovider/service/pg/pg_test.go index 5296c85e3..6c966aae3 100644 --- a/internal/sdkprovider/service/pg/pg_test.go +++ b/internal/sdkprovider/service/pg/pg_test.go @@ -1,13 +1,14 @@ package pg_test import ( + "context" "fmt" "os" "regexp" "strings" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -949,7 +950,9 @@ func testAccCheckAivenServiceTerminationProtection(n string) resource.TestCheckF c := acc.GetTestAivenClient() - service, err := c.Services.Get(projectName, serviceName) + ctx := context.Background() + + service, err := c.Services.Get(ctx, projectName, serviceName) if err != nil { return fmt.Errorf("cannot get service %s err: %s", serviceName, err) } @@ -960,21 +963,26 @@ func testAccCheckAivenServiceTerminationProtection(n string) resource.TestCheckF // try to delete Aiven service with termination_protection enabled // should be an error from Aiven API - err = c.Services.Delete(projectName, serviceName) + err = c.Services.Delete(ctx, projectName, serviceName) if err == nil { return fmt.Errorf("termination_protection enabled should prevent from deletion of a service, deletion went OK") } // set service termination_protection to false to make Terraform Destroy plan work - _, err = c.Services.Update(projectName, service.Name, aiven.UpdateServiceRequest{ - Cloud: service.CloudName, - MaintenanceWindow: &service.MaintenanceWindow, - Plan: service.Plan, - ProjectVPCID: service.ProjectVPCID, - Powered: true, - TerminationProtection: false, - UserConfig: service.UserConfig, - }) + _, err = c.Services.Update( + ctx, + projectName, + service.Name, + aiven.UpdateServiceRequest{ + Cloud: service.CloudName, + MaintenanceWindow: &service.MaintenanceWindow, + Plan: service.Plan, + ProjectVPCID: service.ProjectVPCID, + Powered: true, + TerminationProtection: false, + UserConfig: service.UserConfig, + }, + ) if err != nil { return fmt.Errorf("unable to update Aiven service to set termination_protection=false err: %s", err) diff --git a/internal/sdkprovider/service/pg/pg_user.go b/internal/sdkprovider/service/pg/pg_user.go index 68b96d21b..6f127e880 100644 --- a/internal/sdkprovider/service/pg/pg_user.go +++ b/internal/sdkprovider/service/pg/pg_user.go @@ -3,7 +3,7 @@ package pg import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -84,6 +84,7 @@ func resourcePGUserCreate(ctx context.Context, d *schema.ResourceData, m interfa username := d.Get("username").(string) allowReplication := d.Get("pg_allow_replication").(bool) _, err := client.ServiceUsers.Create( + ctx, projectName, serviceName, aiven.CreateServiceUserRequest{ @@ -98,7 +99,7 @@ func resourcePGUserCreate(ctx context.Context, d *schema.ResourceData, m interfa } if _, ok := d.GetOk("password"); ok { - _, err := client.ServiceUsers.Update(projectName, serviceName, username, + _, err := client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ NewPassword: schemautil.OptionalStringPointer(d, "password"), }) @@ -120,7 +121,7 @@ func resourcePGUserUpdate(ctx context.Context, d *schema.ResourceData, m interfa return diag.FromErr(err) } - _, err = client.ServiceUsers.Update(projectName, serviceName, username, + _, err = client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ NewPassword: schemautil.OptionalStringPointer(d, "password"), }) @@ -131,7 +132,7 @@ func resourcePGUserUpdate(ctx context.Context, d *schema.ResourceData, m interfa return resourcePGUserRead(ctx, d, m) } -func resourcePGUserRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourcePGUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, username, err := schemautil.SplitResourceID3(d.Id()) @@ -139,7 +140,7 @@ func resourcePGUserRead(_ context.Context, d *schema.ResourceData, m interface{} return diag.FromErr(err) } - user, err := client.ServiceUsers.Get(projectName, serviceName, username) + user, err := client.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } diff --git a/internal/sdkprovider/service/pg/pg_user_data_source.go b/internal/sdkprovider/service/pg/pg_user_data_source.go index 37fe3a5fa..583b31ff4 100644 --- a/internal/sdkprovider/service/pg/pg_user_data_source.go +++ b/internal/sdkprovider/service/pg/pg_user_data_source.go @@ -3,7 +3,7 @@ package pg import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourcePGUserRead(ctx context.Context, d *schema.ResourceData, m interfa serviceName := d.Get("service_name").(string) userName := d.Get("username").(string) - list, err := client.ServiceUsers.List(projectName, serviceName) + list, err := client.ServiceUsers.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/pg/pg_user_test.go b/internal/sdkprovider/service/pg/pg_user_test.go index 58ef9b926..7bca1e2dd 100644 --- a/internal/sdkprovider/service/pg/pg_user_test.go +++ b/internal/sdkprovider/service/pg/pg_user_test.go @@ -1,11 +1,12 @@ package pg_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -96,7 +97,9 @@ func testAccCheckAivenPGUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + ctx := context.Background() + + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/project/billing_group.go b/internal/sdkprovider/service/project/billing_group.go index 9a4ea04b0..28dfac5dc 100644 --- a/internal/sdkprovider/service/project/billing_group.go +++ b/internal/sdkprovider/service/project/billing_group.go @@ -3,7 +3,7 @@ package project import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -133,7 +133,7 @@ func resourceBillingGroupCreate(ctx context.Context, d *schema.ResourceData, m i billingEmails = *emails } - cardID, err := getLongCardID(client, d.Get("card_id").(string)) + cardID, err := getLongCardID(ctx, client, d.Get("card_id").(string)) if err != nil { return diag.Errorf("Error getting long card id: %s", err) } @@ -154,14 +154,14 @@ func resourceBillingGroupCreate(ctx context.Context, d *schema.ResourceData, m i CopyFromBillingGroup: schemautil.OptionalStringPointer(d, "copy_from_billing_group"), } - ptrAccountID, err := accountIDPointer(client, d) + ptrAccountID, err := accountIDPointer(ctx, client, d) if err != nil { return diag.FromErr(err) } req.AccountId = ptrAccountID - bg, err := client.BillingGroup.Create(req) + bg, err := client.BillingGroup.Create(ctx, req) if err != nil { return diag.Errorf("cannot create billing group: %s", err) } @@ -171,10 +171,10 @@ func resourceBillingGroupCreate(ctx context.Context, d *schema.ResourceData, m i return resourceBillingGroupRead(ctx, d, m) } -func resourceBillingGroupRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceBillingGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - bg, err := client.BillingGroup.Get(d.Id()) + bg, err := client.BillingGroup.Get(ctx, d.Id()) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -186,7 +186,12 @@ func resourceBillingGroupRead(_ context.Context, d *schema.ResourceData, m inter accountID = *bg.AccountId } - idToSet, err := schemautil.DetermineMixedOrganizationConstraintIDToStore(client, stateID.(string), accountID) + idToSet, err := schemautil.DetermineMixedOrganizationConstraintIDToStore( + ctx, + client, + stateID.(string), + accountID, + ) if err != nil { return diag.FromErr(err) } @@ -247,7 +252,7 @@ func resourceBillingGroupUpdate(ctx context.Context, d *schema.ResourceData, m i billingEmails = *emails } - cardID, err := getLongCardID(client, d.Get("card_id").(string)) + cardID, err := getLongCardID(ctx, client, d.Get("card_id").(string)) if err != nil { return diag.Errorf("Error getting long card id: %s", err) } @@ -267,14 +272,14 @@ func resourceBillingGroupUpdate(ctx context.Context, d *schema.ResourceData, m i State: schemautil.OptionalStringPointer(d, "state"), } - ptrAccountID, err := accountIDPointer(client, d) + ptrAccountID, err := accountIDPointer(ctx, client, d) if err != nil { return diag.FromErr(err) } req.AccountId = ptrAccountID - bg, err := client.BillingGroup.Update(d.Id(), req) + bg, err := client.BillingGroup.Update(ctx, d.Id(), req) if err != nil { return diag.Errorf("cannot update billing group: %s", err) } @@ -284,10 +289,10 @@ func resourceBillingGroupUpdate(ctx context.Context, d *schema.ResourceData, m i return resourceBillingGroupRead(ctx, d, m) } -func resourceBillingGroupDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceBillingGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - err := client.BillingGroup.Delete(d.Id()) + err := client.BillingGroup.Delete(ctx, d.Id()) if err != nil && !aiven.IsNotFound(err) { return diag.Errorf("cannot delete a billing group: %s", err) } diff --git a/internal/sdkprovider/service/project/billing_group_test.go b/internal/sdkprovider/service/project/billing_group_test.go index 6ad8e6929..512844074 100644 --- a/internal/sdkprovider/service/project/billing_group_test.go +++ b/internal/sdkprovider/service/project/billing_group_test.go @@ -1,10 +1,11 @@ package project_test import ( + "context" "fmt" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -45,13 +46,15 @@ func TestAccAivenBillingGroup_basic(t *testing.T) { func testAccCheckAivenBillingGroupResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each billing group is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_billing_group" { continue } - db, err := c.BillingGroup.Get(rs.Primary.ID) + db, err := c.BillingGroup.Get(ctx, rs.Primary.ID) if err != nil && !aiven.IsNotFound(err) && err.(aiven.Error).Status != 500 { return fmt.Errorf("error getting a billing group by id: %w", err) } diff --git a/internal/sdkprovider/service/project/project.go b/internal/sdkprovider/service/project/project.go index d5b951451..ce96c27a5 100644 --- a/internal/sdkprovider/service/project/project.go +++ b/internal/sdkprovider/service/project/project.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -167,14 +167,14 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf Tags: schemautil.GetTagsFromSchema(d), } - ptrAccountID, err := accountIDPointer(client, d) + ptrAccountID, err := accountIDPointer(ctx, client, d) if err != nil { return diag.FromErr(err) } req.AccountId = ptrAccountID - _, err = client.Projects.Create(req) + _, err = client.Projects.Create(ctx, req) if err != nil { return diag.FromErr(err) } @@ -183,7 +183,7 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf // if billing_group is not set but copy_from_project is not empty, // copy billing group from source project if sourceProject, ok := d.GetOk("copy_from_project"); ok { - dia := resourceProjectCopyBillingGroupFromProject(client, sourceProject.(string), d) + dia := resourceProjectCopyBillingGroupFromProject(ctx, client, sourceProject.(string), d) if dia.HasError() { diag.FromErr(err) } @@ -196,14 +196,18 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf } func resourceProjectCopyBillingGroupFromProject( - client *aiven.Client, sourceProjectName string, d *schema.ResourceData) diag.Diagnostics { - list, err := client.BillingGroup.ListAll() + ctx context.Context, + client *aiven.Client, + sourceProjectName string, + d *schema.ResourceData, +) diag.Diagnostics { + list, err := client.BillingGroup.ListAll(ctx) if err != nil { return diag.FromErr(err) } for _, bg := range list { - projects, err := client.BillingGroup.GetProjects(bg.Id) + projects, err := client.BillingGroup.GetProjects(ctx, bg.Id) if err != nil { return diag.FromErr(err) } @@ -211,7 +215,7 @@ func resourceProjectCopyBillingGroupFromProject( for _, pr := range projects { if pr == sourceProjectName { log.Printf("[DEBUG] Source project `%s` has billing group `%s`", sourceProjectName, bg.Id) - return resourceProjectAssignToBillingGroup(sourceProjectName, bg.Id, client, d) + return resourceProjectAssignToBillingGroup(ctx, sourceProjectName, bg.Id, client, d) } } } @@ -221,15 +225,20 @@ func resourceProjectCopyBillingGroupFromProject( } func resourceProjectAssignToBillingGroup( - projectName, billingGroupID string, client *aiven.Client, d *schema.ResourceData) diag.Diagnostics { + ctx context.Context, + projectName string, + billingGroupID string, + client *aiven.Client, + d *schema.ResourceData, +) diag.Diagnostics { log.Printf("[DEBUG] Associating project `%s` with the billing group `%s`", projectName, billingGroupID) - _, err := client.BillingGroup.Get(billingGroupID) + _, err := client.BillingGroup.Get(ctx, billingGroupID) if err != nil { return diag.Errorf("cannot get a billing group by id: %s", err) } var isAlreadyAssigned bool - assignedProjects, err := client.BillingGroup.GetProjects(billingGroupID) + assignedProjects, err := client.BillingGroup.GetProjects(ctx, billingGroupID) if err != nil { return diag.Errorf("cannot get a billing group assigned projects list: %s", err) } @@ -240,7 +249,7 @@ func resourceProjectAssignToBillingGroup( } if !isAlreadyAssigned { - err = client.BillingGroup.AssignProjects(billingGroupID, []string{projectName}) + err = client.BillingGroup.AssignProjects(ctx, billingGroupID, []string{projectName}) if err != nil { return diag.Errorf("cannot assign project to a billing group: %s", err) } @@ -265,7 +274,7 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, m interfac MinTimeout: time.Second, Delay: time.Second, Refresh: func() (result interface{}, state string, err error) { - p, err := client.Projects.Get(d.Id()) + p, err := client.Projects.Get(ctx, d.Id()) if isNotProjectMember(err) { return nil, "pending", nil } @@ -280,10 +289,10 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, m interfac if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } - return setProjectTerraformProperties(d, client, project.(*aiven.Project)) + return setProjectTerraformProperties(ctx, d, client, project.(*aiven.Project)) } -func resourceProjectUpdate(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName := d.Get("project").(string) @@ -296,7 +305,7 @@ func resourceProjectUpdate(_ context.Context, d *schema.ResourceData, m interfac AddAccountOwnersAdminAccess: schemautil.OptionalBoolPointer(d, "add_account_owners_admin_access"), } - ptrAccountID, err := accountIDPointer(client, d) + ptrAccountID, err := accountIDPointer(ctx, client, d) if err != nil { return diag.FromErr(err) } @@ -308,13 +317,19 @@ func resourceProjectUpdate(_ context.Context, d *schema.ResourceData, m interfac req.AccountId = *ptrAccountID } - project, err := client.Projects.Update(d.Id(), req) + project, err := client.Projects.Update(ctx, d.Id(), req) if err != nil { return diag.FromErr(err) } if billingGroupID, ok := d.GetOk("billing_group"); ok { - dia := resourceProjectAssignToBillingGroup(d.Get("project").(string), billingGroupID.(string), client, d) + dia := resourceProjectAssignToBillingGroup( + ctx, + d.Get("project").(string), + billingGroupID.(string), + client, + d, + ) if dia.HasError() { return dia } @@ -325,10 +340,10 @@ func resourceProjectUpdate(_ context.Context, d *schema.ResourceData, m interfac return nil } -func resourceProjectDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) - err := client.Projects.Delete(d.Id()) + err := client.Projects.Delete(ctx, d.Id()) // Silence "Project with open balance cannot be deleted" error // to make long acceptance tests pass which generate some balance @@ -350,8 +365,13 @@ func resourceProjectDelete(_ context.Context, d *schema.ResourceData, m interfac return nil } -func resourceProjectGetCACert(project string, client *aiven.Client, d *schema.ResourceData) diag.Diagnostics { - ca, err := client.CA.Get(project) +func resourceProjectGetCACert( + ctx context.Context, + project string, + client *aiven.Client, + d *schema.ResourceData, +) diag.Diagnostics { + ca, err := client.CA.Get(ctx, project) if err == nil { if err := d.Set("ca_cert", ca); err != nil { return diag.FromErr(err) @@ -361,12 +381,12 @@ func resourceProjectGetCACert(project string, client *aiven.Client, d *schema.Re return nil } -func getLongCardID(client *aiven.Client, cardID string) (*string, error) { +func getLongCardID(ctx context.Context, client *aiven.Client, cardID string) (*string, error) { if cardID == "" { return nil, nil } - card, err := client.CardsHandler.Get(cardID) + card, err := client.CardsHandler.Get(ctx, cardID) if err != nil { return nil, err } @@ -412,9 +432,15 @@ func contactEmailListForTerraform(d *schema.ResourceData, field string, contactE return d.Set(field, results) } -func setProjectTerraformProperties(d *schema.ResourceData, client *aiven.Client, project *aiven.Project) diag.Diagnostics { +func setProjectTerraformProperties( + ctx context.Context, + d *schema.ResourceData, + client *aiven.Client, + project *aiven.Project, +) diag.Diagnostics { if stateID, ok := d.GetOk("parent_id"); ok { idToSet, err := schemautil.DetermineMixedOrganizationConstraintIDToStore( + ctx, client, stateID.(string), project.AccountId, @@ -437,7 +463,7 @@ func setProjectTerraformProperties(d *schema.ResourceData, client *aiven.Client, if err := contactEmailListForTerraform(d, "technical_emails", project.TechnicalEmails); err != nil { return diag.FromErr(err) } - if d := resourceProjectGetCACert(project.Name, client, d); d != nil { + if d := resourceProjectGetCACert(ctx, project.Name, client, d); d != nil { return d } if err := d.Set("default_cloud", project.DefaultCloud); err != nil { diff --git a/internal/sdkprovider/service/project/project_data_source.go b/internal/sdkprovider/service/project/project_data_source.go index b50aee15d..3950a28e1 100644 --- a/internal/sdkprovider/service/project/project_data_source.go +++ b/internal/sdkprovider/service/project/project_data_source.go @@ -3,7 +3,7 @@ package project import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -18,12 +18,12 @@ func DatasourceProject() *schema.Resource { } } -func datasourceProjectRead(c context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func datasourceProjectRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName := d.Get("project").(string) - projects, err := client.Projects.List() + projects, err := client.Projects.List(ctx) if err != nil { return diag.FromErr(err) } @@ -31,7 +31,7 @@ func datasourceProjectRead(c context.Context, d *schema.ResourceData, m interfac for _, project := range projects { if project.Name == projectName { d.SetId(projectName) - return resourceProjectRead(c, d, m) + return resourceProjectRead(ctx, d, m) } } diff --git a/internal/sdkprovider/service/project/project_test.go b/internal/sdkprovider/service/project/project_test.go index 4e366902e..c2f5675b4 100644 --- a/internal/sdkprovider/service/project/project_test.go +++ b/internal/sdkprovider/service/project/project_test.go @@ -1,12 +1,13 @@ package project_test import ( + "context" "fmt" "log" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -244,13 +245,15 @@ func testAccCheckAivenProjectAttributes(n string, attributes ...string) resource func testAccCheckAivenProjectResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each project is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_project" { continue } - p, err := c.Projects.Get(rs.Primary.ID) + p, err := c.Projects.Get(ctx, rs.Primary.ID) if err != nil { errStatus := err.(aiven.Error).Status if errStatus != 404 && errStatus != 403 { diff --git a/internal/sdkprovider/service/project/project_user.go b/internal/sdkprovider/service/project/project_user.go index 94220842b..f339547d3 100644 --- a/internal/sdkprovider/service/project/project_user.go +++ b/internal/sdkprovider/service/project/project_user.go @@ -4,7 +4,7 @@ import ( "context" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -53,6 +53,7 @@ func resourceProjectUserCreate(ctx context.Context, d *schema.ResourceData, m in projectName := d.Get("project").(string) email := d.Get("email").(string) err := client.ProjectUsers.Invite( + ctx, projectName, aiven.CreateProjectInvitationRequest{ UserEmail: email, @@ -79,7 +80,7 @@ func resourceProjectUserRead(ctx context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - user, invitation, err := client.ProjectUsers.Get(projectName, email) + user, invitation, err := client.ProjectUsers.Get(ctx, projectName, email) if err != nil { if aiven.IsNotFound(err) && !d.Get("accepted").(bool) { return resourceProjectUserCreate(ctx, d, m) @@ -121,6 +122,7 @@ func resourceProjectUserUpdate(ctx context.Context, d *schema.ResourceData, m in memberType := d.Get("member_type").(string) err = client.ProjectUsers.UpdateUserOrInvitation( + ctx, projectName, email, aiven.UpdateProjectUserOrInvitationRequest{ @@ -134,7 +136,7 @@ func resourceProjectUserUpdate(ctx context.Context, d *schema.ResourceData, m in return resourceProjectUserRead(ctx, d, m) } -func resourceProjectUserDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceProjectUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, email, err := schemautil.SplitResourceID2(d.Id()) @@ -142,14 +144,14 @@ func resourceProjectUserDelete(_ context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - user, invitation, err := client.ProjectUsers.Get(projectName, email) + user, invitation, err := client.ProjectUsers.Get(ctx, projectName, email) if err != nil { return diag.FromErr(err) } // delete user if exists if user != nil { - err := client.ProjectUsers.DeleteUser(projectName, email) + err := client.ProjectUsers.DeleteUser(ctx, projectName, email) if err != nil { if err.(aiven.Error).Status != 404 || !strings.Contains(err.(aiven.Error).Message, "User does not exist") || @@ -162,7 +164,7 @@ func resourceProjectUserDelete(_ context.Context, d *schema.ResourceData, m inte // delete invitation if exists if invitation != nil { - err := client.ProjectUsers.DeleteInvitation(projectName, email) + err := client.ProjectUsers.DeleteInvitation(ctx, projectName, email) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/project/project_user_data_source.go b/internal/sdkprovider/service/project/project_user_data_source.go index 50022eb8f..3e2228dbe 100644 --- a/internal/sdkprovider/service/project/project_user_data_source.go +++ b/internal/sdkprovider/service/project/project_user_data_source.go @@ -3,7 +3,7 @@ package project import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -25,7 +25,7 @@ func datasourceProjectUserRead(ctx context.Context, d *schema.ResourceData, m in projectName := d.Get("project").(string) email := d.Get("email").(string) - users, invitations, err := client.ProjectUsers.List(projectName) + users, invitations, err := client.ProjectUsers.List(ctx, projectName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/project/project_user_test.go b/internal/sdkprovider/service/project/project_user_test.go index 2146cf1cf..d91dc8ee5 100644 --- a/internal/sdkprovider/service/project/project_user_test.go +++ b/internal/sdkprovider/service/project/project_user_test.go @@ -1,10 +1,11 @@ package project_test import ( + "context" "fmt" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -47,6 +48,8 @@ func TestAccAivenProjectUser_basic(t *testing.T) { func testAccCheckAivenProjectUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each project is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_project_user" { @@ -58,7 +61,7 @@ func testAccCheckAivenProjectUserResourceDestroy(s *terraform.State) error { return err } - p, i, err := c.ProjectUsers.Get(projectName, email) + p, i, err := c.ProjectUsers.Get(ctx, projectName, email) if err != nil { errStatus := err.(aiven.Error).Status if errStatus != 404 && errStatus != 403 { diff --git a/internal/sdkprovider/service/project/sweep.go b/internal/sdkprovider/service/project/sweep.go index 108f5c9cf..379d2f32b 100644 --- a/internal/sdkprovider/service/project/sweep.go +++ b/internal/sdkprovider/service/project/sweep.go @@ -7,7 +7,7 @@ import ( "log" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/aiven/terraform-provider-aiven/internal/sweep" @@ -37,7 +37,7 @@ func init() { } func sweepProjects(region string) error { - client, err := sweep.SharedClient(region) + client, err := sweep.SharedClient() if err != nil { return fmt.Errorf("error getting client: %s", err) } diff --git a/internal/sdkprovider/service/project/util.go b/internal/sdkprovider/service/project/util.go index 07beac3a2..708fa9ed8 100644 --- a/internal/sdkprovider/service/project/util.go +++ b/internal/sdkprovider/service/project/util.go @@ -1,7 +1,9 @@ package project import ( - "github.com/aiven/aiven-go-client" + "context" + + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -10,12 +12,12 @@ import ( // accountIDPointer returns the account ID pointer to use in a request to the Aiven API. // This is limited to the domain of the billing groups and projects. // If the parent_id is set, it will be used as the account ID. Otherwise, the account_id will be used. -func accountIDPointer(client *aiven.Client, d *schema.ResourceData) (*string, error) { +func accountIDPointer(ctx context.Context, client *aiven.Client, d *schema.ResourceData) (*string, error) { var accountID *string ownerEntityID, ok := d.GetOk("parent_id") if ok { - ownerEntityID, err := schemautil.NormalizeOrganizationID(client, ownerEntityID.(string)) + ownerEntityID, err := schemautil.NormalizeOrganizationID(ctx, client, ownerEntityID.(string)) if err != nil { return nil, err } diff --git a/internal/sdkprovider/service/redis/redis_user.go b/internal/sdkprovider/service/redis/redis_user.go index afb301c77..49e091c2e 100644 --- a/internal/sdkprovider/service/redis/redis_user.go +++ b/internal/sdkprovider/service/redis/redis_user.go @@ -3,7 +3,7 @@ package redis import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -101,6 +101,7 @@ func resourceRedisUserCreate(ctx context.Context, d *schema.ResourceData, m inte serviceName := d.Get("service_name").(string) username := d.Get("username").(string) _, err := client.ServiceUsers.Create( + ctx, projectName, serviceName, aiven.CreateServiceUserRequest{ @@ -118,7 +119,7 @@ func resourceRedisUserCreate(ctx context.Context, d *schema.ResourceData, m inte } if _, ok := d.GetOk("password"); ok { - _, err := client.ServiceUsers.Update(projectName, serviceName, username, + _, err := client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ NewPassword: schemautil.OptionalStringPointer(d, "password"), }) @@ -140,7 +141,7 @@ func resourceRedisUserUpdate(ctx context.Context, d *schema.ResourceData, m inte return diag.FromErr(err) } - _, err = client.ServiceUsers.Update(projectName, serviceName, username, + _, err = client.ServiceUsers.Update(ctx, projectName, serviceName, username, aiven.ModifyServiceUserRequest{ NewPassword: schemautil.OptionalStringPointer(d, "password"), }) @@ -151,7 +152,7 @@ func resourceRedisUserUpdate(ctx context.Context, d *schema.ResourceData, m inte return resourceRedisUserRead(ctx, d, m) } -func resourceRedisUserRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceRedisUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, serviceName, username, err := schemautil.SplitResourceID3(d.Id()) @@ -159,7 +160,7 @@ func resourceRedisUserRead(_ context.Context, d *schema.ResourceData, m interfac return diag.FromErr(err) } - user, err := client.ServiceUsers.Get(projectName, serviceName, username) + user, err := client.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } diff --git a/internal/sdkprovider/service/redis/redis_user_data_source.go b/internal/sdkprovider/service/redis/redis_user_data_source.go index 2936300f1..f9a11ee68 100644 --- a/internal/sdkprovider/service/redis/redis_user_data_source.go +++ b/internal/sdkprovider/service/redis/redis_user_data_source.go @@ -3,7 +3,7 @@ package redis import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -26,7 +26,7 @@ func datasourceRedisUserRead(ctx context.Context, d *schema.ResourceData, m inte serviceName := d.Get("service_name").(string) userName := d.Get("username").(string) - list, err := client.ServiceUsers.List(projectName, serviceName) + list, err := client.ServiceUsers.List(ctx, projectName, serviceName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/redis/redis_user_test.go b/internal/sdkprovider/service/redis/redis_user_test.go index 27d9ad4c2..96f887672 100644 --- a/internal/sdkprovider/service/redis/redis_user_test.go +++ b/internal/sdkprovider/service/redis/redis_user_test.go @@ -1,11 +1,12 @@ package redis_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -39,6 +40,8 @@ func TestAccAivenRedisUser_basic(t *testing.T) { func testAccCheckAivenRedisUserResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_redis_user is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_redis_user" { @@ -50,7 +53,7 @@ func testAccCheckAivenRedisUserResourceDestroy(s *terraform.State) error { return err } - p, err := c.ServiceUsers.Get(projectName, serviceName, username) + p, err := c.ServiceUsers.Get(ctx, projectName, serviceName, username) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/servicecomponent/service_component_data_source.go b/internal/sdkprovider/service/servicecomponent/service_component_data_source.go index d5496722b..32f702bae 100644 --- a/internal/sdkprovider/service/servicecomponent/service_component_data_source.go +++ b/internal/sdkprovider/service/servicecomponent/service_component_data_source.go @@ -4,7 +4,7 @@ import ( "context" "strconv" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -103,7 +103,7 @@ func DatasourceServiceComponent() *schema.Resource { } } -func datasourceServiceComponentRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func datasourceServiceComponentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName := d.Get("project").(string) @@ -112,7 +112,7 @@ func datasourceServiceComponentRead(_ context.Context, d *schema.ResourceData, m route := d.Get("route").(string) usage := d.Get("usage").(string) - service, err := client.Services.Get(projectName, serviceName) + service, err := client.Services.Get(ctx, projectName, serviceName) if err != nil { return diag.Errorf("common %s/%s not found: %s", projectName, serviceName, err) } diff --git a/internal/sdkprovider/service/serviceintegration/service_integration.go b/internal/sdkprovider/service/serviceintegration/service_integration.go index b80dde15c..72a4e7042 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration.go @@ -7,7 +7,7 @@ import ( "regexp" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -165,6 +165,7 @@ func resourceServiceIntegrationCreate(ctx context.Context, d *schema.ResourceDat } integration, err := client.ServiceIntegrations.Create( + ctx, projectName, aiven.CreateServiceIntegrationRequest{ DestinationEndpointID: plainEndpointID(schemautil.OptionalStringPointer(d, "destination_endpoint_id")), @@ -186,7 +187,7 @@ func resourceServiceIntegrationCreate(ctx context.Context, d *schema.ResourceDat return resourceServiceIntegrationRead(ctx, d, m) } -func resourceServiceIntegrationRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceServiceIntegrationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, integrationID, err := schemautil.SplitResourceID2(d.Id()) @@ -194,7 +195,7 @@ func resourceServiceIntegrationRead(_ context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - integration, err := client.ServiceIntegrations.Get(projectName, integrationID) + integration, err := client.ServiceIntegrations.Get(ctx, projectName, integrationID) if err != nil { err = schemautil.ResourceReadHandleNotFound(err, d) if err != nil { @@ -229,6 +230,7 @@ func resourceServiceIntegrationUpdate(ctx context.Context, d *schema.ResourceDat } _, err = client.ServiceIntegrations.Update( + ctx, projectName, integrationID, aiven.UpdateServiceIntegrationRequest{ @@ -245,7 +247,7 @@ func resourceServiceIntegrationUpdate(ctx context.Context, d *schema.ResourceDat return resourceServiceIntegrationRead(ctx, d, m) } -func resourceServiceIntegrationDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceServiceIntegrationDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, integrationID, err := schemautil.SplitResourceID2(d.Id()) @@ -253,7 +255,7 @@ func resourceServiceIntegrationDelete(_ context.Context, d *schema.ResourceData, return diag.FromErr(err) } - err = client.ServiceIntegrations.Delete(projectName, integrationID) + err = client.ServiceIntegrations.Delete(ctx, projectName, integrationID) if err != nil && !aiven.IsNotFound(err) { return diag.Errorf("cannot delete service integration: %s", err) } @@ -261,7 +263,7 @@ func resourceServiceIntegrationDelete(_ context.Context, d *schema.ResourceData, return nil } -func resourceServiceIntegrationCheckForPreexistingResource(_ context.Context, d *schema.ResourceData, m interface{}) (*aiven.ServiceIntegration, error) { +func resourceServiceIntegrationCheckForPreexistingResource(ctx context.Context, d *schema.ResourceData, m interface{}) (*aiven.ServiceIntegration, error) { client := m.(*aiven.Client) projectName := d.Get("project").(string) @@ -269,7 +271,7 @@ func resourceServiceIntegrationCheckForPreexistingResource(_ context.Context, d sourceServiceName := d.Get("source_service_name").(string) destinationServiceName := d.Get("destination_service_name").(string) - integrations, err := client.ServiceIntegrations.List(projectName, sourceServiceName) + integrations, err := client.ServiceIntegrations.List(ctx, projectName, sourceServiceName) if err != nil && !aiven.IsNotFound(err) { return nil, fmt.Errorf("unable to get list of service integrations: %s", err) } @@ -308,7 +310,7 @@ func resourceServiceIntegrationWaitUntilActive(ctx context.Context, d *schema.Re Refresh: func() (interface{}, string, error) { log.Println("[DEBUG] Service Integration: waiting until active") - ii, err := client.ServiceIntegrations.Get(projectName, integrationID) + ii, err := client.ServiceIntegrations.Get(ctx, projectName, integrationID) if err != nil { // Sometimes Aiven API retrieves 404 error even when a successful service integration is created if aiven.IsNotFound(err) { @@ -323,7 +325,7 @@ func resourceServiceIntegrationWaitUntilActive(ctx context.Context, d *schema.Re } if ii.IntegrationType == "kafka_connect" && ii.DestinationService != nil { - if _, err := client.KafkaConnectors.List(projectName, *ii.DestinationService); err != nil { + if _, err := client.KafkaConnectors.List(ctx, projectName, *ii.DestinationService); err != nil { log.Println("[DEBUG] Service Integration: error listing kafka connectors: ", err) return nil, notActive, nil } diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_data_source.go b/internal/sdkprovider/service/serviceintegration/service_integration_data_source.go index 89c24d5b0..014bcc8da 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_data_source.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_data_source.go @@ -3,7 +3,7 @@ package serviceintegration import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -27,7 +27,7 @@ func datasourceServiceIntegrationRead(ctx context.Context, d *schema.ResourceDat sourceServiceName := d.Get("source_service_name").(string) destinationServiceName := d.Get("destination_service_name").(string) - integrations, err := client.ServiceIntegrations.List(projectName, sourceServiceName) + integrations, err := client.ServiceIntegrations.List(ctx, projectName, sourceServiceName) if err != nil { return diag.Errorf("unable to list integrations for %s/%s: %s", projectName, sourceServiceName, err) } diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go index 043d9cad8..883867bc4 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -99,6 +99,7 @@ func resourceServiceIntegrationEndpointCreate(ctx context.Context, d *schema.Res } endpoint, err := client.ServiceIntegrationEndpoints.Create( + ctx, projectName, aiven.CreateServiceIntegrationEndpointRequest{ EndpointName: d.Get("endpoint_name").(string), @@ -116,7 +117,7 @@ func resourceServiceIntegrationEndpointCreate(ctx context.Context, d *schema.Res return resourceServiceIntegrationEndpointRead(ctx, d, m) } -func resourceServiceIntegrationEndpointRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceServiceIntegrationEndpointRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, endpointID, err := schemautil.SplitResourceID2(d.Id()) @@ -124,7 +125,7 @@ func resourceServiceIntegrationEndpointRead(_ context.Context, d *schema.Resourc return diag.FromErr(err) } - endpoint, err := client.ServiceIntegrationEndpoints.Get(projectName, endpointID) + endpoint, err := client.ServiceIntegrationEndpoints.Get(ctx, projectName, endpointID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -153,6 +154,7 @@ func resourceServiceIntegrationEndpointUpdate(ctx context.Context, d *schema.Res } _, err = client.ServiceIntegrationEndpoints.Update( + ctx, projectName, endpointID, aiven.UpdateServiceIntegrationEndpointRequest{ @@ -166,7 +168,7 @@ func resourceServiceIntegrationEndpointUpdate(ctx context.Context, d *schema.Res return resourceServiceIntegrationEndpointRead(ctx, d, m) } -func resourceServiceIntegrationEndpointDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceServiceIntegrationEndpointDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, endpointID, err := schemautil.SplitResourceID2(d.Id()) @@ -174,7 +176,7 @@ func resourceServiceIntegrationEndpointDelete(_ context.Context, d *schema.Resou return diag.FromErr(err) } - err = client.ServiceIntegrationEndpoints.Delete(projectName, endpointID) + err = client.ServiceIntegrationEndpoints.Delete(ctx, projectName, endpointID) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go index d18a4d686..479d74a48 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go @@ -3,7 +3,7 @@ package serviceintegration import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -25,7 +25,7 @@ func datasourceServiceIntegrationEndpointRead(ctx context.Context, d *schema.Res projectName := d.Get("project").(string) endpointName := d.Get("endpoint_name").(string) - endpoints, err := client.ServiceIntegrationEndpoints.List(projectName) + endpoints, err := client.ServiceIntegrationEndpoints.List(ctx, projectName) if err != nil { return diag.FromErr(err) } diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_test.go b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_test.go index 8797d4ea7..5ed8b7060 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_test.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_test.go @@ -1,11 +1,12 @@ package serviceintegration_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -93,6 +94,8 @@ data "aiven_service_integration_endpoint" "endpoint" { func testAccCheckAivenServiceIntegraitonEndpointResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_service_integration_endpoint is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_service_integration_endpoint" { @@ -104,7 +107,7 @@ func testAccCheckAivenServiceIntegraitonEndpointResourceDestroy(s *terraform.Sta return err } - i, err := c.ServiceIntegrationEndpoints.Get(projectName, endpointID) + i, err := c.ServiceIntegrationEndpoints.Get(ctx, projectName, endpointID) if err != nil { if err.(aiven.Error).Status != 404 { return err diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_test.go b/internal/sdkprovider/service/serviceintegration/service_integration_test.go index a1ac5b75b..8bcfa5a9a 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_test.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_test.go @@ -1,12 +1,13 @@ package serviceintegration_test import ( + "context" "fmt" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -460,6 +461,8 @@ resource "aiven_service_integration" "bar" { func testAccCheckAivenServiceIntegrationResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each aiven_service_integration is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_service_integration" { @@ -471,7 +474,7 @@ func testAccCheckAivenServiceIntegrationResourceDestroy(s *terraform.State) erro return err } - i, err := c.ServiceIntegrations.Get(projectName, integrationID) + i, err := c.ServiceIntegrations.Get(ctx, projectName, integrationID) if err != nil && !aiven.IsNotFound(err) { return err } diff --git a/internal/sdkprovider/service/serviceintegration/sweep.go b/internal/sdkprovider/service/serviceintegration/sweep.go index 82118916f..1712ccac0 100644 --- a/internal/sdkprovider/service/serviceintegration/sweep.go +++ b/internal/sdkprovider/service/serviceintegration/sweep.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/aiven/terraform-provider-aiven/internal/sweep" @@ -25,7 +25,7 @@ func init() { } func sweepServiceIntegrations(region string) error { - client, err := sweep.SharedClient(region) + client, err := sweep.SharedClient() if err != nil { return err } @@ -60,7 +60,7 @@ func sweepServiceIntegrations(region string) error { } func sweepServiceIntegrationEndpoints(region string) error { - client, err := sweep.SharedClient(region) + client, err := sweep.SharedClient() if err != nil { return err } diff --git a/internal/sdkprovider/service/staticip/static_ip.go b/internal/sdkprovider/service/staticip/static_ip.go index f88852233..b8115414f 100644 --- a/internal/sdkprovider/service/staticip/static_ip.go +++ b/internal/sdkprovider/service/staticip/static_ip.go @@ -5,7 +5,7 @@ import ( "fmt" "log" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -59,7 +59,7 @@ func ResourceStaticIP() *schema.Resource { } } -func resourceStaticIPRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceStaticIPRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, staticIPAddressID, err := schemautil.SplitResourceID2(d.Id()) @@ -67,7 +67,7 @@ func resourceStaticIPRead(_ context.Context, d *schema.ResourceData, m interface return diag.Errorf("error splitting static IP ID: %s", err) } - r, err := client.StaticIPs.List(project) + r, err := client.StaticIPs.List(ctx, project) if err != nil { if schemautil.ResourceReadHandleNotFound(err, d) == nil { return nil @@ -94,7 +94,7 @@ func resourceStaticIPCreate(ctx context.Context, d *schema.ResourceData, m inter project := d.Get("project").(string) cloudName := d.Get("cloud_name").(string) - r, err := client.StaticIPs.Create(project, aiven.CreateStaticIPRequest{CloudName: cloudName}) + r, err := client.StaticIPs.Create(ctx, project, aiven.CreateStaticIPRequest{CloudName: cloudName}) if err != nil { return diag.Errorf("error creating static ip: %s", err) } @@ -108,7 +108,7 @@ func resourceStaticIPCreate(ctx context.Context, d *schema.ResourceData, m inter return resourceStaticIPRead(ctx, d, m) } -func resourceStaticIPDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceStaticIPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, staticIPAddressID, err := schemautil.SplitResourceID2(d.Id()) @@ -116,7 +116,7 @@ func resourceStaticIPDelete(_ context.Context, d *schema.ResourceData, m interfa return diag.Errorf("error spliting static IP ID: %s:", err) } - staticIP, err := client.StaticIPs.Get(project, staticIPAddressID) + staticIP, err := client.StaticIPs.Get(ctx, project, staticIPAddressID) if err != nil { if aiven.IsNotFound(err) { return nil @@ -126,12 +126,13 @@ func resourceStaticIPDelete(_ context.Context, d *schema.ResourceData, m interfa } if staticIP.State == schemautil.StaticIPAvailable { - if err := client.StaticIPs.Dissociate(project, staticIPAddressID); err != nil { + if err := client.StaticIPs.Dissociate(ctx, project, staticIPAddressID); err != nil { return diag.Errorf("error dissociating static IP (%s): %s", staticIPAddressID, err) } } err = client.StaticIPs.Delete( + ctx, project, aiven.DeleteStaticIPRequest{ StaticIPAddressID: staticIPAddressID, @@ -158,7 +159,7 @@ func resourceStaticIPWait(ctx context.Context, d *schema.ResourceData, m interfa Timeout: d.Timeout(schema.TimeoutCreate), Refresh: func() (result interface{}, state string, err error) { log.Println("[DEBUG] checking if static ip", staticIPAddressID, "is in 'created' state") - r, err := client.StaticIPs.List(project) + r, err := client.StaticIPs.List(ctx, project) if err != nil { return nil, "", fmt.Errorf("unable to fetch static ips: %w", err) } diff --git a/internal/sdkprovider/service/staticip/sweep.go b/internal/sdkprovider/service/staticip/sweep.go index 2fdd031ec..3399b7f48 100644 --- a/internal/sdkprovider/service/staticip/sweep.go +++ b/internal/sdkprovider/service/staticip/sweep.go @@ -6,7 +6,7 @@ import ( "fmt" "os" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/aiven/terraform-provider-aiven/internal/sweep" @@ -37,7 +37,7 @@ func init() { } func sweepStaticIPs(region string) error { - client, err := sweep.SharedClient(region) + client, err := sweep.SharedClient() if err != nil { return fmt.Errorf("error getting client: %s", err) } diff --git a/internal/sdkprovider/service/vpc/aws_privatelink.go b/internal/sdkprovider/service/vpc/aws_privatelink.go index ecf1b5a3f..704957017 100644 --- a/internal/sdkprovider/service/vpc/aws_privatelink.go +++ b/internal/sdkprovider/service/vpc/aws_privatelink.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -62,6 +62,7 @@ func resourceAWSPrivatelinkCreate(ctx context.Context, d *schema.ResourceData, m } _, err := client.AWSPrivatelink.Create( + ctx, project, serviceName, principals, @@ -72,6 +73,7 @@ func resourceAWSPrivatelinkCreate(ctx context.Context, d *schema.ResourceData, m // Wait until the AWS privatelink is active w := &AWSPrivatelinkWaiter{ + Context: ctx, Client: m.(*aiven.Client), Project: project, ServiceName: serviceName, @@ -88,7 +90,7 @@ func resourceAWSPrivatelinkCreate(ctx context.Context, d *schema.ResourceData, m return resourceAWSPrivatelinkRead(ctx, d, m) } -func resourceAWSPrivatelinkRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAWSPrivatelinkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, err := schemautil.SplitResourceID2(d.Id()) @@ -96,7 +98,7 @@ func resourceAWSPrivatelinkRead(_ context.Context, d *schema.ResourceData, m int return diag.FromErr(err) } - p, err := client.AWSPrivatelink.Get(project, serviceName) + p, err := client.AWSPrivatelink.Get(ctx, project, serviceName) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -133,6 +135,7 @@ func resourceAWSPrivatelinkUpdate(ctx context.Context, d *schema.ResourceData, m } _, err = client.AWSPrivatelink.Update( + ctx, project, serviceName, principals, @@ -143,6 +146,7 @@ func resourceAWSPrivatelinkUpdate(ctx context.Context, d *schema.ResourceData, m // Wait until the AWS privatelink is active w := &AWSPrivatelinkWaiter{ + Context: ctx, Client: m.(*aiven.Client), Project: project, ServiceName: serviceName, @@ -157,7 +161,7 @@ func resourceAWSPrivatelinkUpdate(ctx context.Context, d *schema.ResourceData, m return resourceAWSPrivatelinkRead(ctx, d, m) } -func resourceAWSPrivatelinkDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAWSPrivatelinkDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, err := schemautil.SplitResourceID2(d.Id()) @@ -165,7 +169,7 @@ func resourceAWSPrivatelinkDelete(_ context.Context, d *schema.ResourceData, m i return diag.FromErr(err) } - err = client.AWSPrivatelink.Delete(project, serviceName) + err = client.AWSPrivatelink.Delete(ctx, project, serviceName) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } @@ -175,6 +179,7 @@ func resourceAWSPrivatelinkDelete(_ context.Context, d *schema.ResourceData, m i // AWSPrivatelinkWaiter is used to wait for Aiven to build a AWS privatelink type AWSPrivatelinkWaiter struct { + Context context.Context Client *aiven.Client Project string ServiceName string @@ -184,7 +189,7 @@ type AWSPrivatelinkWaiter struct { // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. func (w *AWSPrivatelinkWaiter) RefreshFunc() resource.StateRefreshFunc { return func() (interface{}, string, error) { - pc, err := w.Client.AWSPrivatelink.Get(w.Project, w.ServiceName) + pc, err := w.Client.AWSPrivatelink.Get(w.Context, w.Project, w.ServiceName) if err != nil { return nil, "", err } diff --git a/internal/sdkprovider/service/vpc/aws_vpc_peering_connection.go b/internal/sdkprovider/service/vpc/aws_vpc_peering_connection.go index 9846774d6..cbee0ff46 100644 --- a/internal/sdkprovider/service/vpc/aws_vpc_peering_connection.go +++ b/internal/sdkprovider/service/vpc/aws_vpc_peering_connection.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -96,7 +96,13 @@ func resourceAWSVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour } pc, err = client.VPCPeeringConnections.GetVPCPeering( - projectName, vpcID, awsAccountID, awsVPCId, &awsVPCRegion) + ctx, + projectName, + vpcID, + awsAccountID, + awsVPCId, + &awsVPCRegion, + ) if err != nil && !aiven.IsNotFound(err) { return diag.Errorf("error checking aws peering connection: %s", err) } @@ -106,6 +112,7 @@ func resourceAWSVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour } if _, err = client.VPCPeeringConnections.Create( + ctx, projectName, vpcID, aiven.CreateVPCPeeringConnectionRequest{ @@ -130,6 +137,7 @@ func resourceAWSVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour }, Refresh: func() (interface{}, string, error) { pc, err := client.VPCPeeringConnections.GetVPCPeering( + ctx, projectName, vpcID, awsAccountID, @@ -164,7 +172,7 @@ func resourceAWSVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour return append(diags, resourceAWSVPCPeeringConnectionRead(ctx, d, m)...) } -func resourceAWSVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAWSVPCPeeringConnectionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) p, err := parsePeerVPCID(d.Id()) @@ -173,7 +181,13 @@ func resourceAWSVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceDa } pc, err := client.VPCPeeringConnections.GetVPCPeering( - p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC, p.peerRegion) + ctx, + p.projectName, + p.vpcID, + p.peerCloudAccount, + p.peerVPC, + p.peerRegion, + ) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -191,6 +205,7 @@ func resourceAWSVPCPeeringConnectionDelete(ctx context.Context, d *schema.Resour } err = client.VPCPeeringConnections.DeleteVPCPeering( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, @@ -217,6 +232,7 @@ func resourceAWSVPCPeeringConnectionDelete(ctx context.Context, d *schema.Resour }, Refresh: func() (interface{}, string, error) { pc, err := client.VPCPeeringConnections.GetVPCPeering( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, diff --git a/internal/sdkprovider/service/vpc/aws_vpc_peering_connection_data_source.go b/internal/sdkprovider/service/vpc/aws_vpc_peering_connection_data_source.go index 9d602c909..8468ddd0b 100644 --- a/internal/sdkprovider/service/vpc/aws_vpc_peering_connection_data_source.go +++ b/internal/sdkprovider/service/vpc/aws_vpc_peering_connection_data_source.go @@ -3,7 +3,7 @@ package vpc import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -31,7 +31,7 @@ func datasourceAWSVPCPeeringConnectionRead(ctx context.Context, d *schema.Resour awsVPCID := d.Get("aws_vpc_id").(string) awsVPCRegion := d.Get("aws_vpc_region").(string) - vpc, err := client.VPCs.Get(projectName, vpcID) + vpc, err := client.VPCs.Get(ctx, projectName, vpcID) if err != nil { return diag.Errorf("Error getting AWS VPC peering connection: %s", err) } diff --git a/internal/sdkprovider/service/vpc/azure_privatelink.go b/internal/sdkprovider/service/vpc/azure_privatelink.go index 0b0942443..9ad0d550b 100644 --- a/internal/sdkprovider/service/vpc/azure_privatelink.go +++ b/internal/sdkprovider/service/vpc/azure_privatelink.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -75,6 +75,7 @@ func resourceAzurePrivatelinkCreate(ctx context.Context, d *schema.ResourceData, } _, err := client.AzurePrivatelink.Create( + ctx, project, serviceName, aiven.AzurePrivatelinkRequest{UserSubscriptionIDs: subscriptionIDs}, @@ -84,8 +85,13 @@ func resourceAzurePrivatelinkCreate(ctx context.Context, d *schema.ResourceData, } // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated WaitForStateContext. - _, err = waitForAzurePrivatelinkToBeActive(client, project, serviceName, - d.Timeout(schema.TimeoutCreate)).WaitForStateContext(ctx) + _, err = waitForAzurePrivatelinkToBeActive( + ctx, + client, + project, + serviceName, + d.Timeout(schema.TimeoutCreate), + ).WaitForStateContext(ctx) if err != nil { return diag.Errorf("Error waiting for Azure privatelink: %s", err) } @@ -95,14 +101,14 @@ func resourceAzurePrivatelinkCreate(ctx context.Context, d *schema.ResourceData, return resourceAzurePrivatelinkRead(ctx, d, m) } -func resourceAzurePrivatelinkRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAzurePrivatelinkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, err := schemautil.SplitResourceID2(d.Id()) if err != nil { return diag.FromErr(err) } - pl, err := client.AzurePrivatelink.Get(project, serviceName) + pl, err := client.AzurePrivatelink.Get(ctx, project, serviceName) if err != nil { return diag.Errorf("Error getting Azure privatelink: %s", err) } @@ -145,6 +151,7 @@ func resourceAzurePrivatelinkUpdate(ctx context.Context, d *schema.ResourceData, } _, err = client.AzurePrivatelink.Update( + ctx, project, serviceName, aiven.AzurePrivatelinkRequest{UserSubscriptionIDs: subscriptionIDs}, @@ -154,8 +161,13 @@ func resourceAzurePrivatelinkUpdate(ctx context.Context, d *schema.ResourceData, } // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated WaitForStateContext. - _, err = waitForAzurePrivatelinkToBeActive(client, project, serviceName, - d.Timeout(schema.TimeoutUpdate)).WaitForStateContext(ctx) + _, err = waitForAzurePrivatelinkToBeActive( + ctx, + client, + project, + serviceName, + d.Timeout(schema.TimeoutUpdate), + ).WaitForStateContext(ctx) if err != nil { return diag.Errorf("Error waiting for Azure privatelink: %s", err) } @@ -165,12 +177,18 @@ func resourceAzurePrivatelinkUpdate(ctx context.Context, d *schema.ResourceData, // waitForAzurePrivatelinkToBeActive waits until the Azure privatelink is active // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. -func waitForAzurePrivatelinkToBeActive(client *aiven.Client, project string, serviceName string, t time.Duration) *resource.StateChangeConf { +func waitForAzurePrivatelinkToBeActive( + ctx context.Context, + client *aiven.Client, + project string, + serviceName string, + t time.Duration, +) *resource.StateChangeConf { return &resource.StateChangeConf{ Pending: []string{"creating"}, Target: []string{"active"}, Refresh: func() (interface{}, string, error) { - pl, err := client.AzurePrivatelink.Get(project, serviceName) + pl, err := client.AzurePrivatelink.Get(ctx, project, serviceName) if err != nil { return nil, "", err } @@ -193,7 +211,7 @@ func resourceAzurePrivatelinkDelete(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - err = client.AzurePrivatelink.Delete(project, serviceName) + err = client.AzurePrivatelink.Delete(ctx, project, serviceName) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } @@ -202,7 +220,7 @@ func resourceAzurePrivatelinkDelete(ctx context.Context, d *schema.ResourceData, Pending: []string{"deleting"}, Target: []string{"deleted"}, Refresh: func() (interface{}, string, error) { - pl, err := client.AzurePrivatelink.Get(project, serviceName) + pl, err := client.AzurePrivatelink.Get(ctx, project, serviceName) if err != nil { if aiven.IsNotFound(err) { return struct{}{}, "deleted", nil diff --git a/internal/sdkprovider/service/vpc/azure_privatelink_connection_approve.go b/internal/sdkprovider/service/vpc/azure_privatelink_connection_approve.go index 46d378578..55edf01ef 100644 --- a/internal/sdkprovider/service/vpc/azure_privatelink_connection_approve.go +++ b/internal/sdkprovider/service/vpc/azure_privatelink_connection_approve.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -51,17 +51,25 @@ func ResourceAzurePrivatelinkConnectionApproval() *schema.Resource { } // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. -func waitForAzureConnectionState(_ context.Context, client *aiven.Client, project string, service string, t time.Duration, pending []string, target []string) *resource.StateChangeConf { +func waitForAzureConnectionState( + ctx context.Context, + client *aiven.Client, + project string, + service string, + t time.Duration, + pending []string, + target []string, +) *resource.StateChangeConf { return &resource.StateChangeConf{ Pending: pending, Target: target, Refresh: func() (interface{}, string, error) { - err := client.AzurePrivatelink.Refresh(project, service) + err := client.AzurePrivatelink.Refresh(ctx, project, service) if err != nil { return nil, "", err } - plConnections, err := client.AzurePrivatelink.ConnectionsList(project, service) + plConnections, err := client.AzurePrivatelink.ConnectionsList(ctx, project, service) if err != nil { return nil, "", err } @@ -89,7 +97,7 @@ func resourceAzurePrivatelinkConnectionApprovalUpdate(ctx context.Context, d *sc var serviceName = d.Get("service_name").(string) var endpointIPAddress = d.Get("endpoint_ip_address").(string) - err := client.AzurePrivatelink.Refresh(project, serviceName) + err := client.AzurePrivatelink.Refresh(ctx, project, serviceName) if err != nil { return diag.FromErr(err) } @@ -103,7 +111,7 @@ func resourceAzurePrivatelinkConnectionApprovalUpdate(ctx context.Context, d *sc return diag.Errorf("Error waiting for privatelink connection after refresh: %s", err) } - plConnections, err := client.AzurePrivatelink.ConnectionsList(project, serviceName) + plConnections, err := client.AzurePrivatelink.ConnectionsList(ctx, project, serviceName) if err != nil { return diag.FromErr(err) } @@ -116,7 +124,7 @@ func resourceAzurePrivatelinkConnectionApprovalUpdate(ctx context.Context, d *sc plConnectionID := plConnection.PrivatelinkConnectionID if plConnection.State == "pending-user-approval" { - err = client.AzurePrivatelink.ConnectionApprove(project, serviceName, plConnectionID) + err = client.AzurePrivatelink.ConnectionApprove(ctx, project, serviceName, plConnectionID) if err != nil { return diag.Errorf("Error approving privatelink connection %s/%s/%s: %s", project, serviceName, plConnectionID, err) } @@ -134,7 +142,7 @@ func resourceAzurePrivatelinkConnectionApprovalUpdate(ctx context.Context, d *sc updateReq := aiven.AzurePrivatelinkConnectionUpdateRequest{ UserIPAddress: endpointIPAddress, } - err = client.AzurePrivatelink.ConnectionUpdate(project, serviceName, plConnectionID, updateReq) + err = client.AzurePrivatelink.ConnectionUpdate(ctx, project, serviceName, plConnectionID, updateReq) if err != nil { return diag.Errorf("Error updating privatelink connection %s/%s/%s: %s", project, serviceName, plConnectionID, err) } @@ -157,7 +165,7 @@ func resourceAzurePrivatelinkConnectionApprovalUpdate(ctx context.Context, d *sc return resourceAzurePrivatelinkConnectionApprovalRead(ctx, d, m) } -func resourceAzurePrivatelinkConnectionApprovalRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAzurePrivatelinkConnectionApprovalRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, service, err := schemautil.SplitResourceID2(d.Id()) if err != nil { @@ -165,7 +173,7 @@ func resourceAzurePrivatelinkConnectionApprovalRead(_ context.Context, d *schema } plConnectionID := schemautil.OptionalStringPointer(d, "privatelink_connection_id") - plConnection, err := client.AzurePrivatelink.ConnectionGet(project, service, plConnectionID) + plConnection, err := client.AzurePrivatelink.ConnectionGet(ctx, project, service, plConnectionID) if err != nil { if aiven.IsNotFound(err) { if err := d.Set("privatelink_connection_id", ""); err != nil { diff --git a/internal/sdkprovider/service/vpc/azure_privatelink_test.go b/internal/sdkprovider/service/vpc/azure_privatelink_test.go index 539816b96..0ecd91853 100644 --- a/internal/sdkprovider/service/vpc/azure_privatelink_test.go +++ b/internal/sdkprovider/service/vpc/azure_privatelink_test.go @@ -1,11 +1,12 @@ package vpc_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -44,6 +45,8 @@ func TestAccAivenAzurePrivatelink_basic(t *testing.T) { func testAccCheckAivenAzurePrivatelinkResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each Azure privatelink is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_azure_privatelink" { @@ -55,7 +58,7 @@ func testAccCheckAivenAzurePrivatelinkResourceDestroy(s *terraform.State) error return err } - pv, err := c.AzurePrivatelink.Get(project, serviceName) + pv, err := c.AzurePrivatelink.Get(ctx, project, serviceName) if err != nil && !aiven.IsNotFound(err) && err.(aiven.Error).Status != 500 { return fmt.Errorf("error getting a Azure Privatelink: %w", err) } diff --git a/internal/sdkprovider/service/vpc/azure_vpc_peering_connection.go b/internal/sdkprovider/service/vpc/azure_vpc_peering_connection.go index fdcaf3f4f..11f97acb9 100644 --- a/internal/sdkprovider/service/vpc/azure_vpc_peering_connection.go +++ b/internal/sdkprovider/service/vpc/azure_vpc_peering_connection.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -109,7 +109,13 @@ func resourceAzureVPCPeeringConnectionCreate(ctx context.Context, d *schema.Reso } pc, err := client.VPCPeeringConnections.GetVPCPeering( - projectName, vpcID, azureSubscriptionID, vnetName, &peerResourceGroup) + ctx, + projectName, + vpcID, + azureSubscriptionID, + vnetName, + &peerResourceGroup, + ) if err != nil && !aiven.IsNotFound(err) { return diag.Errorf("error checking azure connection: %s", err) } @@ -119,6 +125,7 @@ func resourceAzureVPCPeeringConnectionCreate(ctx context.Context, d *schema.Reso } if _, err := client.VPCPeeringConnections.Create( + ctx, projectName, vpcID, aiven.CreateVPCPeeringConnectionRequest{ @@ -145,6 +152,7 @@ func resourceAzureVPCPeeringConnectionCreate(ctx context.Context, d *schema.Reso }, Refresh: func() (interface{}, string, error) { pc, err := client.VPCPeeringConnections.GetVPCPeering( + ctx, projectName, vpcID, azureSubscriptionID, @@ -179,7 +187,7 @@ func resourceAzureVPCPeeringConnectionCreate(ctx context.Context, d *schema.Reso return append(diags, resourceAzureVPCPeeringConnectionRead(ctx, d, m)...) } -func resourceAzureVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceAzureVPCPeeringConnectionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) p, err := parsePeerVPCID(d.Id()) @@ -188,7 +196,14 @@ func resourceAzureVPCPeeringConnectionRead(_ context.Context, d *schema.Resource } pc, err := client.VPCPeeringConnections.GetVPCPeeringWithResourceGroup( - p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC, p.peerRegion, schemautil.OptionalStringPointer(d, "peer_resource_group")) + ctx, + p.projectName, + p.vpcID, + p.peerCloudAccount, + p.peerVPC, + p.peerRegion, + schemautil.OptionalStringPointer(d, "peer_resource_group"), + ) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -206,6 +221,7 @@ func resourceAzureVPCPeeringConnectionDelete(ctx context.Context, d *schema.Reso } peerResourceGroup := d.Get("peer_resource_group").(string) err = client.VPCPeeringConnections.DeleteVPCPeeringWithResourceGroup( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, @@ -233,12 +249,14 @@ func resourceAzureVPCPeeringConnectionDelete(ctx context.Context, d *schema.Reso }, Refresh: func() (interface{}, string, error) { pc, err := client.VPCPeeringConnections.GetVPCPeeringWithResourceGroup( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC, p.peerRegion, schemautil.OptionalStringPointer(d, "peer_resource_group"), // was already checked + ) if err != nil { return nil, "", err diff --git a/internal/sdkprovider/service/vpc/azure_vpc_peering_connection_data_source.go b/internal/sdkprovider/service/vpc/azure_vpc_peering_connection_data_source.go index 201ecfbfd..9d40051f3 100644 --- a/internal/sdkprovider/service/vpc/azure_vpc_peering_connection_data_source.go +++ b/internal/sdkprovider/service/vpc/azure_vpc_peering_connection_data_source.go @@ -3,7 +3,7 @@ package vpc import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -32,7 +32,7 @@ func datasourceAzureVPCPeeringConnectionRead(ctx context.Context, d *schema.Reso appID := d.Get("peer_azure_app_id").(string) tenantID := d.Get("peer_azure_tenant_id").(string) - vpc, err := client.VPCs.Get(projectName, vpcID) + vpc, err := client.VPCs.Get(ctx, projectName, vpcID) if err != nil { return diag.Errorf("Error getting Azure VPC peering connection: %s", err) } diff --git a/internal/sdkprovider/service/vpc/gcp_privatelink.go b/internal/sdkprovider/service/vpc/gcp_privatelink.go index f11046b7e..47d1feb0f 100644 --- a/internal/sdkprovider/service/vpc/gcp_privatelink.go +++ b/internal/sdkprovider/service/vpc/gcp_privatelink.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -56,14 +56,19 @@ func resourceGCPPrivatelinkCreate(ctx context.Context, d *schema.ResourceData, m var project = d.Get("project").(string) var serviceName = d.Get("service_name").(string) - _, err := client.GCPPrivatelink.Create(project, serviceName) + _, err := client.GCPPrivatelink.Create(ctx, project, serviceName) if err != nil { return diag.FromErr(err) } // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated WaitForStateContext. - _, err = waitForGCPPrivatelinkToBeActive(client, project, serviceName, - d.Timeout(schema.TimeoutCreate)).WaitForStateContext(ctx) + _, err = waitForGCPPrivatelinkToBeActive( + ctx, + client, + project, + serviceName, + d.Timeout(schema.TimeoutCreate), + ).WaitForStateContext(ctx) if err != nil { return diag.Errorf("Error waiting for GCP privatelink: %s", err) } @@ -73,7 +78,7 @@ func resourceGCPPrivatelinkCreate(ctx context.Context, d *schema.ResourceData, m return resourceGCPPrivatelinkRead(ctx, d, m) } -func resourceGCPPrivatelinkRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceGCPPrivatelinkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) project, serviceName, err := schemautil.SplitResourceID2(d.Id()) @@ -81,7 +86,7 @@ func resourceGCPPrivatelinkRead(_ context.Context, d *schema.ResourceData, m int return diag.FromErr(err) } - pl, err := client.GCPPrivatelink.Get(project, serviceName) + pl, err := client.GCPPrivatelink.Get(ctx, project, serviceName) if err != nil { return diag.Errorf("Error getting GCP privatelink: %s", err) } @@ -108,6 +113,7 @@ func resourceGCPPrivatelinkRead(_ context.Context, d *schema.ResourceData, m int // waitForGCPPrivatelinkToBeActive waits until the GCP privatelink is active // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. func waitForGCPPrivatelinkToBeActive( + ctx context.Context, client *aiven.Client, project string, serviceName string, @@ -117,7 +123,7 @@ func waitForGCPPrivatelinkToBeActive( Pending: []string{"creating"}, Target: []string{"active"}, Refresh: func() (interface{}, string, error) { - pl, err := client.GCPPrivatelink.Get(project, serviceName) + pl, err := client.GCPPrivatelink.Get(ctx, project, serviceName) if err != nil { return nil, "", err } @@ -140,7 +146,7 @@ func resourceGCPPrivatelinkDelete(ctx context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - err = client.GCPPrivatelink.Delete(project, serviceName) + err = client.GCPPrivatelink.Delete(ctx, project, serviceName) if err != nil && !aiven.IsNotFound(err) { return diag.FromErr(err) } @@ -149,7 +155,7 @@ func resourceGCPPrivatelinkDelete(ctx context.Context, d *schema.ResourceData, m Pending: []string{"deleting"}, Target: []string{"deleted"}, Refresh: func() (interface{}, string, error) { - pl, err := client.GCPPrivatelink.Get(project, serviceName) + pl, err := client.GCPPrivatelink.Get(ctx, project, serviceName) if err != nil { if aiven.IsNotFound(err) { return struct{}{}, "deleted", nil diff --git a/internal/sdkprovider/service/vpc/gcp_privatelink_connection_approve.go b/internal/sdkprovider/service/vpc/gcp_privatelink_connection_approve.go index 7907c1621..b0d25c68b 100644 --- a/internal/sdkprovider/service/vpc/gcp_privatelink_connection_approve.go +++ b/internal/sdkprovider/service/vpc/gcp_privatelink_connection_approve.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -58,7 +58,7 @@ func ResourceGCPPrivatelinkConnectionApproval() *schema.Resource { // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. func waitForGCPConnectionState( - _ context.Context, + ctx context.Context, client *aiven.Client, project string, service string, @@ -70,12 +70,12 @@ func waitForGCPConnectionState( Pending: pending, Target: target, Refresh: func() (interface{}, string, error) { - err := client.GCPPrivatelink.Refresh(project, service) + err := client.GCPPrivatelink.Refresh(ctx, project, service) if err != nil { return nil, "", err } - plConnections, err := client.GCPPrivatelink.ConnectionsList(project, service) + plConnections, err := client.GCPPrivatelink.ConnectionsList(ctx, project, service) if err != nil { return nil, "", err } @@ -108,7 +108,7 @@ func resourceGCPPrivatelinkConnectionApprovalUpdate( var project = d.Get("project").(string) var serviceName = d.Get("service_name").(string) - err := client.GCPPrivatelink.Refresh(project, serviceName) + err := client.GCPPrivatelink.Refresh(ctx, project, serviceName) if err != nil { return diag.FromErr(err) } @@ -124,7 +124,7 @@ func resourceGCPPrivatelinkConnectionApprovalUpdate( return diag.Errorf("Error waiting for privatelink connection after refresh: %s", err) } - plConnections, err := client.GCPPrivatelink.ConnectionsList(project, serviceName) + plConnections, err := client.GCPPrivatelink.ConnectionsList(ctx, project, serviceName) if err != nil { return diag.FromErr(err) } @@ -138,6 +138,7 @@ func resourceGCPPrivatelinkConnectionApprovalUpdate( if plConnection.State == "pending-user-approval" { err = client.GCPPrivatelink.ConnectionApprove( + ctx, project, serviceName, plConnectionID, @@ -173,7 +174,7 @@ func resourceGCPPrivatelinkConnectionApprovalUpdate( } func resourceGCPPrivatelinkConnectionApprovalRead( - _ context.Context, + ctx context.Context, d *schema.ResourceData, m interface{}, ) diag.Diagnostics { @@ -184,7 +185,7 @@ func resourceGCPPrivatelinkConnectionApprovalRead( } plConnectionID := schemautil.OptionalStringPointer(d, "privatelink_connection_id") - plConnection, err := client.GCPPrivatelink.ConnectionGet(project, service, plConnectionID) + plConnection, err := client.GCPPrivatelink.ConnectionGet(ctx, project, service, plConnectionID) if err != nil { if aiven.IsNotFound(err) { if err := d.Set("privatelink_connection_id", ""); err != nil { diff --git a/internal/sdkprovider/service/vpc/gcp_privatelink_test.go b/internal/sdkprovider/service/vpc/gcp_privatelink_test.go index f9d05a0f4..f24938f11 100644 --- a/internal/sdkprovider/service/vpc/gcp_privatelink_test.go +++ b/internal/sdkprovider/service/vpc/gcp_privatelink_test.go @@ -1,11 +1,12 @@ package vpc_test import ( + "context" "fmt" "os" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -38,6 +39,8 @@ func TestAccAivenGCPPrivatelink_basic(t *testing.T) { func testAccCheckAivenGCPPrivatelinkResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each GCP privatelink is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_gcp_privatelink" { @@ -49,7 +52,7 @@ func testAccCheckAivenGCPPrivatelinkResourceDestroy(s *terraform.State) error { return err } - pv, err := c.GCPPrivatelink.Get(project, serviceName) + pv, err := c.GCPPrivatelink.Get(ctx, project, serviceName) if err != nil && !aiven.IsNotFound(err) && err.(aiven.Error).Status != 500 { return fmt.Errorf("error getting a GCP Privatelink: %w", err) } diff --git a/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection.go b/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection.go index 6b373e20d..a0c8e977e 100644 --- a/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection.go +++ b/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -85,7 +85,13 @@ func resourceGCPVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour peerVPC := d.Get("peer_vpc").(string) pc, err = client.VPCPeeringConnections.GetVPCPeering( - projectName, vpcID, gcpProjectID, peerVPC, nil) + ctx, + projectName, + vpcID, + gcpProjectID, + peerVPC, + nil, + ) if err != nil && !aiven.IsNotFound(err) { return diag.Errorf("error checking gcp peering connection: %s", err) } @@ -95,6 +101,7 @@ func resourceGCPVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour } if _, err = client.VPCPeeringConnections.Create( + ctx, projectName, vpcID, aiven.CreateVPCPeeringConnectionRequest{ @@ -118,6 +125,7 @@ func resourceGCPVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour }, Refresh: func() (interface{}, string, error) { pc, err := client.VPCPeeringConnections.GetVPCPeering( + ctx, projectName, vpcID, gcpProjectID, @@ -152,7 +160,7 @@ func resourceGCPVPCPeeringConnectionCreate(ctx context.Context, d *schema.Resour return append(diags, resourceGCPVPCPeeringConnectionRead(ctx, d, m)...) } -func resourceGCPVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceGCPVPCPeeringConnectionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) p, err := parsePeerVPCID(d.Id()) @@ -162,7 +170,13 @@ func resourceGCPVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceDa var pc *aiven.VPCPeeringConnection pc, err = client.VPCPeeringConnections.GetVPCPeering( - p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC, p.peerRegion) + ctx, + p.projectName, + p.vpcID, + p.peerCloudAccount, + p.peerVPC, + p.peerRegion, + ) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -178,6 +192,7 @@ func resourceGCPVPCPeeringConnectionDelete(ctx context.Context, d *schema.Resour return diag.Errorf("error parsing GCP peering VPC ID: %s", err) } err = client.VPCPeeringConnections.DeleteVPCPeering( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, @@ -204,6 +219,7 @@ func resourceGCPVPCPeeringConnectionDelete(ctx context.Context, d *schema.Resour }, Refresh: func() (interface{}, string, error) { pc, err := client.VPCPeeringConnections.GetVPCPeering( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, diff --git a/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_data_source.go b/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_data_source.go index 1a727ffaf..827753b5a 100644 --- a/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_data_source.go +++ b/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_data_source.go @@ -3,7 +3,7 @@ package vpc import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -30,7 +30,7 @@ func datasourceGCPVPCPeeringConnectionRead(ctx context.Context, d *schema.Resour gcpProjectID := d.Get("gcp_project_id").(string) peerVPC := d.Get("peer_vpc").(string) - vpc, err := client.VPCs.Get(projectName, vpcID) + vpc, err := client.VPCs.Get(ctx, projectName, vpcID) if err != nil { return diag.Errorf("Error getting Azure VPC peering connection: %s", err) } diff --git a/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_test.go b/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_test.go index 98c695edb..7d2cee524 100644 --- a/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_test.go +++ b/internal/sdkprovider/service/vpc/gcp_vpc_peering_connection_test.go @@ -1,13 +1,14 @@ package vpc_test import ( + "context" "errors" "fmt" "strings" "testing" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/kelseyhightower/envconfig" @@ -55,10 +56,13 @@ func TestAccAivenGCPPeeringConnection_basic(t *testing.T) { Config: testAccGCPVPCPeeringConnection(&s), Check: func(state *terraform.State) error { c := acc.GetTestAivenClient() + + ctx := context.Background() + p := s.AivenProject QueryVpc: - vpcs, err := c.VPCs.List(p) + vpcs, err := c.VPCs.List(ctx, p) if err != nil { return err } @@ -74,7 +78,7 @@ func TestAccAivenGCPPeeringConnection_basic(t *testing.T) { return errors.New("error getting GCP peering connection, project VPC is empty") } - cons, err := c.VPCPeeringConnections.List(p, v.ProjectVPCID) + cons, err := c.VPCPeeringConnections.List(ctx, p, v.ProjectVPCID) if err != nil { return fmt.Errorf("error getting list of peering connections: %w", err) } diff --git a/internal/sdkprovider/service/vpc/project_vpc.go b/internal/sdkprovider/service/vpc/project_vpc.go index 4293150cd..b9ce1546f 100644 --- a/internal/sdkprovider/service/vpc/project_vpc.go +++ b/internal/sdkprovider/service/vpc/project_vpc.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -55,6 +55,7 @@ func resourceProjectVPCCreate(ctx context.Context, d *schema.ResourceData, m int client := m.(*aiven.Client) projectName := d.Get("project").(string) vpc, err := client.VPCs.Create( + ctx, projectName, aiven.CreateVPCRequest{ CloudName: d.Get("cloud_name").(string), @@ -68,6 +69,7 @@ func resourceProjectVPCCreate(ctx context.Context, d *schema.ResourceData, m int // Make sure the VPC is active before returning it because service creation, moving // service to VPC, and some other operations will fail unless the VPC is active waiter := ProjectVPCActiveWaiter{ + Context: ctx, Client: client, Project: projectName, VPCID: vpc.ProjectVPCID, @@ -84,7 +86,7 @@ func resourceProjectVPCCreate(ctx context.Context, d *schema.ResourceData, m int return resourceProjectVPCRead(ctx, d, m) } -func resourceProjectVPCRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceProjectVPCRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName, vpcID, err := schemautil.SplitResourceID2(d.Id()) @@ -92,7 +94,7 @@ func resourceProjectVPCRead(_ context.Context, d *schema.ResourceData, m interfa return diag.FromErr(err) } - vpc, err := client.VPCs.Get(projectName, vpcID) + vpc, err := client.VPCs.Get(ctx, projectName, vpcID) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -114,6 +116,7 @@ func resourceProjectVPCDelete(ctx context.Context, d *schema.ResourceData, m int } waiter := ProjectVPCDeleteWaiter{ + Context: ctx, Client: client, Project: projectName, VPCID: vpcID, @@ -148,6 +151,7 @@ func copyVPCPropertiesFromAPIResponseToTerraform(d *schema.ResourceData, vpc *ai // performed before creating a service that has a project VPC to ensure there has been sufficient // time for other actions that update the state to have been completed type ProjectVPCActiveWaiter struct { + Context context.Context Client *aiven.Client Project string VPCID string @@ -157,7 +161,7 @@ type ProjectVPCActiveWaiter struct { // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. func (w *ProjectVPCActiveWaiter) RefreshFunc() resource.StateRefreshFunc { return func() (interface{}, string, error) { - vpc, err := w.Client.VPCs.Get(w.Project, w.VPCID) + vpc, err := w.Client.VPCs.Get(w.Context, w.Project, w.VPCID) if err != nil { return nil, "", err } @@ -185,6 +189,7 @@ func (w *ProjectVPCActiveWaiter) Conf(timeout time.Duration) *resource.StateChan // ProjectVPCDeleteWaiter is used to wait for VPC been deleted. type ProjectVPCDeleteWaiter struct { + Context context.Context Client *aiven.Client Project string VPCID string @@ -194,7 +199,7 @@ type ProjectVPCDeleteWaiter struct { // nolint:staticcheck // TODO: Migrate to helper/retry package to avoid deprecated resource.StateRefreshFunc. func (w *ProjectVPCDeleteWaiter) RefreshFunc() resource.StateRefreshFunc { return func() (interface{}, string, error) { - vpc, err := w.Client.VPCs.Get(w.Project, w.VPCID) + vpc, err := w.Client.VPCs.Get(w.Context, w.Project, w.VPCID) if err != nil { // might be already gone after deletion if aiven.IsNotFound(err) { @@ -205,7 +210,7 @@ func (w *ProjectVPCDeleteWaiter) RefreshFunc() resource.StateRefreshFunc { } if vpc.State != "DELETING" && vpc.State != "DELETED" { - err := w.Client.VPCs.Delete(w.Project, w.VPCID) + err := w.Client.VPCs.Delete(w.Context, w.Project, w.VPCID) if err != nil { if aiven.IsNotFound(err) { return vpc, "DELETED", nil diff --git a/internal/sdkprovider/service/vpc/project_vpc_data_source.go b/internal/sdkprovider/service/vpc/project_vpc_data_source.go index e07c737aa..2003f6ab2 100644 --- a/internal/sdkprovider/service/vpc/project_vpc_data_source.go +++ b/internal/sdkprovider/service/vpc/project_vpc_data_source.go @@ -5,7 +5,7 @@ import ( "fmt" "regexp" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -62,7 +62,7 @@ func DatasourceProjectVPC() *schema.Resource { } } -func datasourceProjectVPCRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func datasourceProjectVPCRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) var vpcID, projectName, cloudName string @@ -80,7 +80,7 @@ func datasourceProjectVPCRead(_ context.Context, d *schema.ResourceData, m inter cloudName = d.Get("cloud_name").(string) } - vpcList, err := client.VPCs.List(projectName) + vpcList, err := client.VPCs.List(ctx, projectName) if err != nil { return diag.Errorf("error getting a list of project %q VPCs: %s", projectName, err) } diff --git a/internal/sdkprovider/service/vpc/project_vpc_data_source_test.go b/internal/sdkprovider/service/vpc/project_vpc_data_source_test.go index fcd2883aa..c29cdc25c 100644 --- a/internal/sdkprovider/service/vpc/project_vpc_data_source_test.go +++ b/internal/sdkprovider/service/vpc/project_vpc_data_source_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/stretchr/testify/require" ) diff --git a/internal/sdkprovider/service/vpc/project_vpc_test.go b/internal/sdkprovider/service/vpc/project_vpc_test.go index dfcde24fd..6ec7ff27e 100644 --- a/internal/sdkprovider/service/vpc/project_vpc_test.go +++ b/internal/sdkprovider/service/vpc/project_vpc_test.go @@ -1,12 +1,13 @@ package vpc_test import ( + "context" "fmt" "os" "regexp" "testing" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -108,6 +109,8 @@ func testAccCheckAivenProjectVPCAttributes(n string) resource.TestCheckFunc { func testAccCheckAivenProjectVPCResourceDestroy(s *terraform.State) error { c := acc.GetTestAivenClient() + ctx := context.Background() + // loop through the resources in state, verifying each project VPC is destroyed for _, rs := range s.RootModule().Resources { if rs.Type != "aiven_project_vpc" { @@ -119,7 +122,7 @@ func testAccCheckAivenProjectVPCResourceDestroy(s *terraform.State) error { return err } - vpc, err := c.VPCs.Get(projectName, vpcID) + vpc, err := c.VPCs.Get(ctx, projectName, vpcID) if err != nil { errStatus := err.(aiven.Error).Status if errStatus != 404 && errStatus != 403 { diff --git a/internal/sdkprovider/service/vpc/transit_gateway_vpc_attachment.go b/internal/sdkprovider/service/vpc/transit_gateway_vpc_attachment.go index 80296e5bb..ee72f917a 100644 --- a/internal/sdkprovider/service/vpc/transit_gateway_vpc_attachment.go +++ b/internal/sdkprovider/service/vpc/transit_gateway_vpc_attachment.go @@ -3,7 +3,7 @@ package vpc import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -97,7 +97,7 @@ func resourceTransitGatewayVPCAttachmentUpdate(ctx context.Context, d *schema.Re } } - peeringConnection, err := client.VPCPeeringConnections.Get(p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC) + peeringConnection, err := client.VPCPeeringConnections.Get(ctx, p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC) if err != nil { return diag.Errorf("cannot get transit gateway vpc attachment by id %s: %s", d.Id(), err) } @@ -148,7 +148,7 @@ func resourceTransitGatewayVPCAttachmentUpdate(ctx context.Context, d *schema.Re return resourceVPCPeeringConnectionRead(ctx, d, m) } - _, err = client.TransitGatewayVPCAttachment.Update(p.projectName, p.vpcID, aiven.TransitGatewayVPCAttachmentRequest{ + _, err = client.TransitGatewayVPCAttachment.Update(ctx, p.projectName, p.vpcID, aiven.TransitGatewayVPCAttachmentRequest{ Add: add, Delete: deleteCIDRs, }) diff --git a/internal/sdkprovider/service/vpc/vpc_peering_connection.go b/internal/sdkprovider/service/vpc/vpc_peering_connection.go index 15de5d380..928fea862 100644 --- a/internal/sdkprovider/service/vpc/vpc_peering_connection.go +++ b/internal/sdkprovider/service/vpc/vpc_peering_connection.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -58,6 +58,7 @@ func resourceVPCPeeringConnectionCreate(ctx context.Context, d *schema.ResourceD } if _, err = client.VPCPeeringConnections.Create( + ctx, projectName, vpcID, aiven.CreateVPCPeeringConnectionRequest{ @@ -86,6 +87,7 @@ func resourceVPCPeeringConnectionCreate(ctx context.Context, d *schema.ResourceD }, Refresh: func() (interface{}, string, error) { pc, err := client.VPCPeeringConnections.GetVPCPeering( + ctx, projectName, vpcID, peerCloudAccount, @@ -177,14 +179,14 @@ func parsePeerVPCID(src string) (*peeringVPCID, error) { return pID, nil } -func resourceVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { +func resourceVPCPeeringConnectionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { p, err := parsePeerVPCID(d.Id()) if err != nil { return diag.Errorf("error parsing peering VPC ID: %s", err) } client := m.(*aiven.Client) - isAzure, err := isAzureVPCPeeringConnection(d, client) + isAzure, err := isAzureVPCPeeringConnection(ctx, d, client) if err != nil { return diag.Errorf("Error checking if it Azure VPC peering connection: %s", err) } @@ -194,7 +196,14 @@ func resourceVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceData, peerResourceGroup := schemautil.OptionalStringPointer(d, "peer_resource_group") if peerResourceGroup != nil { pc, err = client.VPCPeeringConnections.GetVPCPeeringWithResourceGroup( - p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC, p.peerRegion, peerResourceGroup) + ctx, + p.projectName, + p.vpcID, + p.peerCloudAccount, + p.peerVPC, + p.peerRegion, + peerResourceGroup, + ) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -208,7 +217,13 @@ func resourceVPCPeeringConnectionRead(_ context.Context, d *schema.ResourceData, } pc, err = client.VPCPeeringConnections.GetVPCPeering( - p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC, p.peerRegion) + ctx, + p.projectName, + p.vpcID, + p.peerCloudAccount, + p.peerVPC, + p.peerRegion, + ) if err != nil { return diag.FromErr(schemautil.ResourceReadHandleNotFound(err, d)) } @@ -225,7 +240,7 @@ func resourceVPCPeeringConnectionDelete(ctx context.Context, d *schema.ResourceD return diag.Errorf("error parsing peering VPC ID: %s", err) } - isAzure, err := isAzureVPCPeeringConnection(d, client) + isAzure, err := isAzureVPCPeeringConnection(ctx, d, client) if err != nil { return diag.Errorf("Error checking if it Azure VPC peering connection: %s", err) } @@ -233,6 +248,7 @@ func resourceVPCPeeringConnectionDelete(ctx context.Context, d *schema.ResourceD if isAzure { if peerResourceGroup, ok := d.GetOk("peer_resource_group"); ok { if err = client.VPCPeeringConnections.DeleteVPCPeeringWithResourceGroup( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, @@ -247,6 +263,7 @@ func resourceVPCPeeringConnectionDelete(ctx context.Context, d *schema.ResourceD } } if err = client.VPCPeeringConnections.DeleteVPCPeering( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, @@ -274,15 +291,18 @@ func resourceVPCPeeringConnectionDelete(ctx context.Context, d *schema.ResourceD var pc *aiven.VPCPeeringConnection if isAzure { pc, err = client.VPCPeeringConnections.GetVPCPeeringWithResourceGroup( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, p.peerVPC, p.peerRegion, schemautil.OptionalStringPointer(d, "peer_resource_group"), // was already checked + ) } else { pc, err = client.VPCPeeringConnections.GetVPCPeering( + ctx, p.projectName, p.vpcID, p.peerCloudAccount, @@ -442,7 +462,7 @@ func ConvertStateInfoToMap(s *map[string]interface{}) map[string]string { } // isAzureVPCPeeringConnection checking if peered VPC is in the Azure cloud -func isAzureVPCPeeringConnection(d *schema.ResourceData, c *aiven.Client) (bool, error) { +func isAzureVPCPeeringConnection(ctx context.Context, d *schema.ResourceData, c *aiven.Client) (bool, error) { p, err := parsePeerVPCID(d.Id()) if err != nil { return false, fmt.Errorf("error parsing Azure peering VPC ID: %s", err) @@ -451,7 +471,7 @@ func isAzureVPCPeeringConnection(d *schema.ResourceData, c *aiven.Client) (bool, // If peerRegion is nil the peered VPC is assumed to be in the same region and // cloud as the project VPC if p.peerRegion == nil { - vpc, err := c.VPCs.Get(p.projectName, p.vpcID) + vpc, err := c.VPCs.Get(ctx, p.projectName, p.vpcID) if err != nil { return false, err } diff --git a/internal/sdkprovider/service/vpc/vpc_peering_connection_data_source.go b/internal/sdkprovider/service/vpc/vpc_peering_connection_data_source.go index d586c0c8d..cd370b2d4 100644 --- a/internal/sdkprovider/service/vpc/vpc_peering_connection_data_source.go +++ b/internal/sdkprovider/service/vpc/vpc_peering_connection_data_source.go @@ -3,7 +3,7 @@ package vpc import ( "context" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -21,7 +21,7 @@ func datasourceVPCPeeringConnectionRead(ctx context.Context, d *schema.ResourceD peerCloudAccount := d.Get("peer_cloud_account").(string) peerVPC := d.Get("peer_vpc").(string) - vpc, err := client.VPCs.Get(projectName, vpcID) + vpc, err := client.VPCs.Get(ctx, projectName, vpcID) if err != nil { return diag.Errorf("Error getting VPC peering connection: %s", err) } diff --git a/internal/sweep/sweep.go b/internal/sweep/sweep.go index a099ab1c6..360cbe5e1 100644 --- a/internal/sweep/sweep.go +++ b/internal/sweep/sweep.go @@ -3,11 +3,12 @@ package sweep import ( + "context" "fmt" "os" "strings" - "github.com/aiven/aiven-go-client" + "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/aiven/terraform-provider-aiven/internal/common" @@ -16,7 +17,7 @@ import ( var sharedClient *aiven.Client // SharedClient returns a common Aiven Client setup needed for the sweeper -func SharedClient(region string) (interface{}, error) { +func SharedClient() (*aiven.Client, error) { if os.Getenv("AIVEN_PROJECT_NAME") == "" { return nil, fmt.Errorf("must provide environment variable AIVEN_PROJECT_NAME ") } @@ -33,16 +34,15 @@ func SharedClient(region string) (interface{}, error) { return sharedClient, nil } -func SweepServices(region, t string) error { - client, err := SharedClient(region) +func SweepServices(ctx context.Context, t string) error { + client, err := SharedClient() if err != nil { return fmt.Errorf("error getting client: %s", err) } projectName := os.Getenv("AIVEN_PROJECT_NAME") - conn := client.(*aiven.Client) - services, err := conn.Services.List(projectName) + services, err := client.Services.List(ctx, projectName) if err != nil && !aiven.IsNotFound(err) { return fmt.Errorf("error retrieving a list of services for a project `%s`: %w", projectName, err) } @@ -59,7 +59,7 @@ func SweepServices(region, t string) error { // if service termination_protection is on service cannot be deleted // update service and turn termination_protection off if s.TerminationProtection { - _, err := conn.Services.Update(projectName, s.Name, aiven.UpdateServiceRequest{ + _, err := client.Services.Update(ctx, projectName, s.Name, aiven.UpdateServiceRequest{ Cloud: s.CloudName, MaintenanceWindow: &s.MaintenanceWindow, Plan: s.Plan, @@ -74,7 +74,7 @@ func SweepServices(region, t string) error { } } - if err := conn.Services.Delete(projectName, s.Name); err != nil { + if err := client.Services.Delete(ctx, projectName, s.Name); err != nil { if err != nil && !aiven.IsNotFound(err) { return fmt.Errorf("error destroying service %s during sweep: %s", s.Name, err) } @@ -86,8 +86,8 @@ func SweepServices(region, t string) error { func AddServiceSweeper(t string) { resource.AddTestSweepers("aiven_"+t, &resource.Sweeper{ Name: "aiven_" + t, - F: func(r string) error { - return SweepServices(r, t) + F: func(_ string) error { + return SweepServices(context.Background(), t) }, Dependencies: []string{"aiven_service_integration", "aiven_service_integration_endpoint"}, })