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

Use bundle for mariadb #758

Open
wants to merge 7 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
2 changes: 1 addition & 1 deletion docs/resources/dbaas_inmemorydb_replica_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "ionoscloud_server" "example" {
ram = 2048
availability_zone = "ZONE_1"
cpu_family = "INTEL_SKYLAKE"
image_name = "rockylinux-8-GenericCloud-20230518"
image_name = "rockylinux-8-GenericCloud-20240528"
image_password = "password"
volume {
name = "example"
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/dbaas_mariadb_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "ionoscloud_server" "example" {
ram = 2048
availability_zone = "ZONE_1"
cpu_family = "INTEL_SKYLAKE"
image_name = "rockylinux-8-GenericCloud-20230518"
image_name = "rockylinux-8-GenericCloud-20240528"
image_password = "password"
volume {
name = "example"
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/dbaas_pgsql_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ resource "ionoscloud_server" "example" {
ram = 2048
availability_zone = "ZONE_1"
cpu_family = "INTEL_SKYLAKE"
image_name = "rockylinux-8-GenericCloud-20230518"
image_name = "rockylinux-8-GenericCloud-20240528"
image_password = "password"
volume {
name = "example"
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/mariadb/v2 v2.0.0
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 @@ -25,7 +26,6 @@ require (
github.com/ionos-cloud/sdk-go-container-registry v1.2.0
github.com/ionos-cloud/sdk-go-dataplatform v1.1.1
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ 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/mariadb/v2 v2.0.0 h1:HZiy10ADUUheZJFyMzN7a8ILt/2tp9SxasJh1AQ03QU=
github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mariadb/v2 v2.0.0/go.mod h1:viTYczukRYE3C94NUyKrSc2yEZvOq6mCbFwzVnjJnM4=
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 @@ -132,8 +134,6 @@ github.com/ionos-cloud/sdk-go-dataplatform v1.1.1 h1:Wu9TAiphRyMEweUcQlMblhVCl9q
github.com/ionos-cloud/sdk-go-dataplatform v1.1.1/go.mod h1:3rQrOZFbXcjK3C5Dnjzahsd9x7PO+b4AARdBwdz//Mg=
github.com/ionos-cloud/sdk-go-dbaas-in-memory-db v1.0.1 h1:vd3SCqZ1OI5l7Tzql7NDb5Zlpna8e2SsfEYZRGHOkOo=
github.com/ionos-cloud/sdk-go-dbaas-in-memory-db v1.0.1/go.mod h1:JLbyt5wj7+f/njy7pnWD6K+cCfe32p8VrjmKks055+w=
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.1.1 h1:dZLxaH2n0nxCOKMkt49TibOiY1hkaHThpXEgJL0oZng=
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=
Expand Down
4 changes: 2 additions & 2 deletions ionoscloud/data_source_dbaas_mariadb_backups.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"
mariadbSDK "github.com/ionos-cloud/sdk-go-dbaas-mariadb"
mariadbSDK "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mariadb/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dbaas/mariadb"
Expand Down Expand Up @@ -109,7 +109,7 @@ func dataSourceDBaaSMariaDBReadBackups(ctx context.Context, d *schema.ResourceDa
if backupsResponse.Items == nil {
return diag.FromErr(fmt.Errorf("expected valid properties in the API response for cluster backups, but received 'nil' instead, cluster ID: %s", clusterId))
}
backups = *backupsResponse.Items
backups = backupsResponse.Items
} else {
var backup mariadbSDK.BackupResponse
backup, _, err = client.FindBackupByID(ctx, backupId, location)
Expand Down
4 changes: 2 additions & 2 deletions ionoscloud/data_source_dbaas_mariadb_cluster.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"
dbaas "github.com/ionos-cloud/sdk-go-dbaas-mariadb"
dbaas "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mariadb/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
)
Expand Down Expand Up @@ -143,7 +143,7 @@ func dataSourceMariaDBClusterRead(ctx context.Context, d *schema.ResourceData, m
var results []dbaas.ClusterResponse

if clusters.Items != nil {
for _, clusterItem := range *clusters.Items {
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
2 changes: 1 addition & 1 deletion ionoscloud/resource_dbaas_inmemorydb_replicaset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ resource ` + constant.ServerResource + ` ` + constant.ServerTestResource + ` {
ram = 2048
availability_zone = "ZONE_1"
cpu_family = "INTEL_SKYLAKE"
image_name = "rockylinux-8-GenericCloud-20230518"
image_name = "rockylinux-8-GenericCloud-20240528"
image_password = ` + constant.RandomPassword + `.server_image_password.result
volume {
name = "example"
Expand Down
10 changes: 5 additions & 5 deletions ionoscloud/resource_dbaas_mariadb_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
mariadb "github.com/ionos-cloud/sdk-go-dbaas-mariadb"
mariadb "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mariadb/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
)
Expand Down Expand Up @@ -193,7 +193,7 @@ resource ` + constant.ServerResource + ` ` + constant.ServerTestResource + ` {
ram = 2048
availability_zone = "ZONE_1"
cpu_family = "INTEL_SKYLAKE"
image_name = "rockylinux-8-GenericCloud-20230518"
image_name = "rockylinux-8-GenericCloud-20240528"
image_password = ` + constant.RandomPassword + `.server_image_password.result
volume {
name = "example"
Expand Down Expand Up @@ -235,9 +235,9 @@ resource ` + constant.DBaaSMariaDBClusterResource + ` ` + constant.DBaaSClusterT
}

# Wait few seconds after cluster creation so the backups can be properly retrieved
resource "time_sleep" "wait_30_seconds" {
resource "time_sleep" "wait_5_minutes" {
depends_on = [` + constant.DBaaSMariaDBClusterResource + `.` + constant.DBaaSClusterTestResource + `]
create_duration = "30s"
create_duration = "300s"
}
`

Expand Down Expand Up @@ -292,7 +292,7 @@ data ` + constant.DBaaSMariaDBBackupsDataSource + ` ` + constant.DBaasMariaDBBac
cluster_id = ` + constant.DBaaSMariaDBClusterResource + `.` + constant.DBaaSClusterTestResource + `.id
` + clusterLocationAttribute + ` = "` + clusterLocationValue + `"
# Use the previously created 'time' resource to delay information retrieval for the data source
depends_on = [time_sleep.wait_30_seconds]
depends_on = [time_sleep.wait_5_minutes]
}
`
const mariaDBClusterDataSourceWrongName = `
Expand Down
9 changes: 5 additions & 4 deletions services/dbaas/mariadb/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
mariadb "github.com/ionos-cloud/sdk-go-dbaas-mariadb"
mariadb "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mariadb/v2"
shared "github.com/ionos-cloud/sdk-go-bundle/shared"
)

// GetClusterBackups retrieves a list of backups for a given cluster ID and the location in which the cluster is created.
func (c *MariaDBClient) GetClusterBackups(ctx context.Context, clusterID, location string) (mariadb.BackupList, *mariadb.APIResponse, error) {
func (c *MariaDBClient) GetClusterBackups(ctx context.Context, clusterID, location string) (mariadb.BackupList, *shared.APIResponse, error) {
c.modifyConfigURL(location)
backups, apiResponse, err := c.sdkClient.BackupsApi.ClusterBackupsGet(ctx, clusterID).Execute()
apiResponse.LogInfo()
return backups, apiResponse, err
}

// FindBackupByID retrieves a backup by its ID and the location in which the cluster is created.
func (c *MariaDBClient) FindBackupByID(ctx context.Context, backupID, location string) (mariadb.BackupResponse, *mariadb.APIResponse, error) {
func (c *MariaDBClient) FindBackupByID(ctx context.Context, backupID, location string) (mariadb.BackupResponse, *shared.APIResponse, error) {
c.modifyConfigURL(location)
backups, apiResponse, err := c.sdkClient.BackupsApi.BackupsFindById(ctx, backupID).Execute()
apiResponse.LogInfo()
Expand Down Expand Up @@ -47,7 +48,7 @@ func SetMariaDBClusterBackupsData(d *schema.ResourceData, retrievedBackups []mar
backupEntry["size"] = *retrievedBackup.Properties.Size
}
var baseBackupsToBeSet []interface{}
for _, baseBackup := range *retrievedBackup.Properties.BaseBackups {
for _, baseBackup := range retrievedBackup.Properties.BaseBackups {
baseBackupEntry := make(map[string]interface{})
if baseBackup.Size != nil {
baseBackupEntry["size"] = *baseBackup.Size
Expand Down
16 changes: 7 additions & 9 deletions services/dbaas/mariadb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package mariadb
import (
"fmt"
"net/http"
"os"
"runtime"

"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
mariadb "github.com/ionos-cloud/sdk-go-dbaas-mariadb"
mariadb "github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mariadb/v2"
shared "github.com/ionos-cloud/sdk-go-bundle/shared"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
Expand All @@ -18,20 +18,18 @@ type MariaDBClient struct {
}

func NewMariaDBClient(username, password, token, url, version, terraformVersion string, insecure bool) *MariaDBClient {
newConfigDbaas := mariadb.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-mariadb/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s",
version, mariadb.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH)

return &MariaDBClient{
client := &MariaDBClient{
sdkClient: mariadb.NewAPIClient(newConfigDbaas),
}
client.sdkClient.GetConfig().HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}

return client
}
Loading
Loading