Skip to content
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
21 changes: 21 additions & 0 deletions docs/actions/rdb_database_backup_export_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_database_backup_export_action"
---

# scaleway_rdb_database_backup_export_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `backup_id` (String) Database backup ID to export. Can be a plain UUID or a regional ID.

### Optional

- `region` (String) The region you want to attach the resource to
- `wait` (Boolean) Wait for the export operation to complete before returning.



23 changes: 23 additions & 0 deletions docs/actions/rdb_database_backup_restore_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_database_backup_restore_action"
---

# scaleway_rdb_database_backup_restore_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `backup_id` (String) Database backup ID to restore. Can be a plain UUID or a regional ID.
- `instance_id` (String) RDB instance ID to restore the backup to. Can be a plain UUID or a regional ID.

### Optional

- `database_name` (String) Name of the database to restore. If not set, the original database name will be used.
- `region` (String) The region you want to attach the resource to
- `wait` (Boolean) Wait for the restore operation to complete before returning.



21 changes: 21 additions & 0 deletions docs/actions/rdb_instance_certificate_renew_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_instance_certificate_renew_action"
---

# scaleway_rdb_instance_certificate_renew_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `instance_id` (String) RDB instance ID to renew certificate for. Can be a plain UUID or a regional ID.

### Optional

- `region` (String) The region you want to attach the resource to
- `wait` (Boolean) Wait for the certificate renewal to complete before returning.



23 changes: 23 additions & 0 deletions docs/actions/rdb_instance_log_prepare_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_instance_log_prepare_action"
---

# scaleway_rdb_instance_log_prepare_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `instance_id` (String) RDB instance ID to prepare log for. Can be a plain UUID or a regional ID.

### Optional

- `end_date` (String) End datetime of the log in RFC3339 format (ISO 8601).
- `region` (String) The region you want to attach the resource to
- `start_date` (String) Start datetime of the log in RFC3339 format (ISO 8601).
- `wait` (Boolean) Wait for the log preparation to complete before returning.



20 changes: 20 additions & 0 deletions docs/actions/rdb_instance_logs_purge_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_instance_logs_purge_action"
---

# scaleway_rdb_instance_logs_purge_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `instance_id` (String) RDB instance ID to purge logs for. Can be a plain UUID or a regional ID.

### Optional

- `region` (String) The region you want to attach the resource to



23 changes: 23 additions & 0 deletions docs/actions/rdb_instance_snapshot_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_instance_snapshot_action"
---

# scaleway_rdb_instance_snapshot_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `instance_id` (String) RDB instance ID to snapshot. Can be a plain UUID or a regional ID.

### Optional

- `expires_at` (String) Expiration date of the snapshot in RFC3339 format (ISO 8601). If not set, the snapshot will not expire.
- `name` (String) Name of the snapshot. If not set, a name will be generated.
- `region` (String) The region you want to attach the resource to
- `wait` (Boolean) Wait for the snapshot to reach a terminal state before returning.



21 changes: 21 additions & 0 deletions docs/actions/rdb_read_replica_promote_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_read_replica_promote_action"
---

# scaleway_rdb_read_replica_promote_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `read_replica_id` (String) RDB read replica ID to promote. Can be a plain UUID or a regional ID.

### Optional

- `region` (String) The region you want to attach the resource to
- `wait` (Boolean) Wait for the read replica promotion to complete before returning.



21 changes: 21 additions & 0 deletions docs/actions/rdb_read_replica_reset_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
subcategory: "RDB"
page_title: "Scaleway: scaleway_rdb_read_replica_reset_action"
---

# scaleway_rdb_read_replica_reset_action (Action)

<!-- action schema generated by tfplugindocs -->
## Schema

### Required

- `read_replica_id` (String) RDB read replica ID to reset. Can be a plain UUID or a regional ID.

### Optional

- `region` (String) The region you want to attach the resource to
- `wait` (Boolean) Wait for the read replica to reach a terminal state before returning.



176 changes: 176 additions & 0 deletions internal/services/rdb/action_database_backup_export_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package rdb

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/action"
"github.com/hashicorp/terraform-plugin-framework/action/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
rdb "github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
)

var (
_ action.Action = (*DatabaseBackupExportAction)(nil)
_ action.ActionWithConfigure = (*DatabaseBackupExportAction)(nil)
)

// DatabaseBackupExportAction exports a database backup.
type DatabaseBackupExportAction struct {
rdbAPI *rdb.API
meta *meta.Meta
}

func (a *DatabaseBackupExportAction) Configure(_ context.Context, req action.ConfigureRequest, resp *action.ConfigureResponse) {
if req.ProviderData == nil {
return
}

m, ok := req.ProviderData.(*meta.Meta)
if !ok {
resp.Diagnostics.AddError(
"Unexpected Action Configure Type",
fmt.Sprintf("Expected *meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
}

a.meta = m
a.rdbAPI = newAPI(m)
}

func (a *DatabaseBackupExportAction) Metadata(_ context.Context, req action.MetadataRequest, resp *action.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_rdb_database_backup_export_action"
}

type DatabaseBackupExportActionModel struct {
BackupID types.String `tfsdk:"backup_id"`
Region types.String `tfsdk:"region"`
Wait types.Bool `tfsdk:"wait"`
}

// NewDatabaseBackupExportAction returns a new RDB database backup export action.
func NewDatabaseBackupExportAction() action.Action {
return &DatabaseBackupExportAction{}
}

func (a *DatabaseBackupExportAction) Schema(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"backup_id": schema.StringAttribute{
Required: true,
Description: "Database backup ID to export. Can be a plain UUID or a regional ID.",
},
"region": regional.SchemaAttribute(),
"wait": schema.BoolAttribute{
Optional: true,
Description: "Wait for the export operation to complete before returning.",
},
},
}
}

func (a *DatabaseBackupExportAction) Invoke(ctx context.Context, req action.InvokeRequest, resp *action.InvokeResponse) {
var data DatabaseBackupExportActionModel

resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

if resp.Diagnostics.HasError() {
return
}

if a.rdbAPI == nil {
resp.Diagnostics.AddError(
"Unconfigured rdbAPI",
"The action was not properly configured. The Scaleway client is missing. "+
"This is usually a bug in the provider. Please report it to the maintainers.",
)

return
}

if data.BackupID.IsNull() || data.BackupID.IsUnknown() || data.BackupID.ValueString() == "" {
resp.Diagnostics.AddError(
"Missing backup_id",
"The backup_id attribute is required to export a database backup.",
)

return
}

backupID := locality.ExpandID(data.BackupID.ValueString())

var region scw.Region

if !data.Region.IsNull() && !data.Region.IsUnknown() && data.Region.ValueString() != "" {
parsedRegion, err := scw.ParseRegion(data.Region.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Invalid region value",
fmt.Sprintf("The region attribute must be a valid Scaleway region. Got %q: %s", data.Region.ValueString(), err),
)

return
}

region = parsedRegion
} else {
if derivedRegion, id, parseErr := regional.ParseID(data.BackupID.ValueString()); parseErr == nil {
region = derivedRegion
backupID = id
} else if a.meta != nil {
defaultRegion, exists := a.meta.ScwClient().GetDefaultRegion()
if !exists {
resp.Diagnostics.AddError(
"Unable to determine region",
"Failed to get default region from provider configuration. Please set the region attribute, use a regional backup_id, or configure a default region in the provider.",
)

return
}

region = defaultRegion
}
}

if region == "" {
resp.Diagnostics.AddError(
"Missing region",
"Could not determine region for RDB database backup export. Please set the region attribute, use a regional backup_id, or configure a default region in the provider.",
)

return
}

exportReq := &rdb.ExportDatabaseBackupRequest{
Region: region,
DatabaseBackupID: backupID,
}

_, err := a.rdbAPI.ExportDatabaseBackup(exportReq, scw.WithContext(ctx))
if err != nil {
resp.Diagnostics.AddError(
"Error executing RDB ExportDatabaseBackup action",
fmt.Sprintf("Failed to export backup %s: %s", backupID, err),
)

return
}

if data.Wait.ValueBool() {
_, err = waitForRDBDatabaseBackup(ctx, a.rdbAPI, region, backupID, defaultInstanceTimeout)
if err != nil {
resp.Diagnostics.AddError(
"Error waiting for RDB database backup export completion",
fmt.Sprintf("Export operation for backup %s did not complete: %s", backupID, err),
)

return
}
}
}
Loading
Loading