Skip to content

Commit

Permalink
fix: backup schedule time
Browse files Browse the repository at this point in the history
  • Loading branch information
wai-wong-edb committed Nov 13, 2024
1 parent b5078f3 commit 278bf8f
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resource "biganimal_analytics_cluster" "analytics_cluster" {
]

backup_retention_period = "30d"
# 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"
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
# 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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
# 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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
# 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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ resource "biganimal_faraway_replica" "faraway_replica" {
]

backup_retention_period = "8d"
# 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"

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 @@ -111,6 +112,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 @@ -111,6 +112,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 @@ -115,6 +116,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
2 changes: 1 addition & 1 deletion pkg/models/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type Cluster struct {
EncryptionKeyIdReq *string `json:"keyId,omitempty"`
EncryptionKeyResp *EncryptionKey `json:"encryptionKey,omitempty"`
PgIdentity *string `json:"pgIdentity,omitempty"`
BackupSchedule *commonApi.BackupSchedule `json:"backupSchedule,omitempty"`
BackupScheduleTime *string `json:"scheduleBackup,omitempty"`
}

// IsHealthy checks to see if the cluster has the right condition 'biganimal.com/deployed'
Expand Down
6 changes: 0 additions & 6 deletions pkg/models/common/api/backup_schedule.go

This file was deleted.

8 changes: 0 additions & 8 deletions pkg/models/common/terraform/backup_schedule.go

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/models/pgd/api/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

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

type DataGroup struct {
Expand Down Expand Up @@ -33,5 +32,5 @@ type DataGroup struct {
PeAllowedPrincipalIds *[]string `json:"peAllowedPrincipalIds,omitempty"`
RoConnectionUri *string `json:"roConnectionUri,omitempty"`
ReadOnlyConnections *bool `json:"readOnlyConnections,omitempty"`
BackupSchedule *commonApi.BackupSchedule `json:"backupSchedule,omitempty"`
BackupScheduleTime *string `json:"scheduleBackup,omitempty"`
}
55 changes: 27 additions & 28 deletions pkg/models/pgd/terraform/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@ package terraform

import (
"github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models"
commonTerraform "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/terraform"
"github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/pgd/api"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type DataGroup struct {
GroupId types.String `tfsdk:"group_id"`
AllowedIpRanges types.Set `tfsdk:"allowed_ip_ranges"`
BackupRetentionPeriod *string `tfsdk:"backup_retention_period"`
ClusterArchitecture *ClusterArchitecture `tfsdk:"cluster_architecture"`
ClusterName types.String `tfsdk:"cluster_name"`
ClusterType types.String `tfsdk:"cluster_type"`
Connection types.String `tfsdk:"connection_uri"`
CreatedAt types.String `tfsdk:"created_at"`
CspAuth *bool `tfsdk:"csp_auth"`
InstanceType *api.InstanceType `tfsdk:"instance_type"`
LogsUrl types.String `tfsdk:"logs_url"`
MetricsUrl types.String `tfsdk:"metrics_url"`
PgConfig *[]models.KeyValue `tfsdk:"pg_config"`
PgType *api.PgType `tfsdk:"pg_type"`
PgVersion *api.PgVersion `tfsdk:"pg_version"`
Phase types.String `tfsdk:"phase"`
PrivateNetworking *bool `tfsdk:"private_networking"`
Provider *api.CloudProvider `tfsdk:"cloud_provider"`
Region *api.Region `tfsdk:"region"`
ResizingPvc types.Set `tfsdk:"resizing_pvc"`
Storage *Storage `tfsdk:"storage"`
MaintenanceWindow *models.MaintenanceWindow `tfsdk:"maintenance_window"`
ServiceAccountIds types.Set `tfsdk:"service_account_ids"`
PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"`
RoConnectionUri types.String `tfsdk:"ro_connection_uri"`
ReadOnlyConnections *bool `tfsdk:"read_only_connections"`
BackupSchedule *commonTerraform.BackupSchedule `tfsdk:"backup_schedule"`
GroupId types.String `tfsdk:"group_id"`
AllowedIpRanges types.Set `tfsdk:"allowed_ip_ranges"`
BackupRetentionPeriod *string `tfsdk:"backup_retention_period"`
ClusterArchitecture *ClusterArchitecture `tfsdk:"cluster_architecture"`
ClusterName types.String `tfsdk:"cluster_name"`
ClusterType types.String `tfsdk:"cluster_type"`
Connection types.String `tfsdk:"connection_uri"`
CreatedAt types.String `tfsdk:"created_at"`
CspAuth *bool `tfsdk:"csp_auth"`
InstanceType *api.InstanceType `tfsdk:"instance_type"`
LogsUrl types.String `tfsdk:"logs_url"`
MetricsUrl types.String `tfsdk:"metrics_url"`
PgConfig *[]models.KeyValue `tfsdk:"pg_config"`
PgType *api.PgType `tfsdk:"pg_type"`
PgVersion *api.PgVersion `tfsdk:"pg_version"`
Phase types.String `tfsdk:"phase"`
PrivateNetworking *bool `tfsdk:"private_networking"`
Provider *api.CloudProvider `tfsdk:"cloud_provider"`
Region *api.Region `tfsdk:"region"`
ResizingPvc types.Set `tfsdk:"resizing_pvc"`
Storage *Storage `tfsdk:"storage"`
MaintenanceWindow *models.MaintenanceWindow `tfsdk:"maintenance_window"`
ServiceAccountIds types.Set `tfsdk:"service_account_ids"`
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"`
}
37 changes: 4 additions & 33 deletions pkg/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

var WeekdaysNumber = map[string]float64{
"monday": 1.0,
"tuesday": 2.0,
"wednesday": 3.0,
"thursday": 4.0,
"friday": 5.0,
"saturday": 6.0,
"sunday": 0.0,
}

var WeekdaysName = map[float64]string{
1.0: "Monday",
2.0: "Tuesday",
3.0: "Wednesday",
4.0: "Thursday",
5.0: "Friday",
6.0: "Saturday",
0.0: "Sunday",
}

// build tag assign terraform resource as, using api response as input
func buildTFRsrcAssignTagsAs(tfRsrcTagsOut *[]commonTerraform.Tag, apiRespTags []commonApi.Tag) {
*tfRsrcTagsOut = []commonTerraform.Tag{}
Expand All @@ -53,17 +33,8 @@ func buildAPIReqAssignTags(tfRsrcTags []commonTerraform.Tag) []commonApi.Tag {
return tags
}

var resourceBackupSchedule = schema.SingleNestedAttribute{
Description: "Backup schedule.",
Optional: true,
Attributes: map[string]schema.Attribute{
"start_day": schema.StringAttribute{
Description: "Backup schedule start day.",
Required: true,
},
"start_time": schema.StringAttribute{
Description: "Backup schedule start time.",
Required: true,
},
},
var ResourceBackupScheduleTime = schema.StringAttribute{
MarkdownDescription: "Backup schedule time in 24 hour format.",
Optional: true,
Computed: true,
}
20 changes: 4 additions & 16 deletions pkg/provider/resource_analytics_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type analyticsClusterResourceModel struct {
PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"`
Pause types.Bool `tfsdk:"pause"`
Tags []commonTerraform.Tag `tfsdk:"tags"`
BackupSchedule *commonTerraform.BackupSchedule `tfsdk:"backup_schedule"`
BackupScheduleTime types.String `tfsdk:"backup_schedule_time"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (r *analyticsClusterResource) Schema(ctx context.Context, req resource.Sche
plan_modifier.CustomAssignTags(),
},
},
"backup_schedule": resourceBackupSchedule,
"backup_schedule_time": ResourceBackupScheduleTime,
},
}
}
Expand Down Expand Up @@ -408,6 +408,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 @@ -480,13 +481,6 @@ func generateAnalyticsClusterModelCreate(ctx context.Context, client *api.Cluste

cluster.Tags = buildAPIReqAssignTags(clusterResource.Tags)

if clusterResource.BackupSchedule != nil {
cluster.BackupSchedule = &commonApi.BackupSchedule{
StartDay: utils.ToPointer(WeekdaysNumber[clusterResource.BackupSchedule.StartDay.ValueString()]),
StartTime: clusterResource.BackupSchedule.StartTime.ValueStringPointer(),
}
}

return cluster, nil
}

Expand Down Expand Up @@ -514,6 +508,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 Expand Up @@ -555,13 +550,6 @@ func readAnalyticsCluster(ctx context.Context, client *api.ClusterClient, tfClus

buildTFRsrcAssignTagsAs(&tfClusterResource.Tags, responseCluster.Tags)

if responseCluster.BackupSchedule != nil {
tfClusterResource.BackupSchedule = &commonTerraform.BackupSchedule{
StartDay: types.StringValue(WeekdaysName[*responseCluster.BackupSchedule.StartDay]),
StartTime: types.StringPointerValue(responseCluster.BackupSchedule.StartTime),
}
}

return nil
}

Expand Down
Loading

0 comments on commit 278bf8f

Please sign in to comment.