Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: move postgresql to sdk-go-bundle #749

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.7.1
### Refactor
- Move postgresql to sdk-go-bundle.

## 6.7.0
### Fixes
- Fix [#735](https://github.com/ionos-cloud/terraform-provider-ionoscloud/issues/735) by reading all values for `api_subnet_allow_list`, not only non-nill values.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/iancoleman/strcase v0.3.0
github.com/ionos-cloud/sdk-go-api-gateway v1.0.0
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0
github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2 v2.0.3
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0
github.com/ionos-cloud/sdk-go-bundle/products/vpn/v2 v2.0.2
Expand All @@ -27,7 +28,6 @@ require (
github.com/ionos-cloud/sdk-go-dbaas-in-memory-db v1.0.1
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.1.1
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.3
github.com/ionos-cloud/sdk-go-dns v1.2.1
github.com/ionos-cloud/sdk-go-kafka v1.0.0
github.com/ionos-cloud/sdk-go-nfs v1.1.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ github.com/ionos-cloud/sdk-go-api-gateway v1.0.0 h1:T+JzarV1Iw7NjWQfEuv5bESnHoCL
github.com/ionos-cloud/sdk-go-api-gateway v1.0.0/go.mod h1:TkSlamP+qKRT8cgBaZEN8rawanVluOR0dXbXXdmmwTY=
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0 h1:8fRICa4i+GJHrCgnLe8t3uwfahkg7pcDDwoLkH3B2Xc=
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0/go.mod h1:BF6R+j1GdJEMImxkeh32qjIVWqsBfgi6VgyfsY5ezIA=
github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2 v2.0.2 h1:798tViGFFHoqYirqIB62y1bYZYZsBYZvRiT9WLx/hJY=
github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2 v2.0.2/go.mod h1:z5x+V5elUPH09d1iX8pdriq3cNqMSsE9dtCy6RRBfYw=
github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2 v2.0.3 h1:8XAGHfdf4i/jhWtenMWWDwcRztd/LEVpNoKYWzwnxLw=
github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2 v2.0.3/go.mod h1:z5x+V5elUPH09d1iX8pdriq3cNqMSsE9dtCy6RRBfYw=
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1 h1:GXxdNKl7haQnHO1QewZeXazur5+LDCpHqvP+nNObGaA=
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1/go.mod h1:N0ifRq3ENqGg6qht1WPrVgSkcavPS5SRWlNfkHUZbfQ=
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0 h1:gVh+jd0o8ROtJLWqUB6/VU8vSLdj/kRYAz/qbMO7z7I=
Expand All @@ -136,8 +140,6 @@ github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.1.1 h1:dZLxaH2n0nxCOKMkt49TibOiY1
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.1.1/go.mod h1:NuUqBA9DyP4PB3MtKy/R9XRHY1RZcwVP6E3tP4FwI7I=
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1 h1:+tDoZ8IEPxYwJd6fDIpWksNJs9Zzw7Pu5A39jTew058=
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1/go.mod h1:rxOAeyAU6BTfghJibSRDdRNrKm2cIXMpSMe7JIWewJ8=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.3 h1:T05nbKqBIw2zmPwaV2pWyFcUVjblLMoShPM9nAYQjLM=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.3/go.mod h1:5cKJUIcXfMbG5vVkz6cYjnToZvaQylkLsIuhOW7PhEI=
github.com/ionos-cloud/sdk-go-dns v1.2.1 h1:Sy7Jg5trzObad9VPvEh7BgeJrIhaxdGlBEvG2aHJZH8=
github.com/ionos-cloud/sdk-go-dns v1.2.1/go.mod h1:l9gYdwtUshlBOiIi4nHn3RCX81XlV3VoNvLJrO2VfHg=
github.com/ionos-cloud/sdk-go-kafka v1.0.0 h1:S0Tfy/KlYW7UJW6DoU43fF0/iNPc1YKC+AC56G9wfA4=
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/data_source_dbaas_pgsql_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func dataSourceDbaasPgSqlReadBackups(ctx context.Context, d *schema.ResourceData
diags := diag.FromErr(fmt.Errorf("an error occurred while fetching backup for cluster with ID %s: %w", idStr, err))
return diags
}
if len(*clusterBackups.Items) == 0 {
if len(clusterBackups.Items) == 0 {
diags := diag.FromErr(fmt.Errorf("could not find backups for cluster with ID %s: %w", idStr, err))
return diags
}
Expand Down
6 changes: 3 additions & 3 deletions ionoscloud/data_source_dbaas_pgsql_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"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"
dbaas "github.com/ionos-cloud/sdk-go-dbaas-postgres"
dbaas "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
dbaasService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dbaas"
Expand Down Expand Up @@ -200,8 +200,8 @@ func dataSourceDbaasPgSqlReadCluster(ctx context.Context, d *schema.ResourceData

var results []dbaas.ClusterResponse

if clusters.Items != nil && len(*clusters.Items) > 0 {
for _, clusterItem := range *clusters.Items {
if clusters.Items != nil && len(clusters.Items) > 0 {
for _, clusterItem := range clusters.Items {
if clusterItem.Properties != nil && clusterItem.Properties.DisplayName != nil && strings.EqualFold(*clusterItem.Properties.DisplayName, name.(string)) {
results = append(results, clusterItem)
}
Expand Down
10 changes: 2 additions & 8 deletions ionoscloud/data_source_dbaas_pgsql_databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package ionoscloud
import (
"context"
"fmt"
"log"

"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"
Expand Down Expand Up @@ -67,18 +65,14 @@ func dataSourceDbaasPgSqlReadDatabases(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(fmt.Errorf("expected a list of PgSql databases, but received 'nil' instead, cluster ID: %s", clusterId))
}
var databases []interface{}
for _, retrievedDatabase := range *retrievedDatabases.Items {
if retrievedDatabase.Properties == nil {
log.Printf("[INFO] 'nil' values in the response for the database with ID: %s, cluster ID: %s, skipping this database since there is not enough information to set in the state", *retrievedDatabase.Id, clusterId)
continue
}
for _, retrievedDatabase := range retrievedDatabases.Items {
database := make(map[string]interface{})
utils.SetPropWithNilCheck(database, "name", retrievedDatabase.Properties.Name)
utils.SetPropWithNilCheck(database, "owner", retrievedDatabase.Properties.Owner)
utils.SetPropWithNilCheck(database, "id", retrievedDatabase.Id)
// Filter using the owner
if ownerOk {
if *retrievedDatabase.Properties.Owner == owner.(string) {
if retrievedDatabase.Properties.Owner == owner.(string) {
databases = append(databases, database)
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/data_source_dbaas_pgsql_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
psql "github.com/ionos-cloud/sdk-go-dbaas-postgres"
psql "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
dbaasService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dbaas"
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/resource_dbaas_pgsql_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
psql "github.com/ionos-cloud/sdk-go-dbaas-postgres"
psql "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
)

Expand Down
8 changes: 4 additions & 4 deletions ionoscloud/resource_dbaas_pgsql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"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"
pgsql "github.com/ionos-cloud/sdk-go-dbaas-postgres"
pgsql "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dbaas"
Expand Down Expand Up @@ -51,10 +51,10 @@ func resourceDbaasPgSqlDatabaseCreate(ctx context.Context, d *schema.ResourceDat
name := d.Get("name").(string)
owner := d.Get("owner").(string)
request := pgsql.Database{
Properties: &pgsql.DatabaseProperties{},
Properties: pgsql.DatabaseProperties{},
}
request.Properties.Name = &name
request.Properties.Owner = &owner
request.Properties.Name = name
request.Properties.Owner = owner

database, _, err := client.CreateDatabase(ctx, clusterId, request)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/resource_dbaas_pgsql_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
pgsql "github.com/ionos-cloud/sdk-go-dbaas-postgres"
pgsql "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
)
Expand Down
10 changes: 5 additions & 5 deletions ionoscloud/resource_dbaas_pgsql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"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"
pgsql "github.com/ionos-cloud/sdk-go-dbaas-postgres"
pgsql "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dbaas"
Expand Down Expand Up @@ -59,16 +59,16 @@ func resourceDbaasPgSqlUserCreate(ctx context.Context, d *schema.ResourceData, m
password := d.Get("password").(string)

request := pgsql.User{
Properties: &pgsql.UserProperties{},
Properties: pgsql.UserProperties{},
}
request.Properties.Username = &username
request.Properties.Username = username
request.Properties.Password = &password

user, _, err := client.CreateUser(ctx, clusterId, request)
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while adding the user: %s to the PgSql cluster with ID: %s, error: %w", username, clusterId, err))
}
d.SetId(*user.Id)
d.SetId(user.Id)
// Wait for the cluster to be ready again (when creating/updating the user, the cluster enters
// 'BUSY' state).
err = utils.WaitForResourceToBeReady(ctx, d, client.IsClusterReady)
Expand All @@ -82,7 +82,7 @@ func resourceDbaasPgSqlUserUpdate(ctx context.Context, d *schema.ResourceData, m
client := meta.(services.SdkBundle).PsqlClient

request := pgsql.UsersPatchRequest{
Properties: pgsql.NewPatchUserProperties(),
Properties: *pgsql.NewPatchUserProperties(),
}

clusterId := d.Get("cluster_id").(string)
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/resource_dbaas_pgsql_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
pgsql "github.com/ionos-cloud/sdk-go-dbaas-postgres"
pgsql "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
)
Expand Down
11 changes: 6 additions & 5 deletions services/dbaas/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,35 @@
import (
"context"
"fmt"
"github.com/ionos-cloud/sdk-go-bundle/shared"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
dbaas "github.com/ionos-cloud/sdk-go-dbaas-postgres"
"github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"
)

func (c *PsqlClient) GetClusterBackups(ctx context.Context, clusterId string) (dbaas.ClusterBackupList, *dbaas.APIResponse, error) {
func (c *PsqlClient) GetClusterBackups(ctx context.Context, clusterId string) (psql.ClusterBackupList, *shared.APIResponse, error) {

Check failure on line 14 in services/dbaas/backups.go

View workflow job for this annotation

GitHub Actions / lint

exported method `PsqlClient.GetClusterBackups` should have comment or be unexported (golint)
backups, apiResponse, err := c.sdkClient.BackupsApi.ClusterBackupsGet(ctx, clusterId).Execute()
apiResponse.LogInfo()
return backups, apiResponse, err

}

func (c *PsqlClient) GetAllBackups(ctx context.Context) (dbaas.ClusterBackupList, *dbaas.APIResponse, error) {
func (c *PsqlClient) GetAllBackups(ctx context.Context) (psql.ClusterBackupList, *shared.APIResponse, error) {

Check failure on line 21 in services/dbaas/backups.go

View workflow job for this annotation

GitHub Actions / lint

exported method `PsqlClient.GetAllBackups` should have comment or be unexported (golint)
backups, apiResponse, err := c.sdkClient.BackupsApi.ClustersBackupsGet(ctx).Execute()
apiResponse.LogInfo()
return backups, apiResponse, err
}

func SetPgSqlClusterBackupData(d *schema.ResourceData, clusterBackups *dbaas.ClusterBackupList) diag.Diagnostics {
func SetPgSqlClusterBackupData(d *schema.ResourceData, clusterBackups *psql.ClusterBackupList) diag.Diagnostics {

Check failure on line 27 in services/dbaas/backups.go

View workflow job for this annotation

GitHub Actions / lint

exported function `SetPgSqlClusterBackupData` should have comment or be unexported (golint)

resourceId := uuid.New()
d.SetId(resourceId.String())

if clusterBackups.Items != nil {
var backups []interface{}
for _, backup := range *clusterBackups.Items {
for _, backup := range clusterBackups.Items {

backupEntry := make(map[string]interface{})
if backup.Id != nil {
Expand Down
14 changes: 6 additions & 8 deletions services/dbaas/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package dbaas

import (
"fmt"
"github.com/ionos-cloud/sdk-go-bundle/shared"
"net/http"
"os"
"runtime"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"

"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
"github.com/ionos-cloud/sdk-go-bundle/products/dbaas/psql/v2"
mongo "github.com/ionos-cloud/sdk-go-dbaas-mongo"
psql "github.com/ionos-cloud/sdk-go-dbaas-postgres"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
)
Expand Down Expand Up @@ -43,20 +44,17 @@ func NewMongoClient(username, password, token, url, version, terraformVersion st
}

func NewPsqlClient(username, password, token, url, version, terraformVersion string, insecure bool) *PsqlClient {
newConfigDbaas := psql.NewConfiguration(username, password, token, url)
newConfigDbaas := shared.NewConfiguration(username, password, token, url)

if os.Getenv(constant.IonosDebug) != "" {
newConfigDbaas.Debug = true
}
newConfigDbaas.MaxRetries = constant.MaxRetries
newConfigDbaas.MaxWaitTime = constant.MaxWaitTime

newConfigDbaas.HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}
newConfigDbaas.UserAgent = fmt.Sprintf(
"terraform-provider/%s_ionos-cloud-sdk-go-dbaas-postgres/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s",
version, psql.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH)

return &PsqlClient{
psqlClient := &PsqlClient{
sdkClient: psql.NewAPIClient(newConfigDbaas),
}
psqlClient.sdkClient.GetConfig().HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}
return psqlClient
}
Loading
Loading