Skip to content

Commit f826d8c

Browse files
authored
feat(rdb): add new actions (#3525)
* feat(rdb): add 8 new RDB actions with tests and documentation * compress RDB actions cassettes * docs: add RDB actions documentation
1 parent 3a9607b commit f826d8c

File tree

41 files changed

+12903
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+12903
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_database_backup_export_action"
4+
---
5+
6+
# scaleway_rdb_database_backup_export_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `backup_id` (String) Database backup ID to export. Can be a plain UUID or a regional ID.
14+
15+
### Optional
16+
17+
- `region` (String) The region you want to attach the resource to
18+
- `wait` (Boolean) Wait for the export operation to complete before returning.
19+
20+
21+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_database_backup_restore_action"
4+
---
5+
6+
# scaleway_rdb_database_backup_restore_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `backup_id` (String) Database backup ID to restore. Can be a plain UUID or a regional ID.
14+
- `instance_id` (String) RDB instance ID to restore the backup to. Can be a plain UUID or a regional ID.
15+
16+
### Optional
17+
18+
- `database_name` (String) Name of the database to restore. If not set, the original database name will be used.
19+
- `region` (String) The region you want to attach the resource to
20+
- `wait` (Boolean) Wait for the restore operation to complete before returning.
21+
22+
23+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_instance_certificate_renew_action"
4+
---
5+
6+
# scaleway_rdb_instance_certificate_renew_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `instance_id` (String) RDB instance ID to renew certificate for. Can be a plain UUID or a regional ID.
14+
15+
### Optional
16+
17+
- `region` (String) The region you want to attach the resource to
18+
- `wait` (Boolean) Wait for the certificate renewal to complete before returning.
19+
20+
21+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_instance_log_prepare_action"
4+
---
5+
6+
# scaleway_rdb_instance_log_prepare_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `instance_id` (String) RDB instance ID to prepare log for. Can be a plain UUID or a regional ID.
14+
15+
### Optional
16+
17+
- `end_date` (String) End datetime of the log in RFC3339 format (ISO 8601).
18+
- `region` (String) The region you want to attach the resource to
19+
- `start_date` (String) Start datetime of the log in RFC3339 format (ISO 8601).
20+
- `wait` (Boolean) Wait for the log preparation to complete before returning.
21+
22+
23+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_instance_logs_purge_action"
4+
---
5+
6+
# scaleway_rdb_instance_logs_purge_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `instance_id` (String) RDB instance ID to purge logs for. Can be a plain UUID or a regional ID.
14+
15+
### Optional
16+
17+
- `region` (String) The region you want to attach the resource to
18+
19+
20+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_instance_snapshot_action"
4+
---
5+
6+
# scaleway_rdb_instance_snapshot_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `instance_id` (String) RDB instance ID to snapshot. Can be a plain UUID or a regional ID.
14+
15+
### Optional
16+
17+
- `expires_at` (String) Expiration date of the snapshot in RFC3339 format (ISO 8601). If not set, the snapshot will not expire.
18+
- `name` (String) Name of the snapshot. If not set, a name will be generated.
19+
- `region` (String) The region you want to attach the resource to
20+
- `wait` (Boolean) Wait for the snapshot to reach a terminal state before returning.
21+
22+
23+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_read_replica_promote_action"
4+
---
5+
6+
# scaleway_rdb_read_replica_promote_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `read_replica_id` (String) RDB read replica ID to promote. Can be a plain UUID or a regional ID.
14+
15+
### Optional
16+
17+
- `region` (String) The region you want to attach the resource to
18+
- `wait` (Boolean) Wait for the read replica promotion to complete before returning.
19+
20+
21+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
subcategory: "RDB"
3+
page_title: "Scaleway: scaleway_rdb_read_replica_reset_action"
4+
---
5+
6+
# scaleway_rdb_read_replica_reset_action (Action)
7+
8+
<!-- action schema generated by tfplugindocs -->
9+
## Schema
10+
11+
### Required
12+
13+
- `read_replica_id` (String) RDB read replica ID to reset. Can be a plain UUID or a regional ID.
14+
15+
### Optional
16+
17+
- `region` (String) The region you want to attach the resource to
18+
- `wait` (Boolean) Wait for the read replica to reach a terminal state before returning.
19+
20+
21+
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package rdb
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-framework/action"
8+
"github.com/hashicorp/terraform-plugin-framework/action/schema"
9+
"github.com/hashicorp/terraform-plugin-framework/types"
10+
rdb "github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
11+
"github.com/scaleway/scaleway-sdk-go/scw"
12+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
13+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
15+
)
16+
17+
var (
18+
_ action.Action = (*DatabaseBackupExportAction)(nil)
19+
_ action.ActionWithConfigure = (*DatabaseBackupExportAction)(nil)
20+
)
21+
22+
// DatabaseBackupExportAction exports a database backup.
23+
type DatabaseBackupExportAction struct {
24+
rdbAPI *rdb.API
25+
meta *meta.Meta
26+
}
27+
28+
func (a *DatabaseBackupExportAction) Configure(_ context.Context, req action.ConfigureRequest, resp *action.ConfigureResponse) {
29+
if req.ProviderData == nil {
30+
return
31+
}
32+
33+
m, ok := req.ProviderData.(*meta.Meta)
34+
if !ok {
35+
resp.Diagnostics.AddError(
36+
"Unexpected Action Configure Type",
37+
fmt.Sprintf("Expected *meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData),
38+
)
39+
40+
return
41+
}
42+
43+
a.meta = m
44+
a.rdbAPI = newAPI(m)
45+
}
46+
47+
func (a *DatabaseBackupExportAction) Metadata(_ context.Context, req action.MetadataRequest, resp *action.MetadataResponse) {
48+
resp.TypeName = req.ProviderTypeName + "_rdb_database_backup_export_action"
49+
}
50+
51+
type DatabaseBackupExportActionModel struct {
52+
BackupID types.String `tfsdk:"backup_id"`
53+
Region types.String `tfsdk:"region"`
54+
Wait types.Bool `tfsdk:"wait"`
55+
}
56+
57+
// NewDatabaseBackupExportAction returns a new RDB database backup export action.
58+
func NewDatabaseBackupExportAction() action.Action {
59+
return &DatabaseBackupExportAction{}
60+
}
61+
62+
func (a *DatabaseBackupExportAction) Schema(_ context.Context, _ action.SchemaRequest, resp *action.SchemaResponse) {
63+
resp.Schema = schema.Schema{
64+
Attributes: map[string]schema.Attribute{
65+
"backup_id": schema.StringAttribute{
66+
Required: true,
67+
Description: "Database backup ID to export. Can be a plain UUID or a regional ID.",
68+
},
69+
"region": regional.SchemaAttribute(),
70+
"wait": schema.BoolAttribute{
71+
Optional: true,
72+
Description: "Wait for the export operation to complete before returning.",
73+
},
74+
},
75+
}
76+
}
77+
78+
func (a *DatabaseBackupExportAction) Invoke(ctx context.Context, req action.InvokeRequest, resp *action.InvokeResponse) {
79+
var data DatabaseBackupExportActionModel
80+
81+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
82+
83+
if resp.Diagnostics.HasError() {
84+
return
85+
}
86+
87+
if a.rdbAPI == nil {
88+
resp.Diagnostics.AddError(
89+
"Unconfigured rdbAPI",
90+
"The action was not properly configured. The Scaleway client is missing. "+
91+
"This is usually a bug in the provider. Please report it to the maintainers.",
92+
)
93+
94+
return
95+
}
96+
97+
if data.BackupID.IsNull() || data.BackupID.IsUnknown() || data.BackupID.ValueString() == "" {
98+
resp.Diagnostics.AddError(
99+
"Missing backup_id",
100+
"The backup_id attribute is required to export a database backup.",
101+
)
102+
103+
return
104+
}
105+
106+
backupID := locality.ExpandID(data.BackupID.ValueString())
107+
108+
var region scw.Region
109+
110+
if !data.Region.IsNull() && !data.Region.IsUnknown() && data.Region.ValueString() != "" {
111+
parsedRegion, err := scw.ParseRegion(data.Region.ValueString())
112+
if err != nil {
113+
resp.Diagnostics.AddError(
114+
"Invalid region value",
115+
fmt.Sprintf("The region attribute must be a valid Scaleway region. Got %q: %s", data.Region.ValueString(), err),
116+
)
117+
118+
return
119+
}
120+
121+
region = parsedRegion
122+
} else {
123+
if derivedRegion, id, parseErr := regional.ParseID(data.BackupID.ValueString()); parseErr == nil {
124+
region = derivedRegion
125+
backupID = id
126+
} else if a.meta != nil {
127+
defaultRegion, exists := a.meta.ScwClient().GetDefaultRegion()
128+
if !exists {
129+
resp.Diagnostics.AddError(
130+
"Unable to determine region",
131+
"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.",
132+
)
133+
134+
return
135+
}
136+
137+
region = defaultRegion
138+
}
139+
}
140+
141+
if region == "" {
142+
resp.Diagnostics.AddError(
143+
"Missing region",
144+
"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.",
145+
)
146+
147+
return
148+
}
149+
150+
exportReq := &rdb.ExportDatabaseBackupRequest{
151+
Region: region,
152+
DatabaseBackupID: backupID,
153+
}
154+
155+
_, err := a.rdbAPI.ExportDatabaseBackup(exportReq, scw.WithContext(ctx))
156+
if err != nil {
157+
resp.Diagnostics.AddError(
158+
"Error executing RDB ExportDatabaseBackup action",
159+
fmt.Sprintf("Failed to export backup %s: %s", backupID, err),
160+
)
161+
162+
return
163+
}
164+
165+
if data.Wait.ValueBool() {
166+
_, err = waitForRDBDatabaseBackup(ctx, a.rdbAPI, region, backupID, defaultInstanceTimeout)
167+
if err != nil {
168+
resp.Diagnostics.AddError(
169+
"Error waiting for RDB database backup export completion",
170+
fmt.Sprintf("Export operation for backup %s did not complete: %s", backupID, err),
171+
)
172+
173+
return
174+
}
175+
}
176+
}

0 commit comments

Comments
 (0)