Skip to content

Commit

Permalink
feat: Implement 'update' method for MariaDB clusters (#718)
Browse files Browse the repository at this point in the history
adeatcu-ionos authored Nov 29, 2024
1 parent 78750ad commit 7135aaf
Showing 17 changed files with 1,590 additions and 152 deletions.
58 changes: 30 additions & 28 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## 6.6.5 -- upcoming release
### Features
- Resource `ionoscloud_mariadb_cluster` now supports updates
### Testing
- Add import tests for MariaDB clusters

@@ -188,7 +190,7 @@
- Add s3 bucket, object, policy resources with base functionality
### Enhancements
- Move to `sdk-go-bundle` for logging sdk
### Fixes
### Fixes
- Fixes #607. Container registry should wait until the resource is ready before returning the ID.
- Move tests from AMD_OPTERON to INTEL_XEON
- Data source `ionoscloud_mongo_template` should have id `computed` and `optional`
@@ -226,7 +228,7 @@
- Fix documentation for `ionoscloud_server`, `ionoscloud_volume`, `ionoscloud_lan` resources and `ionoscloud_image` data sources

### Enhancements
- Add configurable fields to `ionoscloud_share` resource. Fields that can be set on creation: `description`, `sec_auth_protection`, `licence_type`.
- Add configurable fields to `ionoscloud_share` resource. Fields that can be set on creation: `description`, `sec_auth_protection`, `licence_type`.
Updatable fields: `description`, `licence_type`, `nic_hot_plug`, `cpu_hot_plug`, `nic_hot_unplug`, `disc_virtio_hot_plug`, `disc_virtio_hot_unplug`, `ram_hot_plug`.
- Allow MariaDB cluster creation in other zones than `de/txl` by adding `location` parameter to resources and data sources

@@ -324,7 +326,7 @@ Updatable fields: `description`, `licence_type`, `nic_hot_plug`, `cpu_hot_plug`,
- #412 add support to set power state of Enterprise and Cube servers, by adding the new field `vm_state` in `ionoscloud_server`, `ionoscloud_cube_server` and `ionoscloud_vcpu_server `resources
### Fixes
- #467 removing an inline `nic` of the `server` resource from dcd should not throw 404 when running plan or apply after
- #432 Now it is possible to create and delete multiple `ionoscloud_ipfailover` resources at the same time. The UUID is generated based on the IP of the
- #432 Now it is possible to create and delete multiple `ionoscloud_ipfailover` resources at the same time. The UUID is generated based on the IP of the
failover group. The resources that are created using Terraform cannot be modified/deleted outside Terraform.
- Fix `nil` deref error on list for nic datasource
- #470 fix image name searching in `ionoscloud_image` and `ionoscloud_volume`. Exact matches are returned correctly now if they exist.
@@ -394,7 +396,7 @@ failover group. The resources that are created using Terraform cannot be modifie

## 6.4.2
### Fixes
- Fix `ssh_keys` field upgrade `ionoscloud_server` from `6.3.3` to higher versions should not replace server. `ssh_keys` and `ssh_key_path` fields no longer forceNew.
- Fix `ssh_keys` field upgrade `ionoscloud_server` from `6.3.3` to higher versions should not replace server. `ssh_keys` and `ssh_key_path` fields no longer forceNew.
`ssh_keys` is no longer computed.
- Fix `ssh_keys` suppress diff on upgrade for `ionoscloud_server` when having `volume.0.ssh_keys`
- Add validation to `label` `key` and `value` fields for `ionoscloud_server` resource
@@ -508,7 +510,7 @@ Please contact your sales representative or support for more information.
- [ionoscloud_container_registry](docs/data-sources/container_registry.md)
- [ionoscloud_container_registry_token](docs/data-sources/container_registry_token.md)
- [ionoscloud_container_registry_locations](docs/data-sources/container_registry_locations.md)

⚠️ **Note:** Container Registry is currently in the Early Access (EA) phase. We recommend keeping usage and testing to non-production critical applications.
Please contact your sales representative or support for more information.
### Fixes
@@ -543,7 +545,7 @@ Please contact your sales representative or support for more information.
- `ssh_key_path` will now allow the keys to be passed directly also. In the future, will be renamed to `ssh_keys`.

### Fixes
- Reproduces rarely: sometimes the `nic` resource is not found after creation. As a fix we added a retry for 5 minutes to be able to get the NIC. The retry will keep trying if the response
- Reproduces rarely: sometimes the `nic` resource is not found after creation. As a fix we added a retry for 5 minutes to be able to get the NIC. The retry will keep trying if the response
is `not found`(404)
- Fix cube server creation. Some attributes were not populated - name, boot_cdrom, availability_zone
- Crash on update of k8s version when we have a value without `.`
@@ -579,12 +581,12 @@ is `not found`(404)

## 6.2.5
### Enhancement
- Update sdk-go dependency to v6.0.3.
- Update sdk-go dependency to v6.0.3.
* enable certificate pinning, by setting IONOS_PINNED_CERT env variable
- Temporarily removed `gateway_ip` and `public` fields for k8s
- Introduced error when trying to set `max_node_count` equal to `min_node_count` in `k8s_node_pool`

### Fixes
### Fixes
- Crash when trying to disable `autoscaling` on `k8s_node_pool`

## 6.2.4
@@ -617,7 +619,7 @@ is `not found`(404)
## 6.2.1

### Documentation
- Improved all the examples to be ready to use
- Improved all the examples to be ready to use
- Added units where missing
- Added example for adding a secondary NIC to an IP Failover
- Updated provider version to the latest release in main registry page
@@ -631,17 +633,17 @@ is `not found`(404)
- Update terraform-plugin-sdk to v2.12.0
- Token and username+password does not conflict anymore, all three can be set, the token having priority

### Features
### Features
- Added `backup_location` property for `ionoscloud_pg_cluster`. For more details refer to the [documentation](docs/resources/dbaas_pgsql_cluster.md)

### Fixes
- Fixed image data-source bug when `name` not provided - data-source returned 0 results
- When you try to change an immutable field, you get an error, but before that the tf state is changed.
Before applying a real change you need to `apply` it back with an error again.
- When you try to change an immutable field, you get an error, but before that the tf state is changed.
Before applying a real change you need to `apply` it back with an error again.
To fix, when you try to change immutable fields they will throw an error in the plan phase.
- Reintroduced in group resource the `user_id` argument, as deprecated, to provide a period of transition
- Check slice length to prevent crash
- Fixed k8s_cluster data_source bug when searching by name
- Fixed k8s_cluster data_source bug when searching by name
- Fix lan deletion error, when trying to delete it immediately after the deletion of the DBaaS cluster that contained it

## 6.2.0
@@ -671,16 +673,16 @@ To fix, when you try to change immutable fields they will throw an error in the

### Enhancements:
- Improved lookup in data_sources by using filters
- Improved tests duration by moving steps from data_source test files in the corresponding resource test files
- Added workflow to run tests from GitHub actions
- Improved tests duration by moving steps from data_source test files in the corresponding resource test files
- Added workflow to run tests from GitHub actions
- Split tests with build tags
- Improve http client performance and timeouts

### Documentations:
### Documentations:
- A more accurate example on how can the cidr be set automatically on a DBaaS Cluster
- Update doc of how to dump kube_config into a file in yaml format.

### Fixes:
### Fixes:
- Fix on creating a DBaaS Cluster without specifying the maintenance window
- Solve #204 - targets in nlb forwarding rule(switched to Set instead of List), lb_private_ips(set to computed), features in datacenter resources(switched to Set instead of List)
- Fix of plugin crash when updating k8s_node_pool node_count
@@ -710,13 +712,13 @@ To fix, when you try to change immutable fields they will throw an error in the
## 6.1.1

### Docs:
- Fix documentation in terraform registry
- Fix documentation in terraform registry

## 6.1.0

### Features:
- New Product: **Database as a Service**:
- Resources:
- New Product: **Database as a Service**:
- Resources:
- resource_dbaas_pgsql_cluster
- Data Sources:
- data_source_dbaas_pgsql_backups
@@ -752,7 +754,7 @@ To fix, when you try to change immutable fields they will throw an error in the

## 6.0.1

### Fixes:
### Fixes:
- Fixed rebuild k8 nodes with the same lan - order of lans is ignored now at diff
- Fixed conversion coming from a v5 state - added nil check in lans interface conversion

@@ -810,7 +812,7 @@ To fix, when you try to change immutable fields they will throw an error in the
- made tests comprehensive
- optimized test duration by including both match by id and by name in the same test
- removed duplicated code from import, data_source and resource files (set parameters)

## 6.0.0-beta.12
### Fixes:
- `server`: can not create cube server, firewall not updated
@@ -882,7 +884,7 @@ To fix, when you try to change immutable fields they will throw an error in the

## 6.0.0-beta.2

- Updated dependencies
- Updated dependencies
- Updated server, nic and volume resources with the missing arguments

## 6.0.0-beta.1
@@ -928,21 +930,21 @@ To fix, when you try to change immutable fields they will throw an error in the

## 5.1.4

- Error handling improvements
- Error handling improvements
- Always displaying the full response body from the API in case of an error

## 5.1.3

- Bug fix: correctly checking for nil the image volume
- Bug fix: correctly checking for nil the image volume

## 5.1.2

- Bug fix: avoid sending an empty image password to the API if
- Bug fix: avoid sending an empty image password to the API if
no image password is set

## 5.1.1

- Bug fix: nil check for image password when creating a server
- Bug fix: nil check for image password when creating a server

## 5.1.0

@@ -963,7 +965,7 @@ FEATURES:

BUG FIXES:

- Correctly updating ips on a nic embedded in a server config
- Correctly updating ips on a nic embedded in a server config

## 5.0.1

2 changes: 1 addition & 1 deletion docs/resources/dbaas_mariadb_cluster.md
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ resource "random_password" "cluster_password" {

## Argument reference

* `mariadb_version` - (Required)[string] The MariaDB version of your cluster.
* `mariadb_version` - (Required)[string] The MariaDB version of your cluster. Cannot be downgraded.
* `instances` - (Required)[int] The total number of instances in the cluster (one primary and n-1 secondary).
* `location`- (Optional)[string] The location in which the cluster will be created. Different service endpoints are used based on location, possible options are: "de/fra", "de/txl", "es/vit", "fr/par", "gb/lhr", "us/ewr", "us/las", "us/mci". If not set, the endpoint will be the one corresponding to "de/txl".
* `cores` - (Required)[int] The number of CPU cores per instance.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ require (
github.com/ionos-cloud/sdk-go-container-registry v1.2.0
github.com/ionos-cloud/sdk-go-dataplatform v1.0.3
github.com/ionos-cloud/sdk-go-dbaas-in-memory-db v1.0.1
github.com/ionos-cloud/sdk-go-dbaas-mariadb 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
@@ -69,7 +69,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/hc-install v0.8.0 // indirect
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -130,8 +130,8 @@ github.com/ionos-cloud/sdk-go-dataplatform v1.0.3 h1:eaZITgPaLHbK4d/nVaImvP19a5y
github.com/ionos-cloud/sdk-go-dataplatform v1.0.3/go.mod h1:LXJGnUwLLiJhKgApv7TIPGy7WOuGbYIzBPFxGpNfqN0=
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.0.1 h1:EBsHfY/Bt7CcSsP7W7ohVsnhFAtMEcil3Aa/Q5MBq/Y=
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.0.1/go.mod h1:627dsH56YGQD7x0g2FGdVsxNtBySvQ3QU0uG+d6/Evk=
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=
56 changes: 51 additions & 5 deletions ionoscloud/resource_dbaas_mariadb_cluster.go
Original file line number Diff line number Diff line change
@@ -8,15 +8,15 @@ import (
"strings"
"time"

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

semversion "github.com/hashicorp/go-version"
"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"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dbaas/mariadb"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
)

func resourceDBaaSMariaDBCluster() *schema.Resource {
@@ -28,11 +28,13 @@ func resourceDBaaSMariaDBCluster() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: mariaDBClusterImport,
},
CustomizeDiff: errorOnVersionDowngrade,
Schema: map[string]*schema.Schema{
"mariadb_version": {
Type: schema.TypeString,
Description: "The MariaDB version of your cluster.",
Required: true,
Type: schema.TypeString,
Description: "The MariaDB version of your cluster. Cannot be downgraded.",
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotEmpty),
},
"location": {
Type: schema.TypeString,
@@ -153,6 +155,30 @@ func resourceDBaaSMariaDBCluster() *schema.Resource {
}
}

func errorOnVersionDowngrade(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
// we do not want to check in case of resource creation
if diff.Id() == "" {
return nil
}
if diff.HasChange("mariadb_version") {
oldValue, newValue := diff.GetChange("mariadb_version")
oldVersionStr := oldValue.(string)
newVersionStr := newValue.(string)
oldVersion, err := semversion.NewVersion(oldVersionStr)
if err != nil {
return err
}
newVersion, err := semversion.NewVersion(newVersionStr)
if err != nil {
return err
}
if newVersion.LessThan(oldVersion) {
return fmt.Errorf("downgrade is not supported from %s to %s", oldVersionStr, newVersionStr)
}
}
return nil
}

func mariaDBClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(services.SdkBundle).MariaDBClient

@@ -254,5 +280,25 @@ func mariaDBClusterRead(ctx context.Context, d *schema.ResourceData, meta interf
}

func mariaDBClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(services.SdkBundle).MariaDBClient

clusterID := d.Id()
cluster, err := mariadb.GetMariaDBClusterDataUpdate(d)
if err != nil {
return diag.FromErr(err)
}
location := d.Get("location").(string)
response, _, err := client.UpdateCluster(ctx, *cluster, clusterID, location)
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while updating DBaaS MariaDB cluster with ID: %v in location %s, error: %w", clusterID, location, err))
}

err = utils.WaitForResourceToBeReady(ctx, d, client.IsClusterReady)
if err != nil {
return diag.FromErr(fmt.Errorf("error occurred while checking the status for MariaDB cluster with ID: %v in location %s, error: %w", clusterID, location, err))
}
if err := client.SetMariaDBClusterData(d, response); err != nil {
return diag.FromErr(err)
}
return nil
}
Loading

0 comments on commit 7135aaf

Please sign in to comment.