Skip to content

Commit

Permalink
[3.1.1] AWS GP3 and Throughput support
Browse files Browse the repository at this point in the history
  • Loading branch information
vasiliyskysql committed Jul 16, 2024
1 parent 5e98c0a commit e45b9c7
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [3.1.1] - 2024-07-16
### Fixed
- `gp3` volume type support for AWS.
- `volume_throughput` support for AWS GP3 storage volume type.

## [3.1.0] - 2024-07-15
### Features
- `azure` provider is now supported.
Expand Down
5 changes: 3 additions & 2 deletions docs/resources/skysql_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ resource "skysql_service" "default" {
storage = 100
ssl_enabled = true
version = data.skysql_versions.default.versions[0].name
volume_type = "gp2"
volume_type = "gp3"
# The service create is an asynchronous operation.
# if you want to wait for the service to be created set wait_for_creation to true
wait_for_creation = true
Expand Down Expand Up @@ -66,7 +66,8 @@ resource "skysql_service" "default" {
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `version` (String) The software version
- `volume_iops` (Number) The volume IOPS. This is only applicable for AWS
- `volume_type` (String) The volume type. Valid values are: gp2 and io1. This is only applicable for AWS
- `volume_throughput` (Number) The volume throughput. This is only applicable for AWS
- `volume_type` (String) The volume type. Valid values are: gp3, gp2 and io1. This is only applicable for AWS
- `wait_for_creation` (Boolean) Whether to wait for the service to be created. Valid values are: true or false
- `wait_for_deletion` (Boolean) Whether to wait for the service to be deleted. Valid values are: true or false
- `wait_for_update` (Boolean) Whether to wait for the service to be updated. Valid values are: true or false
Expand Down
2 changes: 1 addition & 1 deletion examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ resource "skysql_service" "default" {
storage = 100
ssl_enabled = true
version = data.skysql_versions.default.versions[0].name
volume_type = "gp2"
volume_type = "gp3"
allow_list = [
{
"ip" : "127.0.0.1/32",
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/skysql_service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource "skysql_service" "default" {
storage = 100
ssl_enabled = true
version = data.skysql_versions.default.versions[0].name
volume_type = "gp2"
volume_type = "gp3"
# The service create is an asynchronous operation.
# if you want to wait for the service to be created set wait_for_creation to true
wait_for_creation = true
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/service_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type StorageVolumeDataSourceModel struct {
Size types.Int64 `tfsdk:"size"`
VolumeType types.String `tfsdk:"volume_type"`
IOPS types.Int64 `tfsdk:"iops"`
Throughput types.Int64 `tfsdk:"throughput"`
}

func (d *ServiceDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
Expand Down Expand Up @@ -318,6 +319,7 @@ func (d *ServiceDataSource) Read(ctx context.Context, req datasource.ReadRequest
Size: types.Int64Value(int64(service.StorageVolume.Size)),
VolumeType: types.StringValue(service.StorageVolume.VolumeType),
IOPS: types.Int64Value(int64(service.StorageVolume.IOPS)),
Throughput: types.Int64Value(int64(service.StorageVolume.Throughput)),
}

data.OutboundIps = make([]types.String, len(service.OutboundIps))
Expand Down
30 changes: 22 additions & 8 deletions internal/provider/service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ServiceResourceModel struct {
SSLEnabled types.Bool `tfsdk:"ssl_enabled"`
NoSQLEnabled types.Bool `tfsdk:"nosql_enabled"`
VolumeType types.String `tfsdk:"volume_type"`
VolumeThroughput types.Int64 `tfsdk:"volume_throughput"`
WaitForCreation types.Bool `tfsdk:"wait_for_creation"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
Mechanism types.String `tfsdk:"endpoint_mechanism"`
Expand Down Expand Up @@ -241,7 +242,7 @@ var serviceResourceSchemaV0 = schema.Schema{
"volume_type": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "The volume type. Valid values are: gp2 and io1. This is only applicable for AWS",
Description: "The volume type. Valid values are: gp3, gp2, and io1. This is only applicable for AWS",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplaceIf(
Expand Down Expand Up @@ -452,6 +453,7 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
Topology: state.Topology.ValueString(),
Storage: uint(state.Storage.ValueInt64()),
VolumeIOPS: uint(state.VolumeIOPS.ValueInt64()),
VolumeThroughput: uint(state.VolumeThroughput.ValueInt64()),
SSLEnabled: state.SSLEnabled.ValueBool(),
NoSQLEnabled: state.NoSQLEnabled.ValueBool(),
VolumeType: state.VolumeType.ValueString(),
Expand Down Expand Up @@ -523,6 +525,11 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
} else {
state.VolumeIOPS = types.Int64Null()
}
if service.StorageVolume.Throughput > 0 {
state.VolumeThroughput = types.Int64Value(int64(service.StorageVolume.Throughput))
} else {
state.VolumeThroughput = types.Int64Null()
}
if service.StorageVolume.VolumeType != "" {
state.VolumeType = types.StringValue(service.StorageVolume.VolumeType)
} else {
Expand Down Expand Up @@ -679,6 +686,11 @@ func (r *ServiceResource) readServiceState(ctx context.Context, data *ServiceRes
} else {
data.VolumeIOPS = types.Int64Null()
}
if !data.VolumeThroughput.IsNull() && service.StorageVolume.Throughput > 0 {
data.VolumeThroughput = types.Int64Value(int64(service.StorageVolume.Throughput))
} else {
data.VolumeThroughput = types.Int64Null()
}
data.VolumeType = types.StringValue(service.StorageVolume.VolumeType)
if !data.ReplicationEnabled.IsNull() {
data.ReplicationEnabled = types.BoolValue(service.ReplicationEnabled)
Expand Down Expand Up @@ -805,16 +817,18 @@ func (r *ServiceResource) updateAllowListState(plan *ServiceResourceModel, state
}

func (r *ServiceResource) updateServiceStorage(ctx context.Context, plan *ServiceResourceModel, state *ServiceResourceModel, resp *resource.UpdateResponse) {
if plan.Storage.ValueInt64() != state.Storage.ValueInt64() || plan.VolumeIOPS.ValueInt64() != state.VolumeIOPS.ValueInt64() {
if plan.Storage.ValueInt64() != state.Storage.ValueInt64() || plan.VolumeIOPS.ValueInt64() != state.VolumeIOPS.ValueInt64() || plan.VolumeThroughput.ValueInt64() != state.VolumeThroughput.ValueInt64() {
tflog.Info(ctx, "Updating storage size for the service", map[string]interface{}{
"id": state.ID.ValueString(),
"from": state.Storage.ValueInt64(),
"to": plan.Storage.ValueInt64(),
"iops_from": state.VolumeIOPS.ValueInt64(),
"iops_to": plan.VolumeIOPS.ValueInt64(),
"id": state.ID.ValueString(),
"from": state.Storage.ValueInt64(),
"to": plan.Storage.ValueInt64(),
"iops_from": state.VolumeIOPS.ValueInt64(),
"iops_to": plan.VolumeIOPS.ValueInt64(),
"throughput_from": state.VolumeThroughput.ValueInt64(),
"throughput_to": plan.VolumeThroughput.ValueInt64(),
})

err := r.client.ModifyServiceStorage(ctx, state.ID.ValueString(), plan.Storage.ValueInt64(), plan.VolumeIOPS.ValueInt64())
err := r.client.ModifyServiceStorage(ctx, state.ID.ValueString(), plan.Storage.ValueInt64(), plan.VolumeIOPS.ValueInt64(), plan.VolumeThroughput.ValueInt64())
if err != nil {
resp.Diagnostics.AddError("Error updating a storage for the service",
fmt.Sprintf("Unable to update a storage size for the service, got error: %s", err))
Expand Down
1 change: 1 addition & 0 deletions internal/provider/service_resource_scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestServiceResourceScaleTest(t *testing.T) {
Size int `json:"size"`
VolumeType string `json:"volume_type"`
IOPS int `json:"iops"`
Throughput int `json:"throughput"`
}{
Size: int(payload.Storage),
VolumeType: payload.VolumeType,
Expand Down
4 changes: 2 additions & 2 deletions internal/skysql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ func (c *Client) ModifyServiceNodeNumber(ctx context.Context, serviceID string,
return err
}

func (c *Client) ModifyServiceStorage(ctx context.Context, serviceID string, size int64, iops int64) error {
func (c *Client) ModifyServiceStorage(ctx context.Context, serviceID string, size int64, iops int64, throughput int64) error {
resp, err := c.HTTPClient.R().
SetHeader("Accept", "application/json").
SetContext(ctx).
SetBody(&provisioning.UpdateStorageRequest{Size: size, IOPS: iops}).
SetBody(&provisioning.UpdateStorageRequest{Size: size, IOPS: iops, Throughput: throughput}).
SetError(&ErrorResponse{}).
Patch("/provisioning/v1/services/" + serviceID + "/storage")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/skysql/provisioning/create_service_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type CreateServiceRequest struct {
SSLEnabled bool `json:"ssl_enabled"`
NoSQLEnabled bool `json:"nosql_enabled"`
VolumeType string `json:"volume_type,omitempty"`
VolumeThroughput uint `json:"volume_throughput,omitempty"`
AllowedAccounts []string `json:"endpoint_allowed_accounts,omitempty"`
Mechanism string `json:"endpoint_mechanism,omitempty"`
ReplicationEnabled bool `json:"replication_enabled,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions internal/skysql/provisioning/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Service struct {
Size int `json:"size"`
VolumeType string `json:"volume_type"`
IOPS int `json:"iops"`
Throughput int `json:"throughput"`
} `json:"storage_volume"`
OutboundIps []string `json:"outbound_ips"`
IsActive bool `json:"is_active"`
Expand Down
5 changes: 3 additions & 2 deletions internal/skysql/provisioning/update_storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provisioning

type UpdateStorageRequest struct {
Size int64 `json:"size,omitempty"`
IOPS int64 `json:"iops,omitempty"`
Size int64 `json:"size,omitempty"`
IOPS int64 `json:"iops,omitempty"`
Throughput int64 `json:"throughput,omitempty"`
}

0 comments on commit e45b9c7

Please sign in to comment.