Skip to content

Commit

Permalink
feat: backup schedule time (#609)
Browse files Browse the repository at this point in the history
* feat: backup schedule

* fix: backup schedule time

* fix: data sources

* fix: backup schedule time description
  • Loading branch information
wai-wong-edb authored Nov 28, 2024
1 parent 4a868a5 commit 2bea36d
Show file tree
Hide file tree
Showing 30 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ output "backup_retention_period" {
value = data.biganimal_analytics_cluster.this.backup_retention_period
}

output "backup_schedule_time" {
value = data.biganimal_analytics_cluster.this.backup_schedule_time
}

output "cluster_name" {
value = data.biganimal_analytics_cluster.this.cluster_name
}
Expand Down
4 changes: 4 additions & 0 deletions examples/data-sources/biganimal_cluster/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ output "backup_retention_period" {
value = data.biganimal_cluster.this.backup_retention_period
}

output "backup_schedule_time" {
value = data.biganimal_cluster.this.backup_schedule_time
}

output "cluster_name" {
value = data.biganimal_cluster.this.cluster_name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ output "backup_retention_period" {
value = data.biganimal_faraway_replica.this.backup_retention_period
}

output "backup_schedule_time" {
value = data.biganimal_faraway_replica.this.backup_schedule_time
}

output "cluster_name" {
value = data.biganimal_faraway_replica.this.cluster_name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ resource "biganimal_analytics_cluster" "analytics_cluster" {
]

backup_retention_period = "30d"
csp_auth = false
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
csp_auth = false

instance_type = "aws:m6id.12xlarge"
password = resource.random_password.password.result
Expand Down
1 change: 1 addition & 0 deletions examples/resources/biganimal_cluster/ha/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "biganimal_cluster" "ha_cluster" {
]

backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
id = "ha"
nodes = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "biganimal_cluster" "single_node_cluster" {
]

backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
id = "single"
nodes = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "biganimal_cluster" "single_node_cluster" {
]

backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
id = "single"
nodes = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ resource "biganimal_cluster" "single_node_cluster" {
]

backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
id = "single"
nodes = 1
Expand Down
5 changes: 3 additions & 2 deletions examples/resources/biganimal_faraway_replica/aws/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
csp_auth = false
instance_type = "aws:c6i.large"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
csp_auth = false
instance_type = "aws:c6i.large"

// only following pg_config parameters are configurable for faraway replica
// max_connections, max_locks_per_transaction, max_prepared_transactions, max_wal_senders, max_worker_processes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
csp_auth = false
instance_type = "azure:Standard_D2s_v3"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
csp_auth = false
instance_type = "azure:Standard_D2s_v3"

// only following pg_config parameters are configurable for faraway replica
// max_connections, max_locks_per_transaction, max_prepared_transactions, max_wal_senders, max_worker_processes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
csp_auth = false
instance_type = "azure:Standard_D2s_v3"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
csp_auth = false
instance_type = "azure:Standard_D2s_v3"

// only following pg_config parameters are configurable for faraway replica
// max_connections, max_locks_per_transaction, max_prepared_transactions, max_wal_senders, max_worker_processes.
Expand Down
5 changes: 3 additions & 2 deletions examples/resources/biganimal_faraway_replica/gcp/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
csp_auth = false
instance_type = "gcp:e2-highcpu-4"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
csp_auth = false
instance_type = "gcp:e2-highcpu-4"

// only following pg_config parameters are configurable for faraway replica
// max_connections, max_locks_per_transaction, max_prepared_transactions, max_wal_senders, max_worker_processes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down Expand Up @@ -116,6 +117,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down Expand Up @@ -116,6 +117,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down Expand Up @@ -120,6 +121,7 @@ resource "biganimal_pgd" "pgd_cluster" {
},
]
backup_retention_period = "6d"
# backup_schedule_time = "0 5 1 * * *" //24 hour format cron expression e.g. "0 5 1 * * *" is 01:05
cluster_architecture = {
cluster_architecture_id = "pgd"
nodes = 3
Expand Down
1 change: 1 addition & 0 deletions pkg/models/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ type Cluster struct {
EncryptionKeyIdReq *string `json:"keyId,omitempty"`
EncryptionKeyResp *EncryptionKey `json:"encryptionKey,omitempty"`
PgIdentity *string `json:"pgIdentity,omitempty"`
BackupScheduleTime *string `json:"scheduleBackup,omitempty"`
WalStorage *Storage `json:"walStorage,omitempty"`
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/models/pgd/api/data_group.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models"
import (
"github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models"
)

type DataGroup struct {
GroupId *string `json:"groupId,omitempty"`
Expand Down Expand Up @@ -30,5 +32,6 @@ type DataGroup struct {
PeAllowedPrincipalIds *[]string `json:"peAllowedPrincipalIds,omitempty"`
RoConnectionUri *string `json:"roConnectionUri,omitempty"`
ReadOnlyConnections *bool `json:"readOnlyConnections,omitempty"`
BackupScheduleTime *string `json:"scheduleBackup,omitempty"`
WalStorage *models.Storage `json:"walStorage,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/models/pgd/terraform/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ type DataGroup struct {
PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"`
RoConnectionUri types.String `tfsdk:"ro_connection_uri"`
ReadOnlyConnections *bool `tfsdk:"read_only_connections"`
BackupScheduleTime types.String `tfsdk:"backup_schedule_time"`
WalStorage *Storage `tfsdk:"wal_storage"`
}
6 changes: 6 additions & 0 deletions pkg/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func buildAPIReqAssignTags(tfRsrcTags []commonTerraform.Tag) []commonApi.Tag {
return tags
}

var ResourceBackupScheduleTime = schema.StringAttribute{
MarkdownDescription: "Backup schedule time in 24 hour cron expression format.",
Optional: true,
Computed: true,
}

var resourceWal = schema.SingleNestedAttribute{
Description: "Use a separate storage volume for Write-Ahead Logs (Recommended for high write workloads)",
Optional: true,
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/data_source_analytics_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func (r *analyticsClusterDataSource) Schema(ctx context.Context, req datasource.
},
},
},
"backup_schedule_time": ResourceBackupScheduleTime,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ func (c *clusterDataSource) Schema(ctx context.Context, req datasource.SchemaReq
MarkdownDescription: "Cluster connection service name.",
Computed: true,
},
"wal_storage": resourceWal,
"backup_schedule_time": ResourceBackupScheduleTime,
"wal_storage": resourceWal,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/data_source_fareplica.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ func (c *FAReplicaData) Schema(ctx context.Context, req datasource.SchemaRequest
},
},
},
"wal_storage": resourceWal,
"backup_schedule_time": ResourceBackupScheduleTime,
"wal_storage": resourceWal,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/data_source_pgd.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ func (p pgdDataSource) Schema(ctx context.Context, req datasource.SchemaRequest,
Description: "Is read-only connections enabled.",
Computed: true,
},
"wal_storage": resourceWal,
"backup_schedule_time": ResourceBackupScheduleTime,
"wal_storage": resourceWal,
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/resource_analytics_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type analyticsClusterResourceModel struct {
PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"`
Pause types.Bool `tfsdk:"pause"`
Tags []commonTerraform.Tag `tfsdk:"tags"`
BackupScheduleTime types.String `tfsdk:"backup_schedule_time"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
}
Expand Down Expand Up @@ -302,6 +303,7 @@ func (r *analyticsClusterResource) Schema(ctx context.Context, req resource.Sche
plan_modifier.CustomAssignTags(),
},
},
"backup_schedule_time": ResourceBackupScheduleTime,
},
}
}
Expand Down Expand Up @@ -407,6 +409,7 @@ func generateAnalyticsClusterModelCreate(ctx context.Context, client *api.Cluste
CSPAuth: clusterResource.CspAuth.ValueBoolPointer(),
PrivateNetworking: clusterResource.PrivateNetworking.ValueBoolPointer(),
BackupRetentionPeriod: clusterResource.BackupRetentionPeriod.ValueStringPointer(),
BackupScheduleTime: clusterResource.BackupScheduleTime.ValueStringPointer(),
}

cluster.ClusterId = nil
Expand Down Expand Up @@ -506,6 +509,7 @@ func readAnalyticsCluster(ctx context.Context, client *api.ClusterClient, tfClus
tfClusterResource.LogsUrl = responseCluster.LogsUrl
tfClusterResource.MetricsUrl = responseCluster.MetricsUrl
tfClusterResource.BackupRetentionPeriod = types.StringPointerValue(responseCluster.BackupRetentionPeriod)
tfClusterResource.BackupScheduleTime = types.StringPointerValue(responseCluster.BackupScheduleTime)
tfClusterResource.PgVersion = types.StringValue(responseCluster.PgVersion.PgVersionId)
tfClusterResource.PgType = types.StringValue(responseCluster.PgType.PgTypeId)
tfClusterResource.PrivateNetworking = types.BoolPointerValue(responseCluster.PrivateNetworking)
Expand Down
6 changes: 5 additions & 1 deletion pkg/provider/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type ClusterResourceModel struct {
VolumeSnapshot types.Bool `tfsdk:"volume_snapshot_backup"`
Tags []commonTerraform.Tag `tfsdk:"tags"`
ServiceName types.String `tfsdk:"service_name"`
BackupScheduleTime types.String `tfsdk:"backup_schedule_time"`
WalStorage *StorageResourceModel `tfsdk:"wal_storage"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
Expand Down Expand Up @@ -577,7 +578,8 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"wal_storage": resourceWal,
"backup_schedule_time": ResourceBackupScheduleTime,
"wal_storage": resourceWal,
},
}
}
Expand Down Expand Up @@ -859,6 +861,7 @@ func readCluster(ctx context.Context, client *api.ClusterClient, tfClusterResour
tfClusterResource.LogsUrl = responseCluster.LogsUrl
tfClusterResource.MetricsUrl = responseCluster.MetricsUrl
tfClusterResource.BackupRetentionPeriod = types.StringPointerValue(responseCluster.BackupRetentionPeriod)
tfClusterResource.BackupScheduleTime = types.StringPointerValue(responseCluster.BackupScheduleTime)
tfClusterResource.PgVersion = types.StringValue(responseCluster.PgVersion.PgVersionId)
tfClusterResource.PgType = types.StringValue(responseCluster.PgType.PgTypeId)
tfClusterResource.FarawayReplicaIds = StringSliceToSet(responseCluster.FarawayReplicaIds)
Expand Down Expand Up @@ -1108,6 +1111,7 @@ func (c *clusterResource) generateGenericClusterModel(ctx context.Context, clust
PrivateNetworking: clusterResource.PrivateNetworking.ValueBoolPointer(),
ReadOnlyConnections: clusterResource.ReadOnlyConnections.ValueBoolPointer(),
BackupRetentionPeriod: clusterResource.BackupRetentionPeriod.ValueStringPointer(),
BackupScheduleTime: clusterResource.BackupScheduleTime.ValueStringPointer(),
SuperuserAccess: clusterResource.SuperuserAccess.ValueBoolPointer(),
VolumeSnapshot: clusterResource.VolumeSnapshot.ValueBoolPointer(),
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/provider/resource_fareplica.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type FAReplicaResourceModel struct {
TransparentDataEncryptionAction types.String `tfsdk:"transparent_data_encryption_action"`
VolumeSnapshot types.Bool `tfsdk:"volume_snapshot_backup"`
Tags []commonTerraform.Tag `tfsdk:"tags"`
BackupScheduleTime types.String `tfsdk:"backup_schedule_time"`
WalStorage *StorageResourceModel `tfsdk:"wal_storage"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
Expand Down Expand Up @@ -423,7 +424,8 @@ func (r *FAReplicaResource) Schema(ctx context.Context, req resource.SchemaReque
plan_modifier.CustomAssignTags(),
},
},
"wal_storage": resourceWal,
"backup_schedule_time": ResourceBackupScheduleTime,
"wal_storage": resourceWal,
},
}
}
Expand Down Expand Up @@ -627,6 +629,7 @@ func readFAReplica(ctx context.Context, client *api.ClusterClient, fAReplicaReso
fAReplicaResourceModel.LogsUrl = responseCluster.LogsUrl
fAReplicaResourceModel.MetricsUrl = responseCluster.MetricsUrl
fAReplicaResourceModel.BackupRetentionPeriod = types.StringPointerValue(responseCluster.BackupRetentionPeriod)
fAReplicaResourceModel.BackupScheduleTime = types.StringPointerValue(responseCluster.BackupScheduleTime)
fAReplicaResourceModel.PrivateNetworking = types.BoolPointerValue(responseCluster.PrivateNetworking)
fAReplicaResourceModel.ClusterArchitecture = &ClusterArchitectureResourceModel{
Id: responseCluster.ClusterArchitecture.ClusterArchitectureId,
Expand Down Expand Up @@ -777,6 +780,7 @@ func (r *FAReplicaResource) generateGenericFAReplicaModel(ctx context.Context, f
CSPAuth: fAReplicaResourceModel.CspAuth.ValueBoolPointer(),
PrivateNetworking: fAReplicaResourceModel.PrivateNetworking.ValueBoolPointer(),
BackupRetentionPeriod: fAReplicaResourceModel.BackupRetentionPeriod.ValueStringPointer(),
BackupScheduleTime: fAReplicaResourceModel.BackupScheduleTime.ValueStringPointer(),
}

if fAReplicaResourceModel.WalStorage != nil {
Expand Down
Loading

0 comments on commit 2bea36d

Please sign in to comment.