Skip to content

Commit 41d8a19

Browse files
authored
[CLOUDGA-31264] Add use_roles to backup resource and backup schedules (#187)
Co-authored-by: pranavbansal <Pranav Bansal> Add optional use_roles to back up global YSQL roles. - ybm_backup: add use_roles attribute (optional, computed). Set on BackupSpec in Create; read from API in Read (default false when omitted). - ybm_cluster backup_schedules: add use_roles to block. Set on ScheduleSpecV2 in editBackupScheduleV2; read in readBackupScheduleInfoV2 (default false when omitted). - models: add UseRoles to Backup and BackupScheduleInfo. - docs: document use_roles for backup and cluster resources.
1 parent d2ea4e9 commit 41d8a19

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

docs/resources/backup.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ resource "ybm_backup" "example_backup" {
3535
- `backup_id` (String) The ID of the backup. Created automatically when the backup is created. Used to get a specific backup.
3636
- `most_recent` (Boolean) Set to true to fetch the most recent backup.
3737
- `timestamp` (String) The timestamp of the backup to be fetched
38+
- `use_roles` (Boolean) Backup global YSQL roles. Defaults to false.
3839

3940
### Read-Only
4041

docs/resources/cluster.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ Optional:
11931193
- `schedule_id` (String) The ID of the backup schedule. Created automatically when the backup schedule is created. Used to get a specific backup schedule.
11941194
- `state` (String) The state of the backup schedule. Used to pause or resume the backup schedule. Valid values are ACTIVE or PAUSED.
11951195
- `time_interval_in_days` (Number) The time interval in days for the backup schedule.
1196+
- `use_roles` (Boolean) Backup global YSQL roles in scheduled backups. Defaults to false.
11961197

11971198

11981199
<a id="nestedatt--cmk_spec"></a>

managed/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type BackupScheduleInfo struct {
9494
CronExpression types.String `tfsdk:"cron_expression"`
9595
TimeIntervalInDays types.Int64 `tfsdk:"time_interval_in_days"`
9696
IncrementalIntervalInMins types.Int64 `tfsdk:"incremental_interval_in_mins"`
97+
UseRoles types.Bool `tfsdk:"use_roles"`
9798
}
9899
type RegionInfo struct {
99100
Region types.String `tfsdk:"region"`
@@ -217,6 +218,7 @@ type Backup struct {
217218
RetentionPeriodInDays types.Int64 `tfsdk:"retention_period_in_days"`
218219
MostRecent types.Bool `tfsdk:"most_recent"`
219220
Timestamp types.String `tfsdk:"timestamp"`
221+
UseRoles types.Bool `tfsdk:"use_roles"`
220222
}
221223

222224
type VPC struct {

managed/resource_backup.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func (r resourceBackupType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia
6767
Type: types.StringType,
6868
Optional: true,
6969
},
70+
"use_roles": {
71+
Description: "Backup global YSQL roles. Defaults to false.",
72+
Type: types.BoolType,
73+
Optional: true,
74+
Computed: true,
75+
},
7076
},
7177
}, nil
7278
}
@@ -92,6 +98,7 @@ func getBackupPlan(ctx context.Context, plan tfsdk.Plan, backup *Backup) diag.Di
9298
diags.Append(plan.GetAttribute(ctx, path.Root("backup_id"), &backup.BackupID)...)
9399
diags.Append(plan.GetAttribute(ctx, path.Root("backup_description"), &backup.BackupDescription)...)
94100
diags.Append(plan.GetAttribute(ctx, path.Root("retention_period_in_days"), &backup.RetentionPeriodInDays)...)
101+
diags.Append(plan.GetAttribute(ctx, path.Root("use_roles"), &backup.UseRoles)...)
95102

96103
return diags
97104
}
@@ -147,6 +154,10 @@ func (r resourceBackup) Create(ctx context.Context, req tfsdk.CreateResourceRequ
147154
backupSpec.SetDescription(backupDescription)
148155
backupSpec.RetentionPeriodInDays = &backupRetentionPeriodInDays
149156

157+
if !plan.UseRoles.IsNull() && !plan.UseRoles.IsUnknown() {
158+
backupSpec.SetUseRoles(plan.UseRoles.Value)
159+
}
160+
150161
backupResp, response, err := apiClient.BackupApi.CreateBackup(context.Background(), accountId, projectId).BackupSpec(backupSpec).Execute()
151162
if err != nil {
152163
errMsg := getErrorMessage(response, err)
@@ -207,6 +218,14 @@ func resourceBackupRead(accountId string, projectId string, backupId string, api
207218
backup.RetentionPeriodInDays.Value = int64(*backupResp.Data.Spec.RetentionPeriodInDays)
208219
backup.MostRecent.Null = true
209220
backup.Timestamp.Null = true
221+
222+
// Read use_roles from response (defaults to false if not present)
223+
if backupResp.Data.Spec.HasUseRoles() {
224+
backup.UseRoles.Value = backupResp.Data.Spec.GetUseRoles()
225+
} else {
226+
backup.UseRoles.Value = false
227+
}
228+
210229
return backup, true, ""
211230
}
212231

managed/resource_cluster.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ func (r resourceClusterType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
549549
Optional: true,
550550
Validators: []tfsdk.AttributeValidator{int64validator.AtLeast(60)},
551551
},
552+
"use_roles": {
553+
Description: "Backup global YSQL roles in scheduled backups. Defaults to false.",
554+
Type: types.BoolType,
555+
Optional: true,
556+
Computed: true,
557+
},
552558
}),
553559
},
554560
"cmk_spec": {
@@ -976,6 +982,10 @@ func editBackupScheduleV2(ctx context.Context, backupScheduleStruct BackupSchedu
976982
return errors.New("unable to create custom backup schedule. You can't pass both the cron expression and time interval in days")
977983
}
978984

985+
if !backupScheduleStruct.UseRoles.IsNull() && !backupScheduleStruct.UseRoles.IsUnknown() {
986+
backupScheduleSpec.SetUseRoles(backupScheduleStruct.UseRoles.Value)
987+
}
988+
979989
_, res, err := apiClient.BackupApi.ModifyBackupScheduleV2(ctx, accountId, projectId, clusterId, scheduleId).ScheduleSpecV2(backupScheduleSpec).Execute()
980990
if err != nil {
981991
errMsg := getErrorMessage(res, err)
@@ -2202,6 +2212,12 @@ func readBackupScheduleInfoV2(ctx context.Context, apiClient *openapiclient.APIC
22022212
if backupScheduleStruct.IncrementalIntervalInMins.Value == 0 {
22032213
backupScheduleStruct.IncrementalIntervalInMins.Null = true
22042214
}
2215+
// Read use_roles from response (defaults to false if not present)
2216+
if spec.HasUseRoles() {
2217+
backupScheduleStruct.UseRoles = types.Bool{Value: spec.GetUseRoles()}
2218+
} else {
2219+
backupScheduleStruct.UseRoles = types.Bool{Value: false}
2220+
}
22052221
backupScheduleInfo[0] = backupScheduleStruct
22062222

22072223
return backupScheduleInfo, nil, nil

0 commit comments

Comments
 (0)